mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-03 07:13:26 +08:00
feat: add license schema
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/db/codesnippet"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/extension"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/model"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovider"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovidermodel"
|
||||
@@ -66,6 +67,8 @@ type Client struct {
|
||||
Extension *ExtensionClient
|
||||
// InviteCode is the client for interacting with the InviteCode builders.
|
||||
InviteCode *InviteCodeClient
|
||||
// License is the client for interacting with the License builders.
|
||||
License *LicenseClient
|
||||
// Model is the client for interacting with the Model builders.
|
||||
Model *ModelClient
|
||||
// ModelProvider is the client for interacting with the ModelProvider builders.
|
||||
@@ -109,6 +112,7 @@ func (c *Client) init() {
|
||||
c.CodeSnippet = NewCodeSnippetClient(c.config)
|
||||
c.Extension = NewExtensionClient(c.config)
|
||||
c.InviteCode = NewInviteCodeClient(c.config)
|
||||
c.License = NewLicenseClient(c.config)
|
||||
c.Model = NewModelClient(c.config)
|
||||
c.ModelProvider = NewModelProviderClient(c.config)
|
||||
c.ModelProviderModel = NewModelProviderModelClient(c.config)
|
||||
@@ -222,6 +226,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
CodeSnippet: NewCodeSnippetClient(cfg),
|
||||
Extension: NewExtensionClient(cfg),
|
||||
InviteCode: NewInviteCodeClient(cfg),
|
||||
License: NewLicenseClient(cfg),
|
||||
Model: NewModelClient(cfg),
|
||||
ModelProvider: NewModelProviderClient(cfg),
|
||||
ModelProviderModel: NewModelProviderModelClient(cfg),
|
||||
@@ -262,6 +267,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
CodeSnippet: NewCodeSnippetClient(cfg),
|
||||
Extension: NewExtensionClient(cfg),
|
||||
InviteCode: NewInviteCodeClient(cfg),
|
||||
License: NewLicenseClient(cfg),
|
||||
Model: NewModelClient(cfg),
|
||||
ModelProvider: NewModelProviderClient(cfg),
|
||||
ModelProviderModel: NewModelProviderModelClient(cfg),
|
||||
@@ -304,7 +310,7 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.Admin, c.AdminLoginHistory, c.ApiKey, c.BillingPlan, c.BillingQuota,
|
||||
c.BillingRecord, c.BillingUsage, c.CodeSnippet, c.Extension, c.InviteCode,
|
||||
c.Model, c.ModelProvider, c.ModelProviderModel, c.Setting, c.Task,
|
||||
c.License, c.Model, c.ModelProvider, c.ModelProviderModel, c.Setting, c.Task,
|
||||
c.TaskRecord, c.User, c.UserIdentity, c.UserLoginHistory, c.Workspace,
|
||||
c.WorkspaceFile,
|
||||
} {
|
||||
@@ -318,7 +324,7 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.Admin, c.AdminLoginHistory, c.ApiKey, c.BillingPlan, c.BillingQuota,
|
||||
c.BillingRecord, c.BillingUsage, c.CodeSnippet, c.Extension, c.InviteCode,
|
||||
c.Model, c.ModelProvider, c.ModelProviderModel, c.Setting, c.Task,
|
||||
c.License, c.Model, c.ModelProvider, c.ModelProviderModel, c.Setting, c.Task,
|
||||
c.TaskRecord, c.User, c.UserIdentity, c.UserLoginHistory, c.Workspace,
|
||||
c.WorkspaceFile,
|
||||
} {
|
||||
@@ -349,6 +355,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
return c.Extension.mutate(ctx, m)
|
||||
case *InviteCodeMutation:
|
||||
return c.InviteCode.mutate(ctx, m)
|
||||
case *LicenseMutation:
|
||||
return c.License.mutate(ctx, m)
|
||||
case *ModelMutation:
|
||||
return c.Model.mutate(ctx, m)
|
||||
case *ModelProviderMutation:
|
||||
@@ -1774,6 +1782,139 @@ func (c *InviteCodeClient) mutate(ctx context.Context, m *InviteCodeMutation) (V
|
||||
}
|
||||
}
|
||||
|
||||
// LicenseClient is a client for the License schema.
|
||||
type LicenseClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewLicenseClient returns a client for the License from the given config.
|
||||
func NewLicenseClient(c config) *LicenseClient {
|
||||
return &LicenseClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `license.Hooks(f(g(h())))`.
|
||||
func (c *LicenseClient) Use(hooks ...Hook) {
|
||||
c.hooks.License = append(c.hooks.License, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `license.Intercept(f(g(h())))`.
|
||||
func (c *LicenseClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.License = append(c.inters.License, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a License entity.
|
||||
func (c *LicenseClient) Create() *LicenseCreate {
|
||||
mutation := newLicenseMutation(c.config, OpCreate)
|
||||
return &LicenseCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of License entities.
|
||||
func (c *LicenseClient) CreateBulk(builders ...*LicenseCreate) *LicenseCreateBulk {
|
||||
return &LicenseCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *LicenseClient) MapCreateBulk(slice any, setFunc func(*LicenseCreate, int)) *LicenseCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &LicenseCreateBulk{err: fmt.Errorf("calling to LicenseClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*LicenseCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &LicenseCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for License.
|
||||
func (c *LicenseClient) Update() *LicenseUpdate {
|
||||
mutation := newLicenseMutation(c.config, OpUpdate)
|
||||
return &LicenseUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *LicenseClient) UpdateOne(l *License) *LicenseUpdateOne {
|
||||
mutation := newLicenseMutation(c.config, OpUpdateOne, withLicense(l))
|
||||
return &LicenseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *LicenseClient) UpdateOneID(id int) *LicenseUpdateOne {
|
||||
mutation := newLicenseMutation(c.config, OpUpdateOne, withLicenseID(id))
|
||||
return &LicenseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for License.
|
||||
func (c *LicenseClient) Delete() *LicenseDelete {
|
||||
mutation := newLicenseMutation(c.config, OpDelete)
|
||||
return &LicenseDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *LicenseClient) DeleteOne(l *License) *LicenseDeleteOne {
|
||||
return c.DeleteOneID(l.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *LicenseClient) DeleteOneID(id int) *LicenseDeleteOne {
|
||||
builder := c.Delete().Where(license.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &LicenseDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for License.
|
||||
func (c *LicenseClient) Query() *LicenseQuery {
|
||||
return &LicenseQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeLicense},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a License entity by its id.
|
||||
func (c *LicenseClient) Get(ctx context.Context, id int) (*License, error) {
|
||||
return c.Query().Where(license.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *LicenseClient) GetX(ctx context.Context, id int) *License {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *LicenseClient) Hooks() []Hook {
|
||||
return c.hooks.License
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *LicenseClient) Interceptors() []Interceptor {
|
||||
return c.inters.License
|
||||
}
|
||||
|
||||
func (c *LicenseClient) mutate(ctx context.Context, m *LicenseMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&LicenseCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&LicenseUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&LicenseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&LicenseDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("db: unknown License mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// ModelClient is a client for the Model schema.
|
||||
type ModelClient struct {
|
||||
config
|
||||
@@ -3597,15 +3738,15 @@ func (c *WorkspaceFileClient) mutate(ctx context.Context, m *WorkspaceFileMutati
|
||||
type (
|
||||
hooks struct {
|
||||
Admin, AdminLoginHistory, ApiKey, BillingPlan, BillingQuota, BillingRecord,
|
||||
BillingUsage, CodeSnippet, Extension, InviteCode, Model, ModelProvider,
|
||||
ModelProviderModel, Setting, Task, TaskRecord, User, UserIdentity,
|
||||
UserLoginHistory, Workspace, WorkspaceFile []ent.Hook
|
||||
BillingUsage, CodeSnippet, Extension, InviteCode, License, Model,
|
||||
ModelProvider, ModelProviderModel, Setting, Task, TaskRecord, User,
|
||||
UserIdentity, UserLoginHistory, Workspace, WorkspaceFile []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
Admin, AdminLoginHistory, ApiKey, BillingPlan, BillingQuota, BillingRecord,
|
||||
BillingUsage, CodeSnippet, Extension, InviteCode, Model, ModelProvider,
|
||||
ModelProviderModel, Setting, Task, TaskRecord, User, UserIdentity,
|
||||
UserLoginHistory, Workspace, WorkspaceFile []ent.Interceptor
|
||||
BillingUsage, CodeSnippet, Extension, InviteCode, License, Model,
|
||||
ModelProvider, ModelProviderModel, Setting, Task, TaskRecord, User,
|
||||
UserIdentity, UserLoginHistory, Workspace, WorkspaceFile []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/db/codesnippet"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/extension"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/model"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovider"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovidermodel"
|
||||
@@ -103,6 +104,7 @@ func checkColumn(table, column string) error {
|
||||
codesnippet.Table: codesnippet.ValidColumn,
|
||||
extension.Table: extension.ValidColumn,
|
||||
invitecode.Table: invitecode.ValidColumn,
|
||||
license.Table: license.ValidColumn,
|
||||
model.Table: model.ValidColumn,
|
||||
modelprovider.Table: modelprovider.ValidColumn,
|
||||
modelprovidermodel.Table: modelprovidermodel.ValidColumn,
|
||||
|
||||
@@ -129,6 +129,18 @@ func (f InviteCodeFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, er
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.InviteCodeMutation", m)
|
||||
}
|
||||
|
||||
// The LicenseFunc type is an adapter to allow the use of ordinary
|
||||
// function as License mutator.
|
||||
type LicenseFunc func(context.Context, *db.LicenseMutation) (db.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f LicenseFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) {
|
||||
if mv, ok := m.(*db.LicenseMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.LicenseMutation", m)
|
||||
}
|
||||
|
||||
// The ModelFunc type is an adapter to allow the use of ordinary
|
||||
// function as Model mutator.
|
||||
type ModelFunc func(context.Context, *db.ModelMutation) (db.Value, error)
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/db/codesnippet"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/extension"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/model"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovider"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovidermodel"
|
||||
@@ -358,6 +359,33 @@ func (f TraverseInviteCode) Traverse(ctx context.Context, q db.Query) error {
|
||||
return fmt.Errorf("unexpected query type %T. expect *db.InviteCodeQuery", q)
|
||||
}
|
||||
|
||||
// The LicenseFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type LicenseFunc func(context.Context, *db.LicenseQuery) (db.Value, error)
|
||||
|
||||
// Query calls f(ctx, q).
|
||||
func (f LicenseFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
|
||||
if q, ok := q.(*db.LicenseQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected query type %T. expect *db.LicenseQuery", q)
|
||||
}
|
||||
|
||||
// The TraverseLicense type is an adapter to allow the use of ordinary function as Traverser.
|
||||
type TraverseLicense func(context.Context, *db.LicenseQuery) error
|
||||
|
||||
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||
func (f TraverseLicense) Intercept(next db.Querier) db.Querier {
|
||||
return next
|
||||
}
|
||||
|
||||
// Traverse calls f(ctx, q).
|
||||
func (f TraverseLicense) Traverse(ctx context.Context, q db.Query) error {
|
||||
if q, ok := q.(*db.LicenseQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return fmt.Errorf("unexpected query type %T. expect *db.LicenseQuery", q)
|
||||
}
|
||||
|
||||
// The ModelFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type ModelFunc func(context.Context, *db.ModelQuery) (db.Value, error)
|
||||
|
||||
@@ -678,6 +706,8 @@ func NewQuery(q db.Query) (Query, error) {
|
||||
return &query[*db.ExtensionQuery, predicate.Extension, extension.OrderOption]{typ: db.TypeExtension, tq: q}, nil
|
||||
case *db.InviteCodeQuery:
|
||||
return &query[*db.InviteCodeQuery, predicate.InviteCode, invitecode.OrderOption]{typ: db.TypeInviteCode, tq: q}, nil
|
||||
case *db.LicenseQuery:
|
||||
return &query[*db.LicenseQuery, predicate.License, license.OrderOption]{typ: db.TypeLicense, tq: q}, nil
|
||||
case *db.ModelQuery:
|
||||
return &query[*db.ModelQuery, predicate.Model, model.OrderOption]{typ: db.TypeModel, tq: q}, nil
|
||||
case *db.ModelProviderQuery:
|
||||
|
||||
142
backend/db/license.go
Normal file
142
backend/db/license.go
Normal file
@@ -0,0 +1,142 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/pro/domain"
|
||||
)
|
||||
|
||||
// License is the model entity for the License schema.
|
||||
type License struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type domain.LicenseType `json:"type,omitempty"`
|
||||
// Data holds the value of the "data" field.
|
||||
Data []byte `json:"data,omitempty"`
|
||||
// Code holds the value of the "code" field.
|
||||
Code string `json:"code,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*License) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case license.FieldData:
|
||||
values[i] = new([]byte)
|
||||
case license.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case license.FieldType, license.FieldCode:
|
||||
values[i] = new(sql.NullString)
|
||||
case license.FieldCreatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the License fields.
|
||||
func (l *License) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case license.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
l.ID = int(value.Int64)
|
||||
case license.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
l.Type = domain.LicenseType(value.String)
|
||||
}
|
||||
case license.FieldData:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field data", values[i])
|
||||
} else if value != nil {
|
||||
l.Data = *value
|
||||
}
|
||||
case license.FieldCode:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field code", values[i])
|
||||
} else if value.Valid {
|
||||
l.Code = value.String
|
||||
}
|
||||
case license.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
l.CreatedAt = value.Time
|
||||
}
|
||||
default:
|
||||
l.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the License.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (l *License) Value(name string) (ent.Value, error) {
|
||||
return l.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this License.
|
||||
// Note that you need to call License.Unwrap() before calling this method if this License
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (l *License) Update() *LicenseUpdateOne {
|
||||
return NewLicenseClient(l.config).UpdateOne(l)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the License entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (l *License) Unwrap() *License {
|
||||
_tx, ok := l.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("db: License is not a transactional entity")
|
||||
}
|
||||
l.config.driver = _tx.drv
|
||||
return l
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (l *License) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("License(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", l.ID))
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", l.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("data=")
|
||||
builder.WriteString(fmt.Sprintf("%v", l.Data))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("code=")
|
||||
builder.WriteString(l.Code)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(l.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Licenses is a parsable slice of License.
|
||||
type Licenses []*License
|
||||
75
backend/db/license/license.go
Normal file
75
backend/db/license/license.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package license
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the license type in the database.
|
||||
Label = "license"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldData holds the string denoting the data field in the database.
|
||||
FieldData = "data"
|
||||
// FieldCode holds the string denoting the code field in the database.
|
||||
FieldCode = "code"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// Table holds the table name of the license in the database.
|
||||
Table = "license"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for license fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldType,
|
||||
FieldData,
|
||||
FieldCode,
|
||||
FieldCreatedAt,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// IDValidator is a validator for the "id" field. It is called by the builders before save.
|
||||
IDValidator func(int) error
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the License queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCode orders the results by the code field.
|
||||
func ByCode(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCode, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
341
backend/db/license/where.go
Normal file
341
backend/db/license/where.go
Normal file
@@ -0,0 +1,341 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package license
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
||||
"github.com/chaitin/MonkeyCode/backend/pro/domain"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.License {
|
||||
return predicate.License(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.License {
|
||||
return predicate.License(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.License {
|
||||
return predicate.License(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.License {
|
||||
return predicate.License(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.License {
|
||||
return predicate.License(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.License {
|
||||
return predicate.License(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.License {
|
||||
return predicate.License(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||
func Type(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldEQ(FieldType, vc))
|
||||
}
|
||||
|
||||
// Data applies equality check predicate on the "data" field. It's identical to DataEQ.
|
||||
func Data(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldData, v))
|
||||
}
|
||||
|
||||
// Code applies equality check predicate on the "code" field. It's identical to CodeEQ.
|
||||
func Code(v string) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldCode, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldEQ(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldNEQ(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...domain.LicenseType) predicate.License {
|
||||
v := make([]any, len(vs))
|
||||
for i := range v {
|
||||
v[i] = string(vs[i])
|
||||
}
|
||||
return predicate.License(sql.FieldIn(FieldType, v...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...domain.LicenseType) predicate.License {
|
||||
v := make([]any, len(vs))
|
||||
for i := range v {
|
||||
v[i] = string(vs[i])
|
||||
}
|
||||
return predicate.License(sql.FieldNotIn(FieldType, v...))
|
||||
}
|
||||
|
||||
// TypeGT applies the GT predicate on the "type" field.
|
||||
func TypeGT(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldGT(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeGTE applies the GTE predicate on the "type" field.
|
||||
func TypeGTE(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldGTE(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeLT applies the LT predicate on the "type" field.
|
||||
func TypeLT(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldLT(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeLTE applies the LTE predicate on the "type" field.
|
||||
func TypeLTE(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldLTE(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeContains applies the Contains predicate on the "type" field.
|
||||
func TypeContains(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldContains(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeHasPrefix applies the HasPrefix predicate on the "type" field.
|
||||
func TypeHasPrefix(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldHasPrefix(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeHasSuffix applies the HasSuffix predicate on the "type" field.
|
||||
func TypeHasSuffix(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldHasSuffix(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeEqualFold applies the EqualFold predicate on the "type" field.
|
||||
func TypeEqualFold(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldEqualFold(FieldType, vc))
|
||||
}
|
||||
|
||||
// TypeContainsFold applies the ContainsFold predicate on the "type" field.
|
||||
func TypeContainsFold(v domain.LicenseType) predicate.License {
|
||||
vc := string(v)
|
||||
return predicate.License(sql.FieldContainsFold(FieldType, vc))
|
||||
}
|
||||
|
||||
// DataEQ applies the EQ predicate on the "data" field.
|
||||
func DataEQ(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldData, v))
|
||||
}
|
||||
|
||||
// DataNEQ applies the NEQ predicate on the "data" field.
|
||||
func DataNEQ(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldNEQ(FieldData, v))
|
||||
}
|
||||
|
||||
// DataIn applies the In predicate on the "data" field.
|
||||
func DataIn(vs ...[]byte) predicate.License {
|
||||
return predicate.License(sql.FieldIn(FieldData, vs...))
|
||||
}
|
||||
|
||||
// DataNotIn applies the NotIn predicate on the "data" field.
|
||||
func DataNotIn(vs ...[]byte) predicate.License {
|
||||
return predicate.License(sql.FieldNotIn(FieldData, vs...))
|
||||
}
|
||||
|
||||
// DataGT applies the GT predicate on the "data" field.
|
||||
func DataGT(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldGT(FieldData, v))
|
||||
}
|
||||
|
||||
// DataGTE applies the GTE predicate on the "data" field.
|
||||
func DataGTE(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldGTE(FieldData, v))
|
||||
}
|
||||
|
||||
// DataLT applies the LT predicate on the "data" field.
|
||||
func DataLT(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldLT(FieldData, v))
|
||||
}
|
||||
|
||||
// DataLTE applies the LTE predicate on the "data" field.
|
||||
func DataLTE(v []byte) predicate.License {
|
||||
return predicate.License(sql.FieldLTE(FieldData, v))
|
||||
}
|
||||
|
||||
// DataIsNil applies the IsNil predicate on the "data" field.
|
||||
func DataIsNil() predicate.License {
|
||||
return predicate.License(sql.FieldIsNull(FieldData))
|
||||
}
|
||||
|
||||
// DataNotNil applies the NotNil predicate on the "data" field.
|
||||
func DataNotNil() predicate.License {
|
||||
return predicate.License(sql.FieldNotNull(FieldData))
|
||||
}
|
||||
|
||||
// CodeEQ applies the EQ predicate on the "code" field.
|
||||
func CodeEQ(v string) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeNEQ applies the NEQ predicate on the "code" field.
|
||||
func CodeNEQ(v string) predicate.License {
|
||||
return predicate.License(sql.FieldNEQ(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeIn applies the In predicate on the "code" field.
|
||||
func CodeIn(vs ...string) predicate.License {
|
||||
return predicate.License(sql.FieldIn(FieldCode, vs...))
|
||||
}
|
||||
|
||||
// CodeNotIn applies the NotIn predicate on the "code" field.
|
||||
func CodeNotIn(vs ...string) predicate.License {
|
||||
return predicate.License(sql.FieldNotIn(FieldCode, vs...))
|
||||
}
|
||||
|
||||
// CodeGT applies the GT predicate on the "code" field.
|
||||
func CodeGT(v string) predicate.License {
|
||||
return predicate.License(sql.FieldGT(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeGTE applies the GTE predicate on the "code" field.
|
||||
func CodeGTE(v string) predicate.License {
|
||||
return predicate.License(sql.FieldGTE(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeLT applies the LT predicate on the "code" field.
|
||||
func CodeLT(v string) predicate.License {
|
||||
return predicate.License(sql.FieldLT(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeLTE applies the LTE predicate on the "code" field.
|
||||
func CodeLTE(v string) predicate.License {
|
||||
return predicate.License(sql.FieldLTE(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeContains applies the Contains predicate on the "code" field.
|
||||
func CodeContains(v string) predicate.License {
|
||||
return predicate.License(sql.FieldContains(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeHasPrefix applies the HasPrefix predicate on the "code" field.
|
||||
func CodeHasPrefix(v string) predicate.License {
|
||||
return predicate.License(sql.FieldHasPrefix(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeHasSuffix applies the HasSuffix predicate on the "code" field.
|
||||
func CodeHasSuffix(v string) predicate.License {
|
||||
return predicate.License(sql.FieldHasSuffix(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeIsNil applies the IsNil predicate on the "code" field.
|
||||
func CodeIsNil() predicate.License {
|
||||
return predicate.License(sql.FieldIsNull(FieldCode))
|
||||
}
|
||||
|
||||
// CodeNotNil applies the NotNil predicate on the "code" field.
|
||||
func CodeNotNil() predicate.License {
|
||||
return predicate.License(sql.FieldNotNull(FieldCode))
|
||||
}
|
||||
|
||||
// CodeEqualFold applies the EqualFold predicate on the "code" field.
|
||||
func CodeEqualFold(v string) predicate.License {
|
||||
return predicate.License(sql.FieldEqualFold(FieldCode, v))
|
||||
}
|
||||
|
||||
// CodeContainsFold applies the ContainsFold predicate on the "code" field.
|
||||
func CodeContainsFold(v string) predicate.License {
|
||||
return predicate.License(sql.FieldContainsFold(FieldCode, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.License {
|
||||
return predicate.License(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.License) predicate.License {
|
||||
return predicate.License(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.License) predicate.License {
|
||||
return predicate.License(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.License) predicate.License {
|
||||
return predicate.License(sql.NotPredicates(p))
|
||||
}
|
||||
710
backend/db/license_create.go
Normal file
710
backend/db/license_create.go
Normal file
@@ -0,0 +1,710 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/pro/domain"
|
||||
)
|
||||
|
||||
// LicenseCreate is the builder for creating a License entity.
|
||||
type LicenseCreate struct {
|
||||
config
|
||||
mutation *LicenseMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (lc *LicenseCreate) SetType(dt domain.LicenseType) *LicenseCreate {
|
||||
lc.mutation.SetType(dt)
|
||||
return lc
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (lc *LicenseCreate) SetData(b []byte) *LicenseCreate {
|
||||
lc.mutation.SetData(b)
|
||||
return lc
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (lc *LicenseCreate) SetCode(s string) *LicenseCreate {
|
||||
lc.mutation.SetCode(s)
|
||||
return lc
|
||||
}
|
||||
|
||||
// SetNillableCode sets the "code" field if the given value is not nil.
|
||||
func (lc *LicenseCreate) SetNillableCode(s *string) *LicenseCreate {
|
||||
if s != nil {
|
||||
lc.SetCode(*s)
|
||||
}
|
||||
return lc
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (lc *LicenseCreate) SetCreatedAt(t time.Time) *LicenseCreate {
|
||||
lc.mutation.SetCreatedAt(t)
|
||||
return lc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (lc *LicenseCreate) SetNillableCreatedAt(t *time.Time) *LicenseCreate {
|
||||
if t != nil {
|
||||
lc.SetCreatedAt(*t)
|
||||
}
|
||||
return lc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (lc *LicenseCreate) SetID(i int) *LicenseCreate {
|
||||
lc.mutation.SetID(i)
|
||||
return lc
|
||||
}
|
||||
|
||||
// Mutation returns the LicenseMutation object of the builder.
|
||||
func (lc *LicenseCreate) Mutation() *LicenseMutation {
|
||||
return lc.mutation
|
||||
}
|
||||
|
||||
// Save creates the License in the database.
|
||||
func (lc *LicenseCreate) Save(ctx context.Context) (*License, error) {
|
||||
lc.defaults()
|
||||
return withHooks(ctx, lc.sqlSave, lc.mutation, lc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (lc *LicenseCreate) SaveX(ctx context.Context) *License {
|
||||
v, err := lc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (lc *LicenseCreate) Exec(ctx context.Context) error {
|
||||
_, err := lc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lc *LicenseCreate) ExecX(ctx context.Context) {
|
||||
if err := lc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (lc *LicenseCreate) defaults() {
|
||||
if _, ok := lc.mutation.CreatedAt(); !ok {
|
||||
v := license.DefaultCreatedAt()
|
||||
lc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (lc *LicenseCreate) check() error {
|
||||
if _, ok := lc.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`db: missing required field "License.type"`)}
|
||||
}
|
||||
if _, ok := lc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "License.created_at"`)}
|
||||
}
|
||||
if v, ok := lc.mutation.ID(); ok {
|
||||
if err := license.IDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "License.id": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lc *LicenseCreate) sqlSave(ctx context.Context) (*License, error) {
|
||||
if err := lc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := lc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, lc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if _spec.ID.Value != _node.ID {
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
}
|
||||
lc.mutation.id = &_node.ID
|
||||
lc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (lc *LicenseCreate) createSpec() (*License, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &License{config: lc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(license.Table, sqlgraph.NewFieldSpec(license.FieldID, field.TypeInt))
|
||||
)
|
||||
_spec.OnConflict = lc.conflict
|
||||
if id, ok := lc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := lc.mutation.GetType(); ok {
|
||||
_spec.SetField(license.FieldType, field.TypeString, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := lc.mutation.Data(); ok {
|
||||
_spec.SetField(license.FieldData, field.TypeBytes, value)
|
||||
_node.Data = value
|
||||
}
|
||||
if value, ok := lc.mutation.Code(); ok {
|
||||
_spec.SetField(license.FieldCode, field.TypeString, value)
|
||||
_node.Code = value
|
||||
}
|
||||
if value, ok := lc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(license.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.License.Create().
|
||||
// SetType(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.LicenseUpsert) {
|
||||
// SetType(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (lc *LicenseCreate) OnConflict(opts ...sql.ConflictOption) *LicenseUpsertOne {
|
||||
lc.conflict = opts
|
||||
return &LicenseUpsertOne{
|
||||
create: lc,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.License.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (lc *LicenseCreate) OnConflictColumns(columns ...string) *LicenseUpsertOne {
|
||||
lc.conflict = append(lc.conflict, sql.ConflictColumns(columns...))
|
||||
return &LicenseUpsertOne{
|
||||
create: lc,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// LicenseUpsertOne is the builder for "upsert"-ing
|
||||
// one License node.
|
||||
LicenseUpsertOne struct {
|
||||
create *LicenseCreate
|
||||
}
|
||||
|
||||
// LicenseUpsert is the "OnConflict" setter.
|
||||
LicenseUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *LicenseUpsert) SetType(v domain.LicenseType) *LicenseUpsert {
|
||||
u.Set(license.FieldType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *LicenseUpsert) UpdateType() *LicenseUpsert {
|
||||
u.SetExcluded(license.FieldType)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (u *LicenseUpsert) SetData(v []byte) *LicenseUpsert {
|
||||
u.Set(license.FieldData, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateData sets the "data" field to the value that was provided on create.
|
||||
func (u *LicenseUpsert) UpdateData() *LicenseUpsert {
|
||||
u.SetExcluded(license.FieldData)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (u *LicenseUpsert) ClearData() *LicenseUpsert {
|
||||
u.SetNull(license.FieldData)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (u *LicenseUpsert) SetCode(v string) *LicenseUpsert {
|
||||
u.Set(license.FieldCode, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateCode sets the "code" field to the value that was provided on create.
|
||||
func (u *LicenseUpsert) UpdateCode() *LicenseUpsert {
|
||||
u.SetExcluded(license.FieldCode)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearCode clears the value of the "code" field.
|
||||
func (u *LicenseUpsert) ClearCode() *LicenseUpsert {
|
||||
u.SetNull(license.FieldCode)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (u *LicenseUpsert) SetCreatedAt(v time.Time) *LicenseUpsert {
|
||||
u.Set(license.FieldCreatedAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||||
func (u *LicenseUpsert) UpdateCreatedAt() *LicenseUpsert {
|
||||
u.SetExcluded(license.FieldCreatedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.License.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
||||
// u.SetIgnore(license.FieldID)
|
||||
// }),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *LicenseUpsertOne) UpdateNewValues() *LicenseUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.ID(); exists {
|
||||
s.SetIgnore(license.FieldID)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.License.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *LicenseUpsertOne) Ignore() *LicenseUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *LicenseUpsertOne) DoNothing() *LicenseUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the LicenseCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *LicenseUpsertOne) Update(set func(*LicenseUpsert)) *LicenseUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&LicenseUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *LicenseUpsertOne) SetType(v domain.LicenseType) *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertOne) UpdateType() *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (u *LicenseUpsertOne) SetData(v []byte) *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetData(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateData sets the "data" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertOne) UpdateData() *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateData()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (u *LicenseUpsertOne) ClearData() *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.ClearData()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (u *LicenseUpsertOne) SetCode(v string) *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetCode(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCode sets the "code" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertOne) UpdateCode() *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateCode()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearCode clears the value of the "code" field.
|
||||
func (u *LicenseUpsertOne) ClearCode() *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.ClearCode()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (u *LicenseUpsertOne) SetCreatedAt(v time.Time) *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetCreatedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertOne) UpdateCreatedAt() *LicenseUpsertOne {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateCreatedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *LicenseUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("db: missing options for LicenseCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *LicenseUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *LicenseUpsertOne) ID(ctx context.Context) (id int, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *LicenseUpsertOne) IDX(ctx context.Context) int {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// LicenseCreateBulk is the builder for creating many License entities in bulk.
|
||||
type LicenseCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*LicenseCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the License entities in the database.
|
||||
func (lcb *LicenseCreateBulk) Save(ctx context.Context) ([]*License, error) {
|
||||
if lcb.err != nil {
|
||||
return nil, lcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(lcb.builders))
|
||||
nodes := make([]*License, len(lcb.builders))
|
||||
mutators := make([]Mutator, len(lcb.builders))
|
||||
for i := range lcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := lcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*LicenseMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, lcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = lcb.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, lcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, lcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (lcb *LicenseCreateBulk) SaveX(ctx context.Context) []*License {
|
||||
v, err := lcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (lcb *LicenseCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := lcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lcb *LicenseCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := lcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.License.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.LicenseUpsert) {
|
||||
// SetType(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (lcb *LicenseCreateBulk) OnConflict(opts ...sql.ConflictOption) *LicenseUpsertBulk {
|
||||
lcb.conflict = opts
|
||||
return &LicenseUpsertBulk{
|
||||
create: lcb,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.License.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (lcb *LicenseCreateBulk) OnConflictColumns(columns ...string) *LicenseUpsertBulk {
|
||||
lcb.conflict = append(lcb.conflict, sql.ConflictColumns(columns...))
|
||||
return &LicenseUpsertBulk{
|
||||
create: lcb,
|
||||
}
|
||||
}
|
||||
|
||||
// LicenseUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of License nodes.
|
||||
type LicenseUpsertBulk struct {
|
||||
create *LicenseCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.License.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
||||
// u.SetIgnore(license.FieldID)
|
||||
// }),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *LicenseUpsertBulk) UpdateNewValues() *LicenseUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.ID(); exists {
|
||||
s.SetIgnore(license.FieldID)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.License.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *LicenseUpsertBulk) Ignore() *LicenseUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *LicenseUpsertBulk) DoNothing() *LicenseUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the LicenseCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *LicenseUpsertBulk) Update(set func(*LicenseUpsert)) *LicenseUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&LicenseUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *LicenseUpsertBulk) SetType(v domain.LicenseType) *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertBulk) UpdateType() *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (u *LicenseUpsertBulk) SetData(v []byte) *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetData(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateData sets the "data" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertBulk) UpdateData() *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateData()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (u *LicenseUpsertBulk) ClearData() *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.ClearData()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (u *LicenseUpsertBulk) SetCode(v string) *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetCode(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCode sets the "code" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertBulk) UpdateCode() *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateCode()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearCode clears the value of the "code" field.
|
||||
func (u *LicenseUpsertBulk) ClearCode() *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.ClearCode()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (u *LicenseUpsertBulk) SetCreatedAt(v time.Time) *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.SetCreatedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||||
func (u *LicenseUpsertBulk) UpdateCreatedAt() *LicenseUpsertBulk {
|
||||
return u.Update(func(s *LicenseUpsert) {
|
||||
s.UpdateCreatedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *LicenseUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the LicenseCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("db: missing options for LicenseCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *LicenseUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
backend/db/license_delete.go
Normal file
88
backend/db/license_delete.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
||||
)
|
||||
|
||||
// LicenseDelete is the builder for deleting a License entity.
|
||||
type LicenseDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *LicenseMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LicenseDelete builder.
|
||||
func (ld *LicenseDelete) Where(ps ...predicate.License) *LicenseDelete {
|
||||
ld.mutation.Where(ps...)
|
||||
return ld
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ld *LicenseDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ld.sqlExec, ld.mutation, ld.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ld *LicenseDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ld.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ld *LicenseDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(license.Table, sqlgraph.NewFieldSpec(license.FieldID, field.TypeInt))
|
||||
if ps := ld.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ld.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ld.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// LicenseDeleteOne is the builder for deleting a single License entity.
|
||||
type LicenseDeleteOne struct {
|
||||
ld *LicenseDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LicenseDelete builder.
|
||||
func (ldo *LicenseDeleteOne) Where(ps ...predicate.License) *LicenseDeleteOne {
|
||||
ldo.ld.mutation.Where(ps...)
|
||||
return ldo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ldo *LicenseDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ldo.ld.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{license.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ldo *LicenseDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ldo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
577
backend/db/license_query.go
Normal file
577
backend/db/license_query.go
Normal file
@@ -0,0 +1,577 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
||||
)
|
||||
|
||||
// LicenseQuery is the builder for querying License entities.
|
||||
type LicenseQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []license.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.License
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the LicenseQuery builder.
|
||||
func (lq *LicenseQuery) Where(ps ...predicate.License) *LicenseQuery {
|
||||
lq.predicates = append(lq.predicates, ps...)
|
||||
return lq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (lq *LicenseQuery) Limit(limit int) *LicenseQuery {
|
||||
lq.ctx.Limit = &limit
|
||||
return lq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (lq *LicenseQuery) Offset(offset int) *LicenseQuery {
|
||||
lq.ctx.Offset = &offset
|
||||
return lq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (lq *LicenseQuery) Unique(unique bool) *LicenseQuery {
|
||||
lq.ctx.Unique = &unique
|
||||
return lq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (lq *LicenseQuery) Order(o ...license.OrderOption) *LicenseQuery {
|
||||
lq.order = append(lq.order, o...)
|
||||
return lq
|
||||
}
|
||||
|
||||
// First returns the first License entity from the query.
|
||||
// Returns a *NotFoundError when no License was found.
|
||||
func (lq *LicenseQuery) First(ctx context.Context) (*License, error) {
|
||||
nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{license.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) FirstX(ctx context.Context) *License {
|
||||
node, err := lq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first License ID from the query.
|
||||
// Returns a *NotFoundError when no License ID was found.
|
||||
func (lq *LicenseQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{license.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := lq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single License entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one License entity is found.
|
||||
// Returns a *NotFoundError when no License entities are found.
|
||||
func (lq *LicenseQuery) Only(ctx context.Context) (*License, error) {
|
||||
nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{license.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{license.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) OnlyX(ctx context.Context) *License {
|
||||
node, err := lq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only License ID in the query.
|
||||
// Returns a *NotSingularError when more than one License ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (lq *LicenseQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{license.Label}
|
||||
default:
|
||||
err = &NotSingularError{license.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := lq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Licenses.
|
||||
func (lq *LicenseQuery) All(ctx context.Context) ([]*License, error) {
|
||||
ctx = setContextOp(ctx, lq.ctx, ent.OpQueryAll)
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*License, *LicenseQuery]()
|
||||
return withInterceptors[[]*License](ctx, lq, qr, lq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) AllX(ctx context.Context) []*License {
|
||||
nodes, err := lq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of License IDs.
|
||||
func (lq *LicenseQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if lq.ctx.Unique == nil && lq.path != nil {
|
||||
lq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, lq.ctx, ent.OpQueryIDs)
|
||||
if err = lq.Select(license.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := lq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (lq *LicenseQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, lq.ctx, ent.OpQueryCount)
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, lq, querierCount[*LicenseQuery](), lq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) CountX(ctx context.Context) int {
|
||||
count, err := lq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (lq *LicenseQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, lq.ctx, ent.OpQueryExist)
|
||||
switch _, err := lq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("db: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (lq *LicenseQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := lq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the LicenseQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (lq *LicenseQuery) Clone() *LicenseQuery {
|
||||
if lq == nil {
|
||||
return nil
|
||||
}
|
||||
return &LicenseQuery{
|
||||
config: lq.config,
|
||||
ctx: lq.ctx.Clone(),
|
||||
order: append([]license.OrderOption{}, lq.order...),
|
||||
inters: append([]Interceptor{}, lq.inters...),
|
||||
predicates: append([]predicate.License{}, lq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: lq.sql.Clone(),
|
||||
path: lq.path,
|
||||
modifiers: append([]func(*sql.Selector){}, lq.modifiers...),
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Type domain.LicenseType `json:"type,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.License.Query().
|
||||
// GroupBy(license.FieldType).
|
||||
// Aggregate(db.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (lq *LicenseQuery) GroupBy(field string, fields ...string) *LicenseGroupBy {
|
||||
lq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &LicenseGroupBy{build: lq}
|
||||
grbuild.flds = &lq.ctx.Fields
|
||||
grbuild.label = license.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Type domain.LicenseType `json:"type,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.License.Query().
|
||||
// Select(license.FieldType).
|
||||
// Scan(ctx, &v)
|
||||
func (lq *LicenseQuery) Select(fields ...string) *LicenseSelect {
|
||||
lq.ctx.Fields = append(lq.ctx.Fields, fields...)
|
||||
sbuild := &LicenseSelect{LicenseQuery: lq}
|
||||
sbuild.label = license.Label
|
||||
sbuild.flds, sbuild.scan = &lq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a LicenseSelect configured with the given aggregations.
|
||||
func (lq *LicenseQuery) Aggregate(fns ...AggregateFunc) *LicenseSelect {
|
||||
return lq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (lq *LicenseQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range lq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, lq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range lq.ctx.Fields {
|
||||
if !license.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if lq.path != nil {
|
||||
prev, err := lq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lq *LicenseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*License, error) {
|
||||
var (
|
||||
nodes = []*License{}
|
||||
_spec = lq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*License).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &License{config: lq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
if len(lq.modifiers) > 0 {
|
||||
_spec.Modifiers = lq.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, lq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (lq *LicenseQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := lq.querySpec()
|
||||
if len(lq.modifiers) > 0 {
|
||||
_spec.Modifiers = lq.modifiers
|
||||
}
|
||||
_spec.Node.Columns = lq.ctx.Fields
|
||||
if len(lq.ctx.Fields) > 0 {
|
||||
_spec.Unique = lq.ctx.Unique != nil && *lq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, lq.driver, _spec)
|
||||
}
|
||||
|
||||
func (lq *LicenseQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(license.Table, license.Columns, sqlgraph.NewFieldSpec(license.FieldID, field.TypeInt))
|
||||
_spec.From = lq.sql
|
||||
if unique := lq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if lq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := lq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, license.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != license.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := lq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := lq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := lq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := lq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (lq *LicenseQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(lq.driver.Dialect())
|
||||
t1 := builder.Table(license.Table)
|
||||
columns := lq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = license.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if lq.sql != nil {
|
||||
selector = lq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if lq.ctx.Unique != nil && *lq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, m := range lq.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
for _, p := range lq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range lq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := lq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := lq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||
// either committed or rolled-back.
|
||||
func (lq *LicenseQuery) ForUpdate(opts ...sql.LockOption) *LicenseQuery {
|
||||
if lq.driver.Dialect() == dialect.Postgres {
|
||||
lq.Unique(false)
|
||||
}
|
||||
lq.modifiers = append(lq.modifiers, func(s *sql.Selector) {
|
||||
s.ForUpdate(opts...)
|
||||
})
|
||||
return lq
|
||||
}
|
||||
|
||||
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||
// until your transaction commits.
|
||||
func (lq *LicenseQuery) ForShare(opts ...sql.LockOption) *LicenseQuery {
|
||||
if lq.driver.Dialect() == dialect.Postgres {
|
||||
lq.Unique(false)
|
||||
}
|
||||
lq.modifiers = append(lq.modifiers, func(s *sql.Selector) {
|
||||
s.ForShare(opts...)
|
||||
})
|
||||
return lq
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (lq *LicenseQuery) Modify(modifiers ...func(s *sql.Selector)) *LicenseSelect {
|
||||
lq.modifiers = append(lq.modifiers, modifiers...)
|
||||
return lq.Select()
|
||||
}
|
||||
|
||||
// LicenseGroupBy is the group-by builder for License entities.
|
||||
type LicenseGroupBy struct {
|
||||
selector
|
||||
build *LicenseQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (lgb *LicenseGroupBy) Aggregate(fns ...AggregateFunc) *LicenseGroupBy {
|
||||
lgb.fns = append(lgb.fns, fns...)
|
||||
return lgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (lgb *LicenseGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, lgb.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := lgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*LicenseQuery, *LicenseGroupBy](ctx, lgb.build, lgb, lgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (lgb *LicenseGroupBy) sqlScan(ctx context.Context, root *LicenseQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(lgb.fns))
|
||||
for _, fn := range lgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*lgb.flds)+len(lgb.fns))
|
||||
for _, f := range *lgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*lgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := lgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// LicenseSelect is the builder for selecting fields of License entities.
|
||||
type LicenseSelect struct {
|
||||
*LicenseQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ls *LicenseSelect) Aggregate(fns ...AggregateFunc) *LicenseSelect {
|
||||
ls.fns = append(ls.fns, fns...)
|
||||
return ls
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ls *LicenseSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ls.ctx, ent.OpQuerySelect)
|
||||
if err := ls.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*LicenseQuery, *LicenseSelect](ctx, ls.LicenseQuery, ls, ls.inters, v)
|
||||
}
|
||||
|
||||
func (ls *LicenseSelect) sqlScan(ctx context.Context, root *LicenseQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ls.fns))
|
||||
for _, fn := range ls.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ls.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ls.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (ls *LicenseSelect) Modify(modifiers ...func(s *sql.Selector)) *LicenseSelect {
|
||||
ls.modifiers = append(ls.modifiers, modifiers...)
|
||||
return ls
|
||||
}
|
||||
349
backend/db/license_update.go
Normal file
349
backend/db/license_update.go
Normal file
@@ -0,0 +1,349 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
||||
"github.com/chaitin/MonkeyCode/backend/pro/domain"
|
||||
)
|
||||
|
||||
// LicenseUpdate is the builder for updating License entities.
|
||||
type LicenseUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *LicenseMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LicenseUpdate builder.
|
||||
func (lu *LicenseUpdate) Where(ps ...predicate.License) *LicenseUpdate {
|
||||
lu.mutation.Where(ps...)
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (lu *LicenseUpdate) SetType(dt domain.LicenseType) *LicenseUpdate {
|
||||
lu.mutation.SetType(dt)
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (lu *LicenseUpdate) SetNillableType(dt *domain.LicenseType) *LicenseUpdate {
|
||||
if dt != nil {
|
||||
lu.SetType(*dt)
|
||||
}
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (lu *LicenseUpdate) SetData(b []byte) *LicenseUpdate {
|
||||
lu.mutation.SetData(b)
|
||||
return lu
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (lu *LicenseUpdate) ClearData() *LicenseUpdate {
|
||||
lu.mutation.ClearData()
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (lu *LicenseUpdate) SetCode(s string) *LicenseUpdate {
|
||||
lu.mutation.SetCode(s)
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetNillableCode sets the "code" field if the given value is not nil.
|
||||
func (lu *LicenseUpdate) SetNillableCode(s *string) *LicenseUpdate {
|
||||
if s != nil {
|
||||
lu.SetCode(*s)
|
||||
}
|
||||
return lu
|
||||
}
|
||||
|
||||
// ClearCode clears the value of the "code" field.
|
||||
func (lu *LicenseUpdate) ClearCode() *LicenseUpdate {
|
||||
lu.mutation.ClearCode()
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (lu *LicenseUpdate) SetCreatedAt(t time.Time) *LicenseUpdate {
|
||||
lu.mutation.SetCreatedAt(t)
|
||||
return lu
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (lu *LicenseUpdate) SetNillableCreatedAt(t *time.Time) *LicenseUpdate {
|
||||
if t != nil {
|
||||
lu.SetCreatedAt(*t)
|
||||
}
|
||||
return lu
|
||||
}
|
||||
|
||||
// Mutation returns the LicenseMutation object of the builder.
|
||||
func (lu *LicenseUpdate) Mutation() *LicenseMutation {
|
||||
return lu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (lu *LicenseUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, lu.sqlSave, lu.mutation, lu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (lu *LicenseUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := lu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (lu *LicenseUpdate) Exec(ctx context.Context) error {
|
||||
_, err := lu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lu *LicenseUpdate) ExecX(ctx context.Context) {
|
||||
if err := lu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (lu *LicenseUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *LicenseUpdate {
|
||||
lu.modifiers = append(lu.modifiers, modifiers...)
|
||||
return lu
|
||||
}
|
||||
|
||||
func (lu *LicenseUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(license.Table, license.Columns, sqlgraph.NewFieldSpec(license.FieldID, field.TypeInt))
|
||||
if ps := lu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := lu.mutation.GetType(); ok {
|
||||
_spec.SetField(license.FieldType, field.TypeString, value)
|
||||
}
|
||||
if value, ok := lu.mutation.Data(); ok {
|
||||
_spec.SetField(license.FieldData, field.TypeBytes, value)
|
||||
}
|
||||
if lu.mutation.DataCleared() {
|
||||
_spec.ClearField(license.FieldData, field.TypeBytes)
|
||||
}
|
||||
if value, ok := lu.mutation.Code(); ok {
|
||||
_spec.SetField(license.FieldCode, field.TypeString, value)
|
||||
}
|
||||
if lu.mutation.CodeCleared() {
|
||||
_spec.ClearField(license.FieldCode, field.TypeString)
|
||||
}
|
||||
if value, ok := lu.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(license.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
_spec.AddModifiers(lu.modifiers...)
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, lu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{license.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
lu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// LicenseUpdateOne is the builder for updating a single License entity.
|
||||
type LicenseUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *LicenseMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (luo *LicenseUpdateOne) SetType(dt domain.LicenseType) *LicenseUpdateOne {
|
||||
luo.mutation.SetType(dt)
|
||||
return luo
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (luo *LicenseUpdateOne) SetNillableType(dt *domain.LicenseType) *LicenseUpdateOne {
|
||||
if dt != nil {
|
||||
luo.SetType(*dt)
|
||||
}
|
||||
return luo
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (luo *LicenseUpdateOne) SetData(b []byte) *LicenseUpdateOne {
|
||||
luo.mutation.SetData(b)
|
||||
return luo
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (luo *LicenseUpdateOne) ClearData() *LicenseUpdateOne {
|
||||
luo.mutation.ClearData()
|
||||
return luo
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (luo *LicenseUpdateOne) SetCode(s string) *LicenseUpdateOne {
|
||||
luo.mutation.SetCode(s)
|
||||
return luo
|
||||
}
|
||||
|
||||
// SetNillableCode sets the "code" field if the given value is not nil.
|
||||
func (luo *LicenseUpdateOne) SetNillableCode(s *string) *LicenseUpdateOne {
|
||||
if s != nil {
|
||||
luo.SetCode(*s)
|
||||
}
|
||||
return luo
|
||||
}
|
||||
|
||||
// ClearCode clears the value of the "code" field.
|
||||
func (luo *LicenseUpdateOne) ClearCode() *LicenseUpdateOne {
|
||||
luo.mutation.ClearCode()
|
||||
return luo
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (luo *LicenseUpdateOne) SetCreatedAt(t time.Time) *LicenseUpdateOne {
|
||||
luo.mutation.SetCreatedAt(t)
|
||||
return luo
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (luo *LicenseUpdateOne) SetNillableCreatedAt(t *time.Time) *LicenseUpdateOne {
|
||||
if t != nil {
|
||||
luo.SetCreatedAt(*t)
|
||||
}
|
||||
return luo
|
||||
}
|
||||
|
||||
// Mutation returns the LicenseMutation object of the builder.
|
||||
func (luo *LicenseUpdateOne) Mutation() *LicenseMutation {
|
||||
return luo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LicenseUpdate builder.
|
||||
func (luo *LicenseUpdateOne) Where(ps ...predicate.License) *LicenseUpdateOne {
|
||||
luo.mutation.Where(ps...)
|
||||
return luo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (luo *LicenseUpdateOne) Select(field string, fields ...string) *LicenseUpdateOne {
|
||||
luo.fields = append([]string{field}, fields...)
|
||||
return luo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated License entity.
|
||||
func (luo *LicenseUpdateOne) Save(ctx context.Context) (*License, error) {
|
||||
return withHooks(ctx, luo.sqlSave, luo.mutation, luo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (luo *LicenseUpdateOne) SaveX(ctx context.Context) *License {
|
||||
node, err := luo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (luo *LicenseUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := luo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (luo *LicenseUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := luo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (luo *LicenseUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *LicenseUpdateOne {
|
||||
luo.modifiers = append(luo.modifiers, modifiers...)
|
||||
return luo
|
||||
}
|
||||
|
||||
func (luo *LicenseUpdateOne) sqlSave(ctx context.Context) (_node *License, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(license.Table, license.Columns, sqlgraph.NewFieldSpec(license.FieldID, field.TypeInt))
|
||||
id, ok := luo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "License.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := luo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, license.FieldID)
|
||||
for _, f := range fields {
|
||||
if !license.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
||||
}
|
||||
if f != license.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := luo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := luo.mutation.GetType(); ok {
|
||||
_spec.SetField(license.FieldType, field.TypeString, value)
|
||||
}
|
||||
if value, ok := luo.mutation.Data(); ok {
|
||||
_spec.SetField(license.FieldData, field.TypeBytes, value)
|
||||
}
|
||||
if luo.mutation.DataCleared() {
|
||||
_spec.ClearField(license.FieldData, field.TypeBytes)
|
||||
}
|
||||
if value, ok := luo.mutation.Code(); ok {
|
||||
_spec.SetField(license.FieldCode, field.TypeString, value)
|
||||
}
|
||||
if luo.mutation.CodeCleared() {
|
||||
_spec.ClearField(license.FieldCode, field.TypeString)
|
||||
}
|
||||
if value, ok := luo.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(license.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
_spec.AddModifiers(luo.modifiers...)
|
||||
_node = &License{config: luo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, luo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{license.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
luo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -235,6 +235,20 @@ var (
|
||||
Columns: InviteCodesColumns,
|
||||
PrimaryKey: []*schema.Column{InviteCodesColumns[0]},
|
||||
}
|
||||
// LicenseColumns holds the columns for the "license" table.
|
||||
LicenseColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "type", Type: field.TypeString},
|
||||
{Name: "data", Type: field.TypeBytes, Nullable: true},
|
||||
{Name: "code", Type: field.TypeString, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
}
|
||||
// LicenseTable holds the schema information for the "license" table.
|
||||
LicenseTable = &schema.Table{
|
||||
Name: "license",
|
||||
Columns: LicenseColumns,
|
||||
PrimaryKey: []*schema.Column{LicenseColumns[0]},
|
||||
}
|
||||
// ModelsColumns holds the columns for the "models" table.
|
||||
ModelsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
@@ -607,6 +621,7 @@ var (
|
||||
CodeSnippetsTable,
|
||||
ExtensionsTable,
|
||||
InviteCodesTable,
|
||||
LicenseTable,
|
||||
ModelsTable,
|
||||
ModelProvidersTable,
|
||||
ModelProviderModelsTable,
|
||||
@@ -655,6 +670,9 @@ func init() {
|
||||
InviteCodesTable.Annotation = &entsql.Annotation{
|
||||
Table: "invite_codes",
|
||||
}
|
||||
LicenseTable.Annotation = &entsql.Annotation{
|
||||
Table: "license",
|
||||
}
|
||||
ModelsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
ModelsTable.Annotation = &entsql.Annotation{
|
||||
Table: "models",
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/db/codesnippet"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/extension"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/model"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovider"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovidermodel"
|
||||
@@ -35,6 +36,7 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/db/workspace"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/workspacefile"
|
||||
"github.com/chaitin/MonkeyCode/backend/ent/types"
|
||||
"github.com/chaitin/MonkeyCode/backend/pro/domain"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -57,6 +59,7 @@ const (
|
||||
TypeCodeSnippet = "CodeSnippet"
|
||||
TypeExtension = "Extension"
|
||||
TypeInviteCode = "InviteCode"
|
||||
TypeLicense = "License"
|
||||
TypeModel = "Model"
|
||||
TypeModelProvider = "ModelProvider"
|
||||
TypeModelProviderModel = "ModelProviderModel"
|
||||
@@ -8196,6 +8199,541 @@ func (m *InviteCodeMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown InviteCode edge %s", name)
|
||||
}
|
||||
|
||||
// LicenseMutation represents an operation that mutates the License nodes in the graph.
|
||||
type LicenseMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
_type *domain.LicenseType
|
||||
data *[]byte
|
||||
code *string
|
||||
created_at *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*License, error)
|
||||
predicates []predicate.License
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*LicenseMutation)(nil)
|
||||
|
||||
// licenseOption allows management of the mutation configuration using functional options.
|
||||
type licenseOption func(*LicenseMutation)
|
||||
|
||||
// newLicenseMutation creates new mutation for the License entity.
|
||||
func newLicenseMutation(c config, op Op, opts ...licenseOption) *LicenseMutation {
|
||||
m := &LicenseMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeLicense,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withLicenseID sets the ID field of the mutation.
|
||||
func withLicenseID(id int) licenseOption {
|
||||
return func(m *LicenseMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *License
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*License, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().License.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withLicense sets the old License of the mutation.
|
||||
func withLicense(node *License) licenseOption {
|
||||
return func(m *LicenseMutation) {
|
||||
m.oldValue = func(context.Context) (*License, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m LicenseMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m LicenseMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("db: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// SetID sets the value of the id field. Note that this
|
||||
// operation is only accepted on creation of License entities.
|
||||
func (m *LicenseMutation) SetID(id int) {
|
||||
m.id = &id
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *LicenseMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *LicenseMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().License.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (m *LicenseMutation) SetType(dt domain.LicenseType) {
|
||||
m._type = &dt
|
||||
}
|
||||
|
||||
// GetType returns the value of the "type" field in the mutation.
|
||||
func (m *LicenseMutation) GetType() (r domain.LicenseType, exists bool) {
|
||||
v := m._type
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldType returns the old "type" field's value of the License entity.
|
||||
// If the License object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *LicenseMutation) OldType(ctx context.Context) (v domain.LicenseType, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldType is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldType requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldType: %w", err)
|
||||
}
|
||||
return oldValue.Type, nil
|
||||
}
|
||||
|
||||
// ResetType resets all changes to the "type" field.
|
||||
func (m *LicenseMutation) ResetType() {
|
||||
m._type = nil
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (m *LicenseMutation) SetData(b []byte) {
|
||||
m.data = &b
|
||||
}
|
||||
|
||||
// Data returns the value of the "data" field in the mutation.
|
||||
func (m *LicenseMutation) Data() (r []byte, exists bool) {
|
||||
v := m.data
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldData returns the old "data" field's value of the License entity.
|
||||
// If the License object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *LicenseMutation) OldData(ctx context.Context) (v []byte, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldData is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldData requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldData: %w", err)
|
||||
}
|
||||
return oldValue.Data, nil
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (m *LicenseMutation) ClearData() {
|
||||
m.data = nil
|
||||
m.clearedFields[license.FieldData] = struct{}{}
|
||||
}
|
||||
|
||||
// DataCleared returns if the "data" field was cleared in this mutation.
|
||||
func (m *LicenseMutation) DataCleared() bool {
|
||||
_, ok := m.clearedFields[license.FieldData]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetData resets all changes to the "data" field.
|
||||
func (m *LicenseMutation) ResetData() {
|
||||
m.data = nil
|
||||
delete(m.clearedFields, license.FieldData)
|
||||
}
|
||||
|
||||
// SetCode sets the "code" field.
|
||||
func (m *LicenseMutation) SetCode(s string) {
|
||||
m.code = &s
|
||||
}
|
||||
|
||||
// Code returns the value of the "code" field in the mutation.
|
||||
func (m *LicenseMutation) Code() (r string, exists bool) {
|
||||
v := m.code
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCode returns the old "code" field's value of the License entity.
|
||||
// If the License object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *LicenseMutation) OldCode(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCode is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCode requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCode: %w", err)
|
||||
}
|
||||
return oldValue.Code, nil
|
||||
}
|
||||
|
||||
// ClearCode clears the value of the "code" field.
|
||||
func (m *LicenseMutation) ClearCode() {
|
||||
m.code = nil
|
||||
m.clearedFields[license.FieldCode] = struct{}{}
|
||||
}
|
||||
|
||||
// CodeCleared returns if the "code" field was cleared in this mutation.
|
||||
func (m *LicenseMutation) CodeCleared() bool {
|
||||
_, ok := m.clearedFields[license.FieldCode]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetCode resets all changes to the "code" field.
|
||||
func (m *LicenseMutation) ResetCode() {
|
||||
m.code = nil
|
||||
delete(m.clearedFields, license.FieldCode)
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (m *LicenseMutation) SetCreatedAt(t time.Time) {
|
||||
m.created_at = &t
|
||||
}
|
||||
|
||||
// CreatedAt returns the value of the "created_at" field in the mutation.
|
||||
func (m *LicenseMutation) CreatedAt() (r time.Time, exists bool) {
|
||||
v := m.created_at
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCreatedAt returns the old "created_at" field's value of the License entity.
|
||||
// If the License object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *LicenseMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
||||
}
|
||||
return oldValue.CreatedAt, nil
|
||||
}
|
||||
|
||||
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||
func (m *LicenseMutation) ResetCreatedAt() {
|
||||
m.created_at = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LicenseMutation builder.
|
||||
func (m *LicenseMutation) Where(ps ...predicate.License) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the LicenseMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *LicenseMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.License, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *LicenseMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *LicenseMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (License).
|
||||
func (m *LicenseMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *LicenseMutation) Fields() []string {
|
||||
fields := make([]string, 0, 4)
|
||||
if m._type != nil {
|
||||
fields = append(fields, license.FieldType)
|
||||
}
|
||||
if m.data != nil {
|
||||
fields = append(fields, license.FieldData)
|
||||
}
|
||||
if m.code != nil {
|
||||
fields = append(fields, license.FieldCode)
|
||||
}
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, license.FieldCreatedAt)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *LicenseMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case license.FieldType:
|
||||
return m.GetType()
|
||||
case license.FieldData:
|
||||
return m.Data()
|
||||
case license.FieldCode:
|
||||
return m.Code()
|
||||
case license.FieldCreatedAt:
|
||||
return m.CreatedAt()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *LicenseMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case license.FieldType:
|
||||
return m.OldType(ctx)
|
||||
case license.FieldData:
|
||||
return m.OldData(ctx)
|
||||
case license.FieldCode:
|
||||
return m.OldCode(ctx)
|
||||
case license.FieldCreatedAt:
|
||||
return m.OldCreatedAt(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown License field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *LicenseMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case license.FieldType:
|
||||
v, ok := value.(domain.LicenseType)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetType(v)
|
||||
return nil
|
||||
case license.FieldData:
|
||||
v, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetData(v)
|
||||
return nil
|
||||
case license.FieldCode:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCode(v)
|
||||
return nil
|
||||
case license.FieldCreatedAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCreatedAt(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown License field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *LicenseMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *LicenseMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *LicenseMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown License numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *LicenseMutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(license.FieldData) {
|
||||
fields = append(fields, license.FieldData)
|
||||
}
|
||||
if m.FieldCleared(license.FieldCode) {
|
||||
fields = append(fields, license.FieldCode)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *LicenseMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *LicenseMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case license.FieldData:
|
||||
m.ClearData()
|
||||
return nil
|
||||
case license.FieldCode:
|
||||
m.ClearCode()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown License nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *LicenseMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case license.FieldType:
|
||||
m.ResetType()
|
||||
return nil
|
||||
case license.FieldData:
|
||||
m.ResetData()
|
||||
return nil
|
||||
case license.FieldCode:
|
||||
m.ResetCode()
|
||||
return nil
|
||||
case license.FieldCreatedAt:
|
||||
m.ResetCreatedAt()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown License field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *LicenseMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *LicenseMutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *LicenseMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *LicenseMutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *LicenseMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *LicenseMutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *LicenseMutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown License unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *LicenseMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown License edge %s", name)
|
||||
}
|
||||
|
||||
// ModelMutation represents an operation that mutates the Model nodes in the graph.
|
||||
type ModelMutation struct {
|
||||
config
|
||||
|
||||
@@ -151,6 +151,20 @@ func (ic *InviteCodeQuery) Page(ctx context.Context, page, size int) ([]*InviteC
|
||||
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
|
||||
}
|
||||
|
||||
func (l *LicenseQuery) Page(ctx context.Context, page, size int) ([]*License, *PageInfo, error) {
|
||||
cnt, err := l.Count(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
offset := size * (page - 1)
|
||||
rs, err := l.Offset(offset).Limit(size).All(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
has := (page * size) < cnt
|
||||
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
|
||||
}
|
||||
|
||||
func (m *ModelQuery) Page(ctx context.Context, page, size int) ([]*Model, *PageInfo, error) {
|
||||
cnt, err := m.Count(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -36,6 +36,9 @@ type Extension func(*sql.Selector)
|
||||
// InviteCode is the predicate function for invitecode builders.
|
||||
type InviteCode func(*sql.Selector)
|
||||
|
||||
// License is the predicate function for license builders.
|
||||
type License func(*sql.Selector)
|
||||
|
||||
// Model is the predicate function for model builders.
|
||||
type Model func(*sql.Selector)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/db/billingusage"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/extension"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/license"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/model"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovider"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/modelprovidermodel"
|
||||
@@ -156,6 +157,16 @@ func init() {
|
||||
invitecode.DefaultUpdatedAt = invitecodeDescUpdatedAt.Default.(func() time.Time)
|
||||
// invitecode.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
invitecode.UpdateDefaultUpdatedAt = invitecodeDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
licenseFields := schema.License{}.Fields()
|
||||
_ = licenseFields
|
||||
// licenseDescCreatedAt is the schema descriptor for created_at field.
|
||||
licenseDescCreatedAt := licenseFields[4].Descriptor()
|
||||
// license.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
license.DefaultCreatedAt = licenseDescCreatedAt.Default.(func() time.Time)
|
||||
// licenseDescID is the schema descriptor for id field.
|
||||
licenseDescID := licenseFields[0].Descriptor()
|
||||
// license.IDValidator is a validator for the "id" field. It is called by the builders before save.
|
||||
license.IDValidator = licenseDescID.Validators[0].(func(int) error)
|
||||
modelFields := schema.Model{}.Fields()
|
||||
_ = modelFields
|
||||
// modelDescIsInternal is the schema descriptor for is_internal field.
|
||||
|
||||
@@ -34,6 +34,8 @@ type Tx struct {
|
||||
Extension *ExtensionClient
|
||||
// InviteCode is the client for interacting with the InviteCode builders.
|
||||
InviteCode *InviteCodeClient
|
||||
// License is the client for interacting with the License builders.
|
||||
License *LicenseClient
|
||||
// Model is the client for interacting with the Model builders.
|
||||
Model *ModelClient
|
||||
// ModelProvider is the client for interacting with the ModelProvider builders.
|
||||
@@ -197,6 +199,7 @@ func (tx *Tx) init() {
|
||||
tx.CodeSnippet = NewCodeSnippetClient(tx.config)
|
||||
tx.Extension = NewExtensionClient(tx.config)
|
||||
tx.InviteCode = NewInviteCodeClient(tx.config)
|
||||
tx.License = NewLicenseClient(tx.config)
|
||||
tx.Model = NewModelClient(tx.config)
|
||||
tx.ModelProvider = NewModelProviderClient(tx.config)
|
||||
tx.ModelProviderModel = NewModelProviderModelClient(tx.config)
|
||||
|
||||
41
backend/ent/schema/license.go
Normal file
41
backend/ent/schema/license.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
|
||||
"github.com/chaitin/MonkeyCode/backend/pro/domain"
|
||||
)
|
||||
|
||||
// License holds the schema definition for the License entity.
|
||||
type License struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (License) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{
|
||||
Table: "license",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the License.
|
||||
func (License) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive().Unique(),
|
||||
field.String("type").GoType(domain.LicenseType("")),
|
||||
field.Bytes("data").Optional(),
|
||||
field.String("code").Optional(),
|
||||
field.Time("created_at").Default(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the License.
|
||||
func (License) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -22,6 +22,8 @@ require (
|
||||
golang.org/x/oauth2 v0.18.0
|
||||
golang.org/x/text v0.26.0
|
||||
golang.org/x/time v0.11.0
|
||||
google.golang.org/grpc v1.64.1
|
||||
google.golang.org/protobuf v1.36.1
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -112,7 +114,7 @@ require (
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/tools v0.33.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/protobuf v1.36.1 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -405,6 +405,10 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
|
||||
google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA=
|
||||
google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
|
||||
|
||||
Reference in New Issue
Block a user