// Code generated by ent, DO NOT EDIT. package db import ( "context" "errors" "fmt" "sync" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/chaitin/MonkeyCode/backend/consts" "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/apikey" "github.com/chaitin/MonkeyCode/backend/db/billingplan" "github.com/chaitin/MonkeyCode/backend/db/billingquota" "github.com/chaitin/MonkeyCode/backend/db/billingrecord" "github.com/chaitin/MonkeyCode/backend/db/billingusage" "github.com/chaitin/MonkeyCode/backend/db/invitecode" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/chaitin/MonkeyCode/backend/db/setting" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskrecord" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/userloginhistory" "github.com/google/uuid" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeAdmin = "Admin" TypeAdminLoginHistory = "AdminLoginHistory" TypeApiKey = "ApiKey" TypeBillingPlan = "BillingPlan" TypeBillingQuota = "BillingQuota" TypeBillingRecord = "BillingRecord" TypeBillingUsage = "BillingUsage" TypeInviteCode = "InviteCode" TypeModel = "Model" TypeSetting = "Setting" TypeTask = "Task" TypeTaskRecord = "TaskRecord" TypeUser = "User" TypeUserLoginHistory = "UserLoginHistory" ) // AdminMutation represents an operation that mutates the Admin nodes in the graph. type AdminMutation struct { config op Op typ string id *uuid.UUID username *string password *string status *consts.AdminStatus last_active_at *time.Time created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} login_histories map[uuid.UUID]struct{} removedlogin_histories map[uuid.UUID]struct{} clearedlogin_histories bool done bool oldValue func(context.Context) (*Admin, error) predicates []predicate.Admin } var _ ent.Mutation = (*AdminMutation)(nil) // adminOption allows management of the mutation configuration using functional options. type adminOption func(*AdminMutation) // newAdminMutation creates new mutation for the Admin entity. func newAdminMutation(c config, op Op, opts ...adminOption) *AdminMutation { m := &AdminMutation{ config: c, op: op, typ: TypeAdmin, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAdminID sets the ID field of the mutation. func withAdminID(id uuid.UUID) adminOption { return func(m *AdminMutation) { var ( err error once sync.Once value *Admin ) m.oldValue = func(ctx context.Context) (*Admin, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Admin.Get(ctx, id) } }) return value, err } m.id = &id } } // withAdmin sets the old Admin of the mutation. func withAdmin(node *Admin) adminOption { return func(m *AdminMutation) { m.oldValue = func(context.Context) (*Admin, 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 AdminMutation) 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 AdminMutation) 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 Admin entities. func (m *AdminMutation) SetID(id uuid.UUID) { 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 *AdminMutation) ID() (id uuid.UUID, 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 *AdminMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Admin.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUsername sets the "username" field. func (m *AdminMutation) SetUsername(s string) { m.username = &s } // Username returns the value of the "username" field in the mutation. func (m *AdminMutation) Username() (r string, exists bool) { v := m.username if v == nil { return } return *v, true } // OldUsername returns the old "username" field's value of the Admin entity. // If the Admin 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 *AdminMutation) OldUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUsername: %w", err) } return oldValue.Username, nil } // ResetUsername resets all changes to the "username" field. func (m *AdminMutation) ResetUsername() { m.username = nil } // SetPassword sets the "password" field. func (m *AdminMutation) SetPassword(s string) { m.password = &s } // Password returns the value of the "password" field in the mutation. func (m *AdminMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old "password" field's value of the Admin entity. // If the Admin 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 *AdminMutation) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPassword requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPassword: %w", err) } return oldValue.Password, nil } // ResetPassword resets all changes to the "password" field. func (m *AdminMutation) ResetPassword() { m.password = nil } // SetStatus sets the "status" field. func (m *AdminMutation) SetStatus(cs consts.AdminStatus) { m.status = &cs } // Status returns the value of the "status" field in the mutation. func (m *AdminMutation) Status() (r consts.AdminStatus, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Admin entity. // If the Admin 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 *AdminMutation) OldStatus(ctx context.Context) (v consts.AdminStatus, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *AdminMutation) ResetStatus() { m.status = nil } // SetLastActiveAt sets the "last_active_at" field. func (m *AdminMutation) SetLastActiveAt(t time.Time) { m.last_active_at = &t } // LastActiveAt returns the value of the "last_active_at" field in the mutation. func (m *AdminMutation) LastActiveAt() (r time.Time, exists bool) { v := m.last_active_at if v == nil { return } return *v, true } // OldLastActiveAt returns the old "last_active_at" field's value of the Admin entity. // If the Admin 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 *AdminMutation) OldLastActiveAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastActiveAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastActiveAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastActiveAt: %w", err) } return oldValue.LastActiveAt, nil } // ResetLastActiveAt resets all changes to the "last_active_at" field. func (m *AdminMutation) ResetLastActiveAt() { m.last_active_at = nil } // SetCreatedAt sets the "created_at" field. func (m *AdminMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *AdminMutation) 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 Admin entity. // If the Admin 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 *AdminMutation) 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 *AdminMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *AdminMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *AdminMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Admin entity. // If the Admin 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 *AdminMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *AdminMutation) ResetUpdatedAt() { m.updated_at = nil } // AddLoginHistoryIDs adds the "login_histories" edge to the AdminLoginHistory entity by ids. func (m *AdminMutation) AddLoginHistoryIDs(ids ...uuid.UUID) { if m.login_histories == nil { m.login_histories = make(map[uuid.UUID]struct{}) } for i := range ids { m.login_histories[ids[i]] = struct{}{} } } // ClearLoginHistories clears the "login_histories" edge to the AdminLoginHistory entity. func (m *AdminMutation) ClearLoginHistories() { m.clearedlogin_histories = true } // LoginHistoriesCleared reports if the "login_histories" edge to the AdminLoginHistory entity was cleared. func (m *AdminMutation) LoginHistoriesCleared() bool { return m.clearedlogin_histories } // RemoveLoginHistoryIDs removes the "login_histories" edge to the AdminLoginHistory entity by IDs. func (m *AdminMutation) RemoveLoginHistoryIDs(ids ...uuid.UUID) { if m.removedlogin_histories == nil { m.removedlogin_histories = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.login_histories, ids[i]) m.removedlogin_histories[ids[i]] = struct{}{} } } // RemovedLoginHistories returns the removed IDs of the "login_histories" edge to the AdminLoginHistory entity. func (m *AdminMutation) RemovedLoginHistoriesIDs() (ids []uuid.UUID) { for id := range m.removedlogin_histories { ids = append(ids, id) } return } // LoginHistoriesIDs returns the "login_histories" edge IDs in the mutation. func (m *AdminMutation) LoginHistoriesIDs() (ids []uuid.UUID) { for id := range m.login_histories { ids = append(ids, id) } return } // ResetLoginHistories resets all changes to the "login_histories" edge. func (m *AdminMutation) ResetLoginHistories() { m.login_histories = nil m.clearedlogin_histories = false m.removedlogin_histories = nil } // Where appends a list predicates to the AdminMutation builder. func (m *AdminMutation) Where(ps ...predicate.Admin) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AdminMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AdminMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Admin, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AdminMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AdminMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Admin). func (m *AdminMutation) 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 *AdminMutation) Fields() []string { fields := make([]string, 0, 6) if m.username != nil { fields = append(fields, admin.FieldUsername) } if m.password != nil { fields = append(fields, admin.FieldPassword) } if m.status != nil { fields = append(fields, admin.FieldStatus) } if m.last_active_at != nil { fields = append(fields, admin.FieldLastActiveAt) } if m.created_at != nil { fields = append(fields, admin.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, admin.FieldUpdatedAt) } 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 *AdminMutation) Field(name string) (ent.Value, bool) { switch name { case admin.FieldUsername: return m.Username() case admin.FieldPassword: return m.Password() case admin.FieldStatus: return m.Status() case admin.FieldLastActiveAt: return m.LastActiveAt() case admin.FieldCreatedAt: return m.CreatedAt() case admin.FieldUpdatedAt: return m.UpdatedAt() } 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 *AdminMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case admin.FieldUsername: return m.OldUsername(ctx) case admin.FieldPassword: return m.OldPassword(ctx) case admin.FieldStatus: return m.OldStatus(ctx) case admin.FieldLastActiveAt: return m.OldLastActiveAt(ctx) case admin.FieldCreatedAt: return m.OldCreatedAt(ctx) case admin.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Admin 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 *AdminMutation) SetField(name string, value ent.Value) error { switch name { case admin.FieldUsername: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsername(v) return nil case admin.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(v) return nil case admin.FieldStatus: v, ok := value.(consts.AdminStatus) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case admin.FieldLastActiveAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastActiveAt(v) return nil case admin.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case admin.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Admin field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AdminMutation) 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 *AdminMutation) 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 *AdminMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Admin numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AdminMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AdminMutation) 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 *AdminMutation) ClearField(name string) error { return fmt.Errorf("unknown Admin 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 *AdminMutation) ResetField(name string) error { switch name { case admin.FieldUsername: m.ResetUsername() return nil case admin.FieldPassword: m.ResetPassword() return nil case admin.FieldStatus: m.ResetStatus() return nil case admin.FieldLastActiveAt: m.ResetLastActiveAt() return nil case admin.FieldCreatedAt: m.ResetCreatedAt() return nil case admin.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Admin field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AdminMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.login_histories != nil { edges = append(edges, admin.EdgeLoginHistories) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AdminMutation) AddedIDs(name string) []ent.Value { switch name { case admin.EdgeLoginHistories: ids := make([]ent.Value, 0, len(m.login_histories)) for id := range m.login_histories { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AdminMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedlogin_histories != nil { edges = append(edges, admin.EdgeLoginHistories) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AdminMutation) RemovedIDs(name string) []ent.Value { switch name { case admin.EdgeLoginHistories: ids := make([]ent.Value, 0, len(m.removedlogin_histories)) for id := range m.removedlogin_histories { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AdminMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedlogin_histories { edges = append(edges, admin.EdgeLoginHistories) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AdminMutation) EdgeCleared(name string) bool { switch name { case admin.EdgeLoginHistories: return m.clearedlogin_histories } 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 *AdminMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Admin 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 *AdminMutation) ResetEdge(name string) error { switch name { case admin.EdgeLoginHistories: m.ResetLoginHistories() return nil } return fmt.Errorf("unknown Admin edge %s", name) } // AdminLoginHistoryMutation represents an operation that mutates the AdminLoginHistory nodes in the graph. type AdminLoginHistoryMutation struct { config op Op typ string id *uuid.UUID admin_id *uuid.UUID ip *string country *string province *string city *string isp *string asn *string client_version *string device *string created_at *time.Time clearedFields map[string]struct{} owner *uuid.UUID clearedowner bool done bool oldValue func(context.Context) (*AdminLoginHistory, error) predicates []predicate.AdminLoginHistory } var _ ent.Mutation = (*AdminLoginHistoryMutation)(nil) // adminloginhistoryOption allows management of the mutation configuration using functional options. type adminloginhistoryOption func(*AdminLoginHistoryMutation) // newAdminLoginHistoryMutation creates new mutation for the AdminLoginHistory entity. func newAdminLoginHistoryMutation(c config, op Op, opts ...adminloginhistoryOption) *AdminLoginHistoryMutation { m := &AdminLoginHistoryMutation{ config: c, op: op, typ: TypeAdminLoginHistory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAdminLoginHistoryID sets the ID field of the mutation. func withAdminLoginHistoryID(id uuid.UUID) adminloginhistoryOption { return func(m *AdminLoginHistoryMutation) { var ( err error once sync.Once value *AdminLoginHistory ) m.oldValue = func(ctx context.Context) (*AdminLoginHistory, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AdminLoginHistory.Get(ctx, id) } }) return value, err } m.id = &id } } // withAdminLoginHistory sets the old AdminLoginHistory of the mutation. func withAdminLoginHistory(node *AdminLoginHistory) adminloginhistoryOption { return func(m *AdminLoginHistoryMutation) { m.oldValue = func(context.Context) (*AdminLoginHistory, 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 AdminLoginHistoryMutation) 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 AdminLoginHistoryMutation) 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 AdminLoginHistory entities. func (m *AdminLoginHistoryMutation) SetID(id uuid.UUID) { 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 *AdminLoginHistoryMutation) ID() (id uuid.UUID, 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 *AdminLoginHistoryMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().AdminLoginHistory.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetAdminID sets the "admin_id" field. func (m *AdminLoginHistoryMutation) SetAdminID(u uuid.UUID) { m.admin_id = &u } // AdminID returns the value of the "admin_id" field in the mutation. func (m *AdminLoginHistoryMutation) AdminID() (r uuid.UUID, exists bool) { v := m.admin_id if v == nil { return } return *v, true } // OldAdminID returns the old "admin_id" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldAdminID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAdminID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAdminID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAdminID: %w", err) } return oldValue.AdminID, nil } // ResetAdminID resets all changes to the "admin_id" field. func (m *AdminLoginHistoryMutation) ResetAdminID() { m.admin_id = nil } // SetIP sets the "ip" field. func (m *AdminLoginHistoryMutation) SetIP(s string) { m.ip = &s } // IP returns the value of the "ip" field in the mutation. func (m *AdminLoginHistoryMutation) IP() (r string, exists bool) { v := m.ip if v == nil { return } return *v, true } // OldIP returns the old "ip" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldIP(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIP requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIP: %w", err) } return oldValue.IP, nil } // ResetIP resets all changes to the "ip" field. func (m *AdminLoginHistoryMutation) ResetIP() { m.ip = nil } // SetCountry sets the "country" field. func (m *AdminLoginHistoryMutation) SetCountry(s string) { m.country = &s } // Country returns the value of the "country" field in the mutation. func (m *AdminLoginHistoryMutation) Country() (r string, exists bool) { v := m.country if v == nil { return } return *v, true } // OldCountry returns the old "country" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldCountry(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCountry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCountry requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCountry: %w", err) } return oldValue.Country, nil } // ResetCountry resets all changes to the "country" field. func (m *AdminLoginHistoryMutation) ResetCountry() { m.country = nil } // SetProvince sets the "province" field. func (m *AdminLoginHistoryMutation) SetProvince(s string) { m.province = &s } // Province returns the value of the "province" field in the mutation. func (m *AdminLoginHistoryMutation) Province() (r string, exists bool) { v := m.province if v == nil { return } return *v, true } // OldProvince returns the old "province" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldProvince(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProvince is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProvince requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProvince: %w", err) } return oldValue.Province, nil } // ResetProvince resets all changes to the "province" field. func (m *AdminLoginHistoryMutation) ResetProvince() { m.province = nil } // SetCity sets the "city" field. func (m *AdminLoginHistoryMutation) SetCity(s string) { m.city = &s } // City returns the value of the "city" field in the mutation. func (m *AdminLoginHistoryMutation) City() (r string, exists bool) { v := m.city if v == nil { return } return *v, true } // OldCity returns the old "city" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldCity(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCity is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCity requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCity: %w", err) } return oldValue.City, nil } // ResetCity resets all changes to the "city" field. func (m *AdminLoginHistoryMutation) ResetCity() { m.city = nil } // SetIsp sets the "isp" field. func (m *AdminLoginHistoryMutation) SetIsp(s string) { m.isp = &s } // Isp returns the value of the "isp" field in the mutation. func (m *AdminLoginHistoryMutation) Isp() (r string, exists bool) { v := m.isp if v == nil { return } return *v, true } // OldIsp returns the old "isp" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldIsp(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIsp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIsp requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIsp: %w", err) } return oldValue.Isp, nil } // ResetIsp resets all changes to the "isp" field. func (m *AdminLoginHistoryMutation) ResetIsp() { m.isp = nil } // SetAsn sets the "asn" field. func (m *AdminLoginHistoryMutation) SetAsn(s string) { m.asn = &s } // Asn returns the value of the "asn" field in the mutation. func (m *AdminLoginHistoryMutation) Asn() (r string, exists bool) { v := m.asn if v == nil { return } return *v, true } // OldAsn returns the old "asn" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldAsn(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAsn is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAsn requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAsn: %w", err) } return oldValue.Asn, nil } // ResetAsn resets all changes to the "asn" field. func (m *AdminLoginHistoryMutation) ResetAsn() { m.asn = nil } // SetClientVersion sets the "client_version" field. func (m *AdminLoginHistoryMutation) SetClientVersion(s string) { m.client_version = &s } // ClientVersion returns the value of the "client_version" field in the mutation. func (m *AdminLoginHistoryMutation) ClientVersion() (r string, exists bool) { v := m.client_version if v == nil { return } return *v, true } // OldClientVersion returns the old "client_version" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldClientVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldClientVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldClientVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldClientVersion: %w", err) } return oldValue.ClientVersion, nil } // ResetClientVersion resets all changes to the "client_version" field. func (m *AdminLoginHistoryMutation) ResetClientVersion() { m.client_version = nil } // SetDevice sets the "device" field. func (m *AdminLoginHistoryMutation) SetDevice(s string) { m.device = &s } // Device returns the value of the "device" field in the mutation. func (m *AdminLoginHistoryMutation) Device() (r string, exists bool) { v := m.device if v == nil { return } return *v, true } // OldDevice returns the old "device" field's value of the AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) OldDevice(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDevice is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDevice requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDevice: %w", err) } return oldValue.Device, nil } // ResetDevice resets all changes to the "device" field. func (m *AdminLoginHistoryMutation) ResetDevice() { m.device = nil } // SetCreatedAt sets the "created_at" field. func (m *AdminLoginHistoryMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *AdminLoginHistoryMutation) 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 AdminLoginHistory entity. // If the AdminLoginHistory 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 *AdminLoginHistoryMutation) 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 *AdminLoginHistoryMutation) ResetCreatedAt() { m.created_at = nil } // SetOwnerID sets the "owner" edge to the Admin entity by id. func (m *AdminLoginHistoryMutation) SetOwnerID(id uuid.UUID) { m.owner = &id } // ClearOwner clears the "owner" edge to the Admin entity. func (m *AdminLoginHistoryMutation) ClearOwner() { m.clearedowner = true } // OwnerCleared reports if the "owner" edge to the Admin entity was cleared. func (m *AdminLoginHistoryMutation) OwnerCleared() bool { return m.clearedowner } // OwnerID returns the "owner" edge ID in the mutation. func (m *AdminLoginHistoryMutation) OwnerID() (id uuid.UUID, exists bool) { if m.owner != nil { return *m.owner, true } return } // OwnerIDs returns the "owner" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *AdminLoginHistoryMutation) OwnerIDs() (ids []uuid.UUID) { if id := m.owner; id != nil { ids = append(ids, *id) } return } // ResetOwner resets all changes to the "owner" edge. func (m *AdminLoginHistoryMutation) ResetOwner() { m.owner = nil m.clearedowner = false } // Where appends a list predicates to the AdminLoginHistoryMutation builder. func (m *AdminLoginHistoryMutation) Where(ps ...predicate.AdminLoginHistory) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AdminLoginHistoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AdminLoginHistoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.AdminLoginHistory, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AdminLoginHistoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AdminLoginHistoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (AdminLoginHistory). func (m *AdminLoginHistoryMutation) 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 *AdminLoginHistoryMutation) Fields() []string { fields := make([]string, 0, 10) if m.admin_id != nil { fields = append(fields, adminloginhistory.FieldAdminID) } if m.ip != nil { fields = append(fields, adminloginhistory.FieldIP) } if m.country != nil { fields = append(fields, adminloginhistory.FieldCountry) } if m.province != nil { fields = append(fields, adminloginhistory.FieldProvince) } if m.city != nil { fields = append(fields, adminloginhistory.FieldCity) } if m.isp != nil { fields = append(fields, adminloginhistory.FieldIsp) } if m.asn != nil { fields = append(fields, adminloginhistory.FieldAsn) } if m.client_version != nil { fields = append(fields, adminloginhistory.FieldClientVersion) } if m.device != nil { fields = append(fields, adminloginhistory.FieldDevice) } if m.created_at != nil { fields = append(fields, adminloginhistory.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 *AdminLoginHistoryMutation) Field(name string) (ent.Value, bool) { switch name { case adminloginhistory.FieldAdminID: return m.AdminID() case adminloginhistory.FieldIP: return m.IP() case adminloginhistory.FieldCountry: return m.Country() case adminloginhistory.FieldProvince: return m.Province() case adminloginhistory.FieldCity: return m.City() case adminloginhistory.FieldIsp: return m.Isp() case adminloginhistory.FieldAsn: return m.Asn() case adminloginhistory.FieldClientVersion: return m.ClientVersion() case adminloginhistory.FieldDevice: return m.Device() case adminloginhistory.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 *AdminLoginHistoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case adminloginhistory.FieldAdminID: return m.OldAdminID(ctx) case adminloginhistory.FieldIP: return m.OldIP(ctx) case adminloginhistory.FieldCountry: return m.OldCountry(ctx) case adminloginhistory.FieldProvince: return m.OldProvince(ctx) case adminloginhistory.FieldCity: return m.OldCity(ctx) case adminloginhistory.FieldIsp: return m.OldIsp(ctx) case adminloginhistory.FieldAsn: return m.OldAsn(ctx) case adminloginhistory.FieldClientVersion: return m.OldClientVersion(ctx) case adminloginhistory.FieldDevice: return m.OldDevice(ctx) case adminloginhistory.FieldCreatedAt: return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown AdminLoginHistory 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 *AdminLoginHistoryMutation) SetField(name string, value ent.Value) error { switch name { case adminloginhistory.FieldAdminID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAdminID(v) return nil case adminloginhistory.FieldIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIP(v) return nil case adminloginhistory.FieldCountry: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCountry(v) return nil case adminloginhistory.FieldProvince: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProvince(v) return nil case adminloginhistory.FieldCity: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCity(v) return nil case adminloginhistory.FieldIsp: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIsp(v) return nil case adminloginhistory.FieldAsn: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAsn(v) return nil case adminloginhistory.FieldClientVersion: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetClientVersion(v) return nil case adminloginhistory.FieldDevice: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDevice(v) return nil case adminloginhistory.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 AdminLoginHistory field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AdminLoginHistoryMutation) 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 *AdminLoginHistoryMutation) 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 *AdminLoginHistoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown AdminLoginHistory numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AdminLoginHistoryMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AdminLoginHistoryMutation) 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 *AdminLoginHistoryMutation) ClearField(name string) error { return fmt.Errorf("unknown AdminLoginHistory 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 *AdminLoginHistoryMutation) ResetField(name string) error { switch name { case adminloginhistory.FieldAdminID: m.ResetAdminID() return nil case adminloginhistory.FieldIP: m.ResetIP() return nil case adminloginhistory.FieldCountry: m.ResetCountry() return nil case adminloginhistory.FieldProvince: m.ResetProvince() return nil case adminloginhistory.FieldCity: m.ResetCity() return nil case adminloginhistory.FieldIsp: m.ResetIsp() return nil case adminloginhistory.FieldAsn: m.ResetAsn() return nil case adminloginhistory.FieldClientVersion: m.ResetClientVersion() return nil case adminloginhistory.FieldDevice: m.ResetDevice() return nil case adminloginhistory.FieldCreatedAt: m.ResetCreatedAt() return nil } return fmt.Errorf("unknown AdminLoginHistory field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AdminLoginHistoryMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { edges = append(edges, adminloginhistory.EdgeOwner) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AdminLoginHistoryMutation) AddedIDs(name string) []ent.Value { switch name { case adminloginhistory.EdgeOwner: if id := m.owner; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AdminLoginHistoryMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AdminLoginHistoryMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AdminLoginHistoryMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { edges = append(edges, adminloginhistory.EdgeOwner) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AdminLoginHistoryMutation) EdgeCleared(name string) bool { switch name { case adminloginhistory.EdgeOwner: return m.clearedowner } 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 *AdminLoginHistoryMutation) ClearEdge(name string) error { switch name { case adminloginhistory.EdgeOwner: m.ClearOwner() return nil } return fmt.Errorf("unknown AdminLoginHistory 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 *AdminLoginHistoryMutation) ResetEdge(name string) error { switch name { case adminloginhistory.EdgeOwner: m.ResetOwner() return nil } return fmt.Errorf("unknown AdminLoginHistory edge %s", name) } // ApiKeyMutation represents an operation that mutates the ApiKey nodes in the graph. type ApiKeyMutation struct { config op Op typ string id *uuid.UUID user_id *uuid.UUID key *string name *string status *consts.ApiKeyStatus last_used *time.Time created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*ApiKey, error) predicates []predicate.ApiKey } var _ ent.Mutation = (*ApiKeyMutation)(nil) // apikeyOption allows management of the mutation configuration using functional options. type apikeyOption func(*ApiKeyMutation) // newApiKeyMutation creates new mutation for the ApiKey entity. func newApiKeyMutation(c config, op Op, opts ...apikeyOption) *ApiKeyMutation { m := &ApiKeyMutation{ config: c, op: op, typ: TypeApiKey, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withApiKeyID sets the ID field of the mutation. func withApiKeyID(id uuid.UUID) apikeyOption { return func(m *ApiKeyMutation) { var ( err error once sync.Once value *ApiKey ) m.oldValue = func(ctx context.Context) (*ApiKey, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().ApiKey.Get(ctx, id) } }) return value, err } m.id = &id } } // withApiKey sets the old ApiKey of the mutation. func withApiKey(node *ApiKey) apikeyOption { return func(m *ApiKeyMutation) { m.oldValue = func(context.Context) (*ApiKey, 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 ApiKeyMutation) 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 ApiKeyMutation) 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 ApiKey entities. func (m *ApiKeyMutation) SetID(id uuid.UUID) { 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 *ApiKeyMutation) ID() (id uuid.UUID, 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 *ApiKeyMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().ApiKey.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUserID sets the "user_id" field. func (m *ApiKeyMutation) SetUserID(u uuid.UUID) { m.user_id = &u } // UserID returns the value of the "user_id" field in the mutation. func (m *ApiKeyMutation) UserID() (r uuid.UUID, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *ApiKeyMutation) ResetUserID() { m.user_id = nil } // SetKey sets the "key" field. func (m *ApiKeyMutation) SetKey(s string) { m.key = &s } // Key returns the value of the "key" field in the mutation. func (m *ApiKeyMutation) Key() (r string, exists bool) { v := m.key if v == nil { return } return *v, true } // OldKey returns the old "key" field's value of the ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) OldKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldKey requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldKey: %w", err) } return oldValue.Key, nil } // ResetKey resets all changes to the "key" field. func (m *ApiKeyMutation) ResetKey() { m.key = nil } // SetName sets the "name" field. func (m *ApiKeyMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ApiKeyMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *ApiKeyMutation) ResetName() { m.name = nil } // SetStatus sets the "status" field. func (m *ApiKeyMutation) SetStatus(cks consts.ApiKeyStatus) { m.status = &cks } // Status returns the value of the "status" field in the mutation. func (m *ApiKeyMutation) Status() (r consts.ApiKeyStatus, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) OldStatus(ctx context.Context) (v consts.ApiKeyStatus, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *ApiKeyMutation) ResetStatus() { m.status = nil } // SetLastUsed sets the "last_used" field. func (m *ApiKeyMutation) SetLastUsed(t time.Time) { m.last_used = &t } // LastUsed returns the value of the "last_used" field in the mutation. func (m *ApiKeyMutation) LastUsed() (r time.Time, exists bool) { v := m.last_used if v == nil { return } return *v, true } // OldLastUsed returns the old "last_used" field's value of the ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) OldLastUsed(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastUsed is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastUsed requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastUsed: %w", err) } return oldValue.LastUsed, nil } // ClearLastUsed clears the value of the "last_used" field. func (m *ApiKeyMutation) ClearLastUsed() { m.last_used = nil m.clearedFields[apikey.FieldLastUsed] = struct{}{} } // LastUsedCleared returns if the "last_used" field was cleared in this mutation. func (m *ApiKeyMutation) LastUsedCleared() bool { _, ok := m.clearedFields[apikey.FieldLastUsed] return ok } // ResetLastUsed resets all changes to the "last_used" field. func (m *ApiKeyMutation) ResetLastUsed() { m.last_used = nil delete(m.clearedFields, apikey.FieldLastUsed) } // SetCreatedAt sets the "created_at" field. func (m *ApiKeyMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *ApiKeyMutation) 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 ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) 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 *ApiKeyMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *ApiKeyMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *ApiKeyMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the ApiKey entity. // If the ApiKey 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 *ApiKeyMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *ApiKeyMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the ApiKeyMutation builder. func (m *ApiKeyMutation) Where(ps ...predicate.ApiKey) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ApiKeyMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ApiKeyMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.ApiKey, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ApiKeyMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ApiKeyMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (ApiKey). func (m *ApiKeyMutation) 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 *ApiKeyMutation) Fields() []string { fields := make([]string, 0, 7) if m.user_id != nil { fields = append(fields, apikey.FieldUserID) } if m.key != nil { fields = append(fields, apikey.FieldKey) } if m.name != nil { fields = append(fields, apikey.FieldName) } if m.status != nil { fields = append(fields, apikey.FieldStatus) } if m.last_used != nil { fields = append(fields, apikey.FieldLastUsed) } if m.created_at != nil { fields = append(fields, apikey.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, apikey.FieldUpdatedAt) } 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 *ApiKeyMutation) Field(name string) (ent.Value, bool) { switch name { case apikey.FieldUserID: return m.UserID() case apikey.FieldKey: return m.Key() case apikey.FieldName: return m.Name() case apikey.FieldStatus: return m.Status() case apikey.FieldLastUsed: return m.LastUsed() case apikey.FieldCreatedAt: return m.CreatedAt() case apikey.FieldUpdatedAt: return m.UpdatedAt() } 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 *ApiKeyMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case apikey.FieldUserID: return m.OldUserID(ctx) case apikey.FieldKey: return m.OldKey(ctx) case apikey.FieldName: return m.OldName(ctx) case apikey.FieldStatus: return m.OldStatus(ctx) case apikey.FieldLastUsed: return m.OldLastUsed(ctx) case apikey.FieldCreatedAt: return m.OldCreatedAt(ctx) case apikey.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown ApiKey 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 *ApiKeyMutation) SetField(name string, value ent.Value) error { switch name { case apikey.FieldUserID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case apikey.FieldKey: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetKey(v) return nil case apikey.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case apikey.FieldStatus: v, ok := value.(consts.ApiKeyStatus) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case apikey.FieldLastUsed: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastUsed(v) return nil case apikey.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case apikey.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown ApiKey field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ApiKeyMutation) 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 *ApiKeyMutation) 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 *ApiKeyMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown ApiKey numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ApiKeyMutation) ClearedFields() []string { var fields []string if m.FieldCleared(apikey.FieldLastUsed) { fields = append(fields, apikey.FieldLastUsed) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ApiKeyMutation) 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 *ApiKeyMutation) ClearField(name string) error { switch name { case apikey.FieldLastUsed: m.ClearLastUsed() return nil } return fmt.Errorf("unknown ApiKey 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 *ApiKeyMutation) ResetField(name string) error { switch name { case apikey.FieldUserID: m.ResetUserID() return nil case apikey.FieldKey: m.ResetKey() return nil case apikey.FieldName: m.ResetName() return nil case apikey.FieldStatus: m.ResetStatus() return nil case apikey.FieldLastUsed: m.ResetLastUsed() return nil case apikey.FieldCreatedAt: m.ResetCreatedAt() return nil case apikey.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown ApiKey field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ApiKeyMutation) 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 *ApiKeyMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ApiKeyMutation) 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 *ApiKeyMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ApiKeyMutation) 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 *ApiKeyMutation) 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 *ApiKeyMutation) ClearEdge(name string) error { return fmt.Errorf("unknown ApiKey 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 *ApiKeyMutation) ResetEdge(name string) error { return fmt.Errorf("unknown ApiKey edge %s", name) } // BillingPlanMutation represents an operation that mutates the BillingPlan nodes in the graph. type BillingPlanMutation struct { config op Op typ string id *string name *string description *string rules *map[string]interface{} created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*BillingPlan, error) predicates []predicate.BillingPlan } var _ ent.Mutation = (*BillingPlanMutation)(nil) // billingplanOption allows management of the mutation configuration using functional options. type billingplanOption func(*BillingPlanMutation) // newBillingPlanMutation creates new mutation for the BillingPlan entity. func newBillingPlanMutation(c config, op Op, opts ...billingplanOption) *BillingPlanMutation { m := &BillingPlanMutation{ config: c, op: op, typ: TypeBillingPlan, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBillingPlanID sets the ID field of the mutation. func withBillingPlanID(id string) billingplanOption { return func(m *BillingPlanMutation) { var ( err error once sync.Once value *BillingPlan ) m.oldValue = func(ctx context.Context) (*BillingPlan, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().BillingPlan.Get(ctx, id) } }) return value, err } m.id = &id } } // withBillingPlan sets the old BillingPlan of the mutation. func withBillingPlan(node *BillingPlan) billingplanOption { return func(m *BillingPlanMutation) { m.oldValue = func(context.Context) (*BillingPlan, 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 BillingPlanMutation) 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 BillingPlanMutation) 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 BillingPlan entities. func (m *BillingPlanMutation) SetID(id string) { 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 *BillingPlanMutation) ID() (id string, 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 *BillingPlanMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().BillingPlan.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *BillingPlanMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *BillingPlanMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the BillingPlan entity. // If the BillingPlan 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 *BillingPlanMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *BillingPlanMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *BillingPlanMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *BillingPlanMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the BillingPlan entity. // If the BillingPlan 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 *BillingPlanMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ResetDescription resets all changes to the "description" field. func (m *BillingPlanMutation) ResetDescription() { m.description = nil } // SetRules sets the "rules" field. func (m *BillingPlanMutation) SetRules(value map[string]interface{}) { m.rules = &value } // Rules returns the value of the "rules" field in the mutation. func (m *BillingPlanMutation) Rules() (r map[string]interface{}, exists bool) { v := m.rules if v == nil { return } return *v, true } // OldRules returns the old "rules" field's value of the BillingPlan entity. // If the BillingPlan 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 *BillingPlanMutation) OldRules(ctx context.Context) (v map[string]interface{}, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRules is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRules requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRules: %w", err) } return oldValue.Rules, nil } // ResetRules resets all changes to the "rules" field. func (m *BillingPlanMutation) ResetRules() { m.rules = nil } // SetCreatedAt sets the "created_at" field. func (m *BillingPlanMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *BillingPlanMutation) 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 BillingPlan entity. // If the BillingPlan 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 *BillingPlanMutation) 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 *BillingPlanMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *BillingPlanMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *BillingPlanMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the BillingPlan entity. // If the BillingPlan 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 *BillingPlanMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *BillingPlanMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the BillingPlanMutation builder. func (m *BillingPlanMutation) Where(ps ...predicate.BillingPlan) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BillingPlanMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BillingPlanMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.BillingPlan, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BillingPlanMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BillingPlanMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (BillingPlan). func (m *BillingPlanMutation) 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 *BillingPlanMutation) Fields() []string { fields := make([]string, 0, 5) if m.name != nil { fields = append(fields, billingplan.FieldName) } if m.description != nil { fields = append(fields, billingplan.FieldDescription) } if m.rules != nil { fields = append(fields, billingplan.FieldRules) } if m.created_at != nil { fields = append(fields, billingplan.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, billingplan.FieldUpdatedAt) } 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 *BillingPlanMutation) Field(name string) (ent.Value, bool) { switch name { case billingplan.FieldName: return m.Name() case billingplan.FieldDescription: return m.Description() case billingplan.FieldRules: return m.Rules() case billingplan.FieldCreatedAt: return m.CreatedAt() case billingplan.FieldUpdatedAt: return m.UpdatedAt() } 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 *BillingPlanMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case billingplan.FieldName: return m.OldName(ctx) case billingplan.FieldDescription: return m.OldDescription(ctx) case billingplan.FieldRules: return m.OldRules(ctx) case billingplan.FieldCreatedAt: return m.OldCreatedAt(ctx) case billingplan.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown BillingPlan 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 *BillingPlanMutation) SetField(name string, value ent.Value) error { switch name { case billingplan.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case billingplan.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case billingplan.FieldRules: v, ok := value.(map[string]interface{}) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRules(v) return nil case billingplan.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case billingplan.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown BillingPlan field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BillingPlanMutation) 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 *BillingPlanMutation) 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 *BillingPlanMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown BillingPlan numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BillingPlanMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BillingPlanMutation) 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 *BillingPlanMutation) ClearField(name string) error { return fmt.Errorf("unknown BillingPlan 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 *BillingPlanMutation) ResetField(name string) error { switch name { case billingplan.FieldName: m.ResetName() return nil case billingplan.FieldDescription: m.ResetDescription() return nil case billingplan.FieldRules: m.ResetRules() return nil case billingplan.FieldCreatedAt: m.ResetCreatedAt() return nil case billingplan.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown BillingPlan field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BillingPlanMutation) 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 *BillingPlanMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BillingPlanMutation) 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 *BillingPlanMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BillingPlanMutation) 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 *BillingPlanMutation) 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 *BillingPlanMutation) ClearEdge(name string) error { return fmt.Errorf("unknown BillingPlan 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 *BillingPlanMutation) ResetEdge(name string) error { return fmt.Errorf("unknown BillingPlan edge %s", name) } // BillingQuotaMutation represents an operation that mutates the BillingQuota nodes in the graph. type BillingQuotaMutation struct { config op Op typ string id *string deleted_at *time.Time user_id *string total *int64 addtotal *int64 used *int64 addused *int64 remain *int64 addremain *int64 created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*BillingQuota, error) predicates []predicate.BillingQuota } var _ ent.Mutation = (*BillingQuotaMutation)(nil) // billingquotaOption allows management of the mutation configuration using functional options. type billingquotaOption func(*BillingQuotaMutation) // newBillingQuotaMutation creates new mutation for the BillingQuota entity. func newBillingQuotaMutation(c config, op Op, opts ...billingquotaOption) *BillingQuotaMutation { m := &BillingQuotaMutation{ config: c, op: op, typ: TypeBillingQuota, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBillingQuotaID sets the ID field of the mutation. func withBillingQuotaID(id string) billingquotaOption { return func(m *BillingQuotaMutation) { var ( err error once sync.Once value *BillingQuota ) m.oldValue = func(ctx context.Context) (*BillingQuota, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().BillingQuota.Get(ctx, id) } }) return value, err } m.id = &id } } // withBillingQuota sets the old BillingQuota of the mutation. func withBillingQuota(node *BillingQuota) billingquotaOption { return func(m *BillingQuotaMutation) { m.oldValue = func(context.Context) (*BillingQuota, 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 BillingQuotaMutation) 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 BillingQuotaMutation) 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 BillingQuota entities. func (m *BillingQuotaMutation) SetID(id string) { 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 *BillingQuotaMutation) ID() (id string, 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 *BillingQuotaMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().BillingQuota.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetDeletedAt sets the "deleted_at" field. func (m *BillingQuotaMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. func (m *BillingQuotaMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return } return *v, true } // OldDeletedAt returns the old "deleted_at" field's value of the BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDeletedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } return oldValue.DeletedAt, nil } // ClearDeletedAt clears the value of the "deleted_at" field. func (m *BillingQuotaMutation) ClearDeletedAt() { m.deleted_at = nil m.clearedFields[billingquota.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. func (m *BillingQuotaMutation) DeletedAtCleared() bool { _, ok := m.clearedFields[billingquota.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. func (m *BillingQuotaMutation) ResetDeletedAt() { m.deleted_at = nil delete(m.clearedFields, billingquota.FieldDeletedAt) } // SetUserID sets the "user_id" field. func (m *BillingQuotaMutation) SetUserID(s string) { m.user_id = &s } // UserID returns the value of the "user_id" field in the mutation. func (m *BillingQuotaMutation) UserID() (r string, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *BillingQuotaMutation) ResetUserID() { m.user_id = nil } // SetTotal sets the "total" field. func (m *BillingQuotaMutation) SetTotal(i int64) { m.total = &i m.addtotal = nil } // Total returns the value of the "total" field in the mutation. func (m *BillingQuotaMutation) Total() (r int64, exists bool) { v := m.total if v == nil { return } return *v, true } // OldTotal returns the old "total" field's value of the BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) OldTotal(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTotal: %w", err) } return oldValue.Total, nil } // AddTotal adds i to the "total" field. func (m *BillingQuotaMutation) AddTotal(i int64) { if m.addtotal != nil { *m.addtotal += i } else { m.addtotal = &i } } // AddedTotal returns the value that was added to the "total" field in this mutation. func (m *BillingQuotaMutation) AddedTotal() (r int64, exists bool) { v := m.addtotal if v == nil { return } return *v, true } // ResetTotal resets all changes to the "total" field. func (m *BillingQuotaMutation) ResetTotal() { m.total = nil m.addtotal = nil } // SetUsed sets the "used" field. func (m *BillingQuotaMutation) SetUsed(i int64) { m.used = &i m.addused = nil } // Used returns the value of the "used" field in the mutation. func (m *BillingQuotaMutation) Used() (r int64, exists bool) { v := m.used if v == nil { return } return *v, true } // OldUsed returns the old "used" field's value of the BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) OldUsed(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUsed is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUsed requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUsed: %w", err) } return oldValue.Used, nil } // AddUsed adds i to the "used" field. func (m *BillingQuotaMutation) AddUsed(i int64) { if m.addused != nil { *m.addused += i } else { m.addused = &i } } // AddedUsed returns the value that was added to the "used" field in this mutation. func (m *BillingQuotaMutation) AddedUsed() (r int64, exists bool) { v := m.addused if v == nil { return } return *v, true } // ResetUsed resets all changes to the "used" field. func (m *BillingQuotaMutation) ResetUsed() { m.used = nil m.addused = nil } // SetRemain sets the "remain" field. func (m *BillingQuotaMutation) SetRemain(i int64) { m.remain = &i m.addremain = nil } // Remain returns the value of the "remain" field in the mutation. func (m *BillingQuotaMutation) Remain() (r int64, exists bool) { v := m.remain if v == nil { return } return *v, true } // OldRemain returns the old "remain" field's value of the BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) OldRemain(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRemain is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRemain requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRemain: %w", err) } return oldValue.Remain, nil } // AddRemain adds i to the "remain" field. func (m *BillingQuotaMutation) AddRemain(i int64) { if m.addremain != nil { *m.addremain += i } else { m.addremain = &i } } // AddedRemain returns the value that was added to the "remain" field in this mutation. func (m *BillingQuotaMutation) AddedRemain() (r int64, exists bool) { v := m.addremain if v == nil { return } return *v, true } // ResetRemain resets all changes to the "remain" field. func (m *BillingQuotaMutation) ResetRemain() { m.remain = nil m.addremain = nil } // SetCreatedAt sets the "created_at" field. func (m *BillingQuotaMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *BillingQuotaMutation) 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 BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) 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 *BillingQuotaMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *BillingQuotaMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *BillingQuotaMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the BillingQuota entity. // If the BillingQuota 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 *BillingQuotaMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *BillingQuotaMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the BillingQuotaMutation builder. func (m *BillingQuotaMutation) Where(ps ...predicate.BillingQuota) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BillingQuotaMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BillingQuotaMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.BillingQuota, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BillingQuotaMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BillingQuotaMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (BillingQuota). func (m *BillingQuotaMutation) 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 *BillingQuotaMutation) Fields() []string { fields := make([]string, 0, 7) if m.deleted_at != nil { fields = append(fields, billingquota.FieldDeletedAt) } if m.user_id != nil { fields = append(fields, billingquota.FieldUserID) } if m.total != nil { fields = append(fields, billingquota.FieldTotal) } if m.used != nil { fields = append(fields, billingquota.FieldUsed) } if m.remain != nil { fields = append(fields, billingquota.FieldRemain) } if m.created_at != nil { fields = append(fields, billingquota.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, billingquota.FieldUpdatedAt) } 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 *BillingQuotaMutation) Field(name string) (ent.Value, bool) { switch name { case billingquota.FieldDeletedAt: return m.DeletedAt() case billingquota.FieldUserID: return m.UserID() case billingquota.FieldTotal: return m.Total() case billingquota.FieldUsed: return m.Used() case billingquota.FieldRemain: return m.Remain() case billingquota.FieldCreatedAt: return m.CreatedAt() case billingquota.FieldUpdatedAt: return m.UpdatedAt() } 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 *BillingQuotaMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case billingquota.FieldDeletedAt: return m.OldDeletedAt(ctx) case billingquota.FieldUserID: return m.OldUserID(ctx) case billingquota.FieldTotal: return m.OldTotal(ctx) case billingquota.FieldUsed: return m.OldUsed(ctx) case billingquota.FieldRemain: return m.OldRemain(ctx) case billingquota.FieldCreatedAt: return m.OldCreatedAt(ctx) case billingquota.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown BillingQuota 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 *BillingQuotaMutation) SetField(name string, value ent.Value) error { switch name { case billingquota.FieldDeletedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDeletedAt(v) return nil case billingquota.FieldUserID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case billingquota.FieldTotal: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTotal(v) return nil case billingquota.FieldUsed: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsed(v) return nil case billingquota.FieldRemain: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRemain(v) return nil case billingquota.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case billingquota.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown BillingQuota field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BillingQuotaMutation) AddedFields() []string { var fields []string if m.addtotal != nil { fields = append(fields, billingquota.FieldTotal) } if m.addused != nil { fields = append(fields, billingquota.FieldUsed) } if m.addremain != nil { fields = append(fields, billingquota.FieldRemain) } return fields } // 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 *BillingQuotaMutation) AddedField(name string) (ent.Value, bool) { switch name { case billingquota.FieldTotal: return m.AddedTotal() case billingquota.FieldUsed: return m.AddedUsed() case billingquota.FieldRemain: return m.AddedRemain() } 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 *BillingQuotaMutation) AddField(name string, value ent.Value) error { switch name { case billingquota.FieldTotal: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddTotal(v) return nil case billingquota.FieldUsed: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddUsed(v) return nil case billingquota.FieldRemain: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddRemain(v) return nil } return fmt.Errorf("unknown BillingQuota numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BillingQuotaMutation) ClearedFields() []string { var fields []string if m.FieldCleared(billingquota.FieldDeletedAt) { fields = append(fields, billingquota.FieldDeletedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BillingQuotaMutation) 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 *BillingQuotaMutation) ClearField(name string) error { switch name { case billingquota.FieldDeletedAt: m.ClearDeletedAt() return nil } return fmt.Errorf("unknown BillingQuota 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 *BillingQuotaMutation) ResetField(name string) error { switch name { case billingquota.FieldDeletedAt: m.ResetDeletedAt() return nil case billingquota.FieldUserID: m.ResetUserID() return nil case billingquota.FieldTotal: m.ResetTotal() return nil case billingquota.FieldUsed: m.ResetUsed() return nil case billingquota.FieldRemain: m.ResetRemain() return nil case billingquota.FieldCreatedAt: m.ResetCreatedAt() return nil case billingquota.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown BillingQuota field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BillingQuotaMutation) 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 *BillingQuotaMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BillingQuotaMutation) 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 *BillingQuotaMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BillingQuotaMutation) 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 *BillingQuotaMutation) 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 *BillingQuotaMutation) ClearEdge(name string) error { return fmt.Errorf("unknown BillingQuota 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 *BillingQuotaMutation) ResetEdge(name string) error { return fmt.Errorf("unknown BillingQuota edge %s", name) } // BillingRecordMutation represents an operation that mutates the BillingRecord nodes in the graph. type BillingRecordMutation struct { config op Op typ string id *string tenant_id *string user_id *string model *string operation *string input_tokens *int64 addinput_tokens *int64 output_tokens *int64 addoutput_tokens *int64 cost *int64 addcost *int64 request_time *time.Time metadata *map[string]interface{} created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*BillingRecord, error) predicates []predicate.BillingRecord } var _ ent.Mutation = (*BillingRecordMutation)(nil) // billingrecordOption allows management of the mutation configuration using functional options. type billingrecordOption func(*BillingRecordMutation) // newBillingRecordMutation creates new mutation for the BillingRecord entity. func newBillingRecordMutation(c config, op Op, opts ...billingrecordOption) *BillingRecordMutation { m := &BillingRecordMutation{ config: c, op: op, typ: TypeBillingRecord, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBillingRecordID sets the ID field of the mutation. func withBillingRecordID(id string) billingrecordOption { return func(m *BillingRecordMutation) { var ( err error once sync.Once value *BillingRecord ) m.oldValue = func(ctx context.Context) (*BillingRecord, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().BillingRecord.Get(ctx, id) } }) return value, err } m.id = &id } } // withBillingRecord sets the old BillingRecord of the mutation. func withBillingRecord(node *BillingRecord) billingrecordOption { return func(m *BillingRecordMutation) { m.oldValue = func(context.Context) (*BillingRecord, 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 BillingRecordMutation) 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 BillingRecordMutation) 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 BillingRecord entities. func (m *BillingRecordMutation) SetID(id string) { 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 *BillingRecordMutation) ID() (id string, 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 *BillingRecordMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().BillingRecord.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetTenantID sets the "tenant_id" field. func (m *BillingRecordMutation) SetTenantID(s string) { m.tenant_id = &s } // TenantID returns the value of the "tenant_id" field in the mutation. func (m *BillingRecordMutation) TenantID() (r string, exists bool) { v := m.tenant_id if v == nil { return } return *v, true } // OldTenantID returns the old "tenant_id" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldTenantID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTenantID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTenantID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTenantID: %w", err) } return oldValue.TenantID, nil } // ResetTenantID resets all changes to the "tenant_id" field. func (m *BillingRecordMutation) ResetTenantID() { m.tenant_id = nil } // SetUserID sets the "user_id" field. func (m *BillingRecordMutation) SetUserID(s string) { m.user_id = &s } // UserID returns the value of the "user_id" field in the mutation. func (m *BillingRecordMutation) UserID() (r string, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *BillingRecordMutation) ResetUserID() { m.user_id = nil } // SetModel sets the "model" field. func (m *BillingRecordMutation) SetModel(s string) { m.model = &s } // Model returns the value of the "model" field in the mutation. func (m *BillingRecordMutation) Model() (r string, exists bool) { v := m.model if v == nil { return } return *v, true } // OldModel returns the old "model" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldModel(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldModel is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldModel requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldModel: %w", err) } return oldValue.Model, nil } // ResetModel resets all changes to the "model" field. func (m *BillingRecordMutation) ResetModel() { m.model = nil } // SetOperation sets the "operation" field. func (m *BillingRecordMutation) SetOperation(s string) { m.operation = &s } // Operation returns the value of the "operation" field in the mutation. func (m *BillingRecordMutation) Operation() (r string, exists bool) { v := m.operation if v == nil { return } return *v, true } // OldOperation returns the old "operation" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldOperation(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOperation is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOperation requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOperation: %w", err) } return oldValue.Operation, nil } // ResetOperation resets all changes to the "operation" field. func (m *BillingRecordMutation) ResetOperation() { m.operation = nil } // SetInputTokens sets the "input_tokens" field. func (m *BillingRecordMutation) SetInputTokens(i int64) { m.input_tokens = &i m.addinput_tokens = nil } // InputTokens returns the value of the "input_tokens" field in the mutation. func (m *BillingRecordMutation) InputTokens() (r int64, exists bool) { v := m.input_tokens if v == nil { return } return *v, true } // OldInputTokens returns the old "input_tokens" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldInputTokens(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldInputTokens is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldInputTokens requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldInputTokens: %w", err) } return oldValue.InputTokens, nil } // AddInputTokens adds i to the "input_tokens" field. func (m *BillingRecordMutation) AddInputTokens(i int64) { if m.addinput_tokens != nil { *m.addinput_tokens += i } else { m.addinput_tokens = &i } } // AddedInputTokens returns the value that was added to the "input_tokens" field in this mutation. func (m *BillingRecordMutation) AddedInputTokens() (r int64, exists bool) { v := m.addinput_tokens if v == nil { return } return *v, true } // ResetInputTokens resets all changes to the "input_tokens" field. func (m *BillingRecordMutation) ResetInputTokens() { m.input_tokens = nil m.addinput_tokens = nil } // SetOutputTokens sets the "output_tokens" field. func (m *BillingRecordMutation) SetOutputTokens(i int64) { m.output_tokens = &i m.addoutput_tokens = nil } // OutputTokens returns the value of the "output_tokens" field in the mutation. func (m *BillingRecordMutation) OutputTokens() (r int64, exists bool) { v := m.output_tokens if v == nil { return } return *v, true } // OldOutputTokens returns the old "output_tokens" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldOutputTokens(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOutputTokens is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOutputTokens requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOutputTokens: %w", err) } return oldValue.OutputTokens, nil } // AddOutputTokens adds i to the "output_tokens" field. func (m *BillingRecordMutation) AddOutputTokens(i int64) { if m.addoutput_tokens != nil { *m.addoutput_tokens += i } else { m.addoutput_tokens = &i } } // AddedOutputTokens returns the value that was added to the "output_tokens" field in this mutation. func (m *BillingRecordMutation) AddedOutputTokens() (r int64, exists bool) { v := m.addoutput_tokens if v == nil { return } return *v, true } // ResetOutputTokens resets all changes to the "output_tokens" field. func (m *BillingRecordMutation) ResetOutputTokens() { m.output_tokens = nil m.addoutput_tokens = nil } // SetCost sets the "cost" field. func (m *BillingRecordMutation) SetCost(i int64) { m.cost = &i m.addcost = nil } // Cost returns the value of the "cost" field in the mutation. func (m *BillingRecordMutation) Cost() (r int64, exists bool) { v := m.cost if v == nil { return } return *v, true } // OldCost returns the old "cost" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldCost(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCost is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCost requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCost: %w", err) } return oldValue.Cost, nil } // AddCost adds i to the "cost" field. func (m *BillingRecordMutation) AddCost(i int64) { if m.addcost != nil { *m.addcost += i } else { m.addcost = &i } } // AddedCost returns the value that was added to the "cost" field in this mutation. func (m *BillingRecordMutation) AddedCost() (r int64, exists bool) { v := m.addcost if v == nil { return } return *v, true } // ResetCost resets all changes to the "cost" field. func (m *BillingRecordMutation) ResetCost() { m.cost = nil m.addcost = nil } // SetRequestTime sets the "request_time" field. func (m *BillingRecordMutation) SetRequestTime(t time.Time) { m.request_time = &t } // RequestTime returns the value of the "request_time" field in the mutation. func (m *BillingRecordMutation) RequestTime() (r time.Time, exists bool) { v := m.request_time if v == nil { return } return *v, true } // OldRequestTime returns the old "request_time" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldRequestTime(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRequestTime is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRequestTime requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRequestTime: %w", err) } return oldValue.RequestTime, nil } // ResetRequestTime resets all changes to the "request_time" field. func (m *BillingRecordMutation) ResetRequestTime() { m.request_time = nil } // SetMetadata sets the "metadata" field. func (m *BillingRecordMutation) SetMetadata(value map[string]interface{}) { m.metadata = &value } // Metadata returns the value of the "metadata" field in the mutation. func (m *BillingRecordMutation) Metadata() (r map[string]interface{}, exists bool) { v := m.metadata if v == nil { return } return *v, true } // OldMetadata returns the old "metadata" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldMetadata(ctx context.Context) (v map[string]interface{}, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldMetadata is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldMetadata requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldMetadata: %w", err) } return oldValue.Metadata, nil } // ResetMetadata resets all changes to the "metadata" field. func (m *BillingRecordMutation) ResetMetadata() { m.metadata = nil } // SetCreatedAt sets the "created_at" field. func (m *BillingRecordMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *BillingRecordMutation) 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 BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) 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 *BillingRecordMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *BillingRecordMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *BillingRecordMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the BillingRecord entity. // If the BillingRecord 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 *BillingRecordMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *BillingRecordMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the BillingRecordMutation builder. func (m *BillingRecordMutation) Where(ps ...predicate.BillingRecord) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BillingRecordMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BillingRecordMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.BillingRecord, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BillingRecordMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BillingRecordMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (BillingRecord). func (m *BillingRecordMutation) 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 *BillingRecordMutation) Fields() []string { fields := make([]string, 0, 11) if m.tenant_id != nil { fields = append(fields, billingrecord.FieldTenantID) } if m.user_id != nil { fields = append(fields, billingrecord.FieldUserID) } if m.model != nil { fields = append(fields, billingrecord.FieldModel) } if m.operation != nil { fields = append(fields, billingrecord.FieldOperation) } if m.input_tokens != nil { fields = append(fields, billingrecord.FieldInputTokens) } if m.output_tokens != nil { fields = append(fields, billingrecord.FieldOutputTokens) } if m.cost != nil { fields = append(fields, billingrecord.FieldCost) } if m.request_time != nil { fields = append(fields, billingrecord.FieldRequestTime) } if m.metadata != nil { fields = append(fields, billingrecord.FieldMetadata) } if m.created_at != nil { fields = append(fields, billingrecord.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, billingrecord.FieldUpdatedAt) } 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 *BillingRecordMutation) Field(name string) (ent.Value, bool) { switch name { case billingrecord.FieldTenantID: return m.TenantID() case billingrecord.FieldUserID: return m.UserID() case billingrecord.FieldModel: return m.Model() case billingrecord.FieldOperation: return m.Operation() case billingrecord.FieldInputTokens: return m.InputTokens() case billingrecord.FieldOutputTokens: return m.OutputTokens() case billingrecord.FieldCost: return m.Cost() case billingrecord.FieldRequestTime: return m.RequestTime() case billingrecord.FieldMetadata: return m.Metadata() case billingrecord.FieldCreatedAt: return m.CreatedAt() case billingrecord.FieldUpdatedAt: return m.UpdatedAt() } 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 *BillingRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case billingrecord.FieldTenantID: return m.OldTenantID(ctx) case billingrecord.FieldUserID: return m.OldUserID(ctx) case billingrecord.FieldModel: return m.OldModel(ctx) case billingrecord.FieldOperation: return m.OldOperation(ctx) case billingrecord.FieldInputTokens: return m.OldInputTokens(ctx) case billingrecord.FieldOutputTokens: return m.OldOutputTokens(ctx) case billingrecord.FieldCost: return m.OldCost(ctx) case billingrecord.FieldRequestTime: return m.OldRequestTime(ctx) case billingrecord.FieldMetadata: return m.OldMetadata(ctx) case billingrecord.FieldCreatedAt: return m.OldCreatedAt(ctx) case billingrecord.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown BillingRecord 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 *BillingRecordMutation) SetField(name string, value ent.Value) error { switch name { case billingrecord.FieldTenantID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTenantID(v) return nil case billingrecord.FieldUserID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case billingrecord.FieldModel: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetModel(v) return nil case billingrecord.FieldOperation: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOperation(v) return nil case billingrecord.FieldInputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetInputTokens(v) return nil case billingrecord.FieldOutputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOutputTokens(v) return nil case billingrecord.FieldCost: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCost(v) return nil case billingrecord.FieldRequestTime: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRequestTime(v) return nil case billingrecord.FieldMetadata: v, ok := value.(map[string]interface{}) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMetadata(v) return nil case billingrecord.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case billingrecord.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown BillingRecord field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BillingRecordMutation) AddedFields() []string { var fields []string if m.addinput_tokens != nil { fields = append(fields, billingrecord.FieldInputTokens) } if m.addoutput_tokens != nil { fields = append(fields, billingrecord.FieldOutputTokens) } if m.addcost != nil { fields = append(fields, billingrecord.FieldCost) } return fields } // 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 *BillingRecordMutation) AddedField(name string) (ent.Value, bool) { switch name { case billingrecord.FieldInputTokens: return m.AddedInputTokens() case billingrecord.FieldOutputTokens: return m.AddedOutputTokens() case billingrecord.FieldCost: return m.AddedCost() } 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 *BillingRecordMutation) AddField(name string, value ent.Value) error { switch name { case billingrecord.FieldInputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddInputTokens(v) return nil case billingrecord.FieldOutputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddOutputTokens(v) return nil case billingrecord.FieldCost: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddCost(v) return nil } return fmt.Errorf("unknown BillingRecord numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BillingRecordMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BillingRecordMutation) 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 *BillingRecordMutation) ClearField(name string) error { return fmt.Errorf("unknown BillingRecord 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 *BillingRecordMutation) ResetField(name string) error { switch name { case billingrecord.FieldTenantID: m.ResetTenantID() return nil case billingrecord.FieldUserID: m.ResetUserID() return nil case billingrecord.FieldModel: m.ResetModel() return nil case billingrecord.FieldOperation: m.ResetOperation() return nil case billingrecord.FieldInputTokens: m.ResetInputTokens() return nil case billingrecord.FieldOutputTokens: m.ResetOutputTokens() return nil case billingrecord.FieldCost: m.ResetCost() return nil case billingrecord.FieldRequestTime: m.ResetRequestTime() return nil case billingrecord.FieldMetadata: m.ResetMetadata() return nil case billingrecord.FieldCreatedAt: m.ResetCreatedAt() return nil case billingrecord.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown BillingRecord field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BillingRecordMutation) 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 *BillingRecordMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BillingRecordMutation) 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 *BillingRecordMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BillingRecordMutation) 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 *BillingRecordMutation) 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 *BillingRecordMutation) ClearEdge(name string) error { return fmt.Errorf("unknown BillingRecord 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 *BillingRecordMutation) ResetEdge(name string) error { return fmt.Errorf("unknown BillingRecord edge %s", name) } // BillingUsageMutation represents an operation that mutates the BillingUsage nodes in the graph. type BillingUsageMutation struct { config op Op typ string id *string deleted_at *time.Time user_id *string model_name *string tokens *int64 addtokens *int64 operation *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*BillingUsage, error) predicates []predicate.BillingUsage } var _ ent.Mutation = (*BillingUsageMutation)(nil) // billingusageOption allows management of the mutation configuration using functional options. type billingusageOption func(*BillingUsageMutation) // newBillingUsageMutation creates new mutation for the BillingUsage entity. func newBillingUsageMutation(c config, op Op, opts ...billingusageOption) *BillingUsageMutation { m := &BillingUsageMutation{ config: c, op: op, typ: TypeBillingUsage, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withBillingUsageID sets the ID field of the mutation. func withBillingUsageID(id string) billingusageOption { return func(m *BillingUsageMutation) { var ( err error once sync.Once value *BillingUsage ) m.oldValue = func(ctx context.Context) (*BillingUsage, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().BillingUsage.Get(ctx, id) } }) return value, err } m.id = &id } } // withBillingUsage sets the old BillingUsage of the mutation. func withBillingUsage(node *BillingUsage) billingusageOption { return func(m *BillingUsageMutation) { m.oldValue = func(context.Context) (*BillingUsage, 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 BillingUsageMutation) 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 BillingUsageMutation) 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 BillingUsage entities. func (m *BillingUsageMutation) SetID(id string) { 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 *BillingUsageMutation) ID() (id string, 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 *BillingUsageMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().BillingUsage.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetDeletedAt sets the "deleted_at" field. func (m *BillingUsageMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. func (m *BillingUsageMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return } return *v, true } // OldDeletedAt returns the old "deleted_at" field's value of the BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDeletedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } return oldValue.DeletedAt, nil } // ClearDeletedAt clears the value of the "deleted_at" field. func (m *BillingUsageMutation) ClearDeletedAt() { m.deleted_at = nil m.clearedFields[billingusage.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. func (m *BillingUsageMutation) DeletedAtCleared() bool { _, ok := m.clearedFields[billingusage.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. func (m *BillingUsageMutation) ResetDeletedAt() { m.deleted_at = nil delete(m.clearedFields, billingusage.FieldDeletedAt) } // SetUserID sets the "user_id" field. func (m *BillingUsageMutation) SetUserID(s string) { m.user_id = &s } // UserID returns the value of the "user_id" field in the mutation. func (m *BillingUsageMutation) UserID() (r string, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *BillingUsageMutation) ResetUserID() { m.user_id = nil } // SetModelName sets the "model_name" field. func (m *BillingUsageMutation) SetModelName(s string) { m.model_name = &s } // ModelName returns the value of the "model_name" field in the mutation. func (m *BillingUsageMutation) ModelName() (r string, exists bool) { v := m.model_name if v == nil { return } return *v, true } // OldModelName returns the old "model_name" field's value of the BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) OldModelName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldModelName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldModelName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldModelName: %w", err) } return oldValue.ModelName, nil } // ResetModelName resets all changes to the "model_name" field. func (m *BillingUsageMutation) ResetModelName() { m.model_name = nil } // SetTokens sets the "tokens" field. func (m *BillingUsageMutation) SetTokens(i int64) { m.tokens = &i m.addtokens = nil } // Tokens returns the value of the "tokens" field in the mutation. func (m *BillingUsageMutation) Tokens() (r int64, exists bool) { v := m.tokens if v == nil { return } return *v, true } // OldTokens returns the old "tokens" field's value of the BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) OldTokens(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTokens is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTokens requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTokens: %w", err) } return oldValue.Tokens, nil } // AddTokens adds i to the "tokens" field. func (m *BillingUsageMutation) AddTokens(i int64) { if m.addtokens != nil { *m.addtokens += i } else { m.addtokens = &i } } // AddedTokens returns the value that was added to the "tokens" field in this mutation. func (m *BillingUsageMutation) AddedTokens() (r int64, exists bool) { v := m.addtokens if v == nil { return } return *v, true } // ResetTokens resets all changes to the "tokens" field. func (m *BillingUsageMutation) ResetTokens() { m.tokens = nil m.addtokens = nil } // SetOperation sets the "operation" field. func (m *BillingUsageMutation) SetOperation(s string) { m.operation = &s } // Operation returns the value of the "operation" field in the mutation. func (m *BillingUsageMutation) Operation() (r string, exists bool) { v := m.operation if v == nil { return } return *v, true } // OldOperation returns the old "operation" field's value of the BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) OldOperation(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOperation is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOperation requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOperation: %w", err) } return oldValue.Operation, nil } // ResetOperation resets all changes to the "operation" field. func (m *BillingUsageMutation) ResetOperation() { m.operation = nil } // SetCreatedAt sets the "created_at" field. func (m *BillingUsageMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *BillingUsageMutation) 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 BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) 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 *BillingUsageMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *BillingUsageMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *BillingUsageMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the BillingUsage entity. // If the BillingUsage 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 *BillingUsageMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *BillingUsageMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the BillingUsageMutation builder. func (m *BillingUsageMutation) Where(ps ...predicate.BillingUsage) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the BillingUsageMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *BillingUsageMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.BillingUsage, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *BillingUsageMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *BillingUsageMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (BillingUsage). func (m *BillingUsageMutation) 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 *BillingUsageMutation) Fields() []string { fields := make([]string, 0, 7) if m.deleted_at != nil { fields = append(fields, billingusage.FieldDeletedAt) } if m.user_id != nil { fields = append(fields, billingusage.FieldUserID) } if m.model_name != nil { fields = append(fields, billingusage.FieldModelName) } if m.tokens != nil { fields = append(fields, billingusage.FieldTokens) } if m.operation != nil { fields = append(fields, billingusage.FieldOperation) } if m.created_at != nil { fields = append(fields, billingusage.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, billingusage.FieldUpdatedAt) } 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 *BillingUsageMutation) Field(name string) (ent.Value, bool) { switch name { case billingusage.FieldDeletedAt: return m.DeletedAt() case billingusage.FieldUserID: return m.UserID() case billingusage.FieldModelName: return m.ModelName() case billingusage.FieldTokens: return m.Tokens() case billingusage.FieldOperation: return m.Operation() case billingusage.FieldCreatedAt: return m.CreatedAt() case billingusage.FieldUpdatedAt: return m.UpdatedAt() } 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 *BillingUsageMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case billingusage.FieldDeletedAt: return m.OldDeletedAt(ctx) case billingusage.FieldUserID: return m.OldUserID(ctx) case billingusage.FieldModelName: return m.OldModelName(ctx) case billingusage.FieldTokens: return m.OldTokens(ctx) case billingusage.FieldOperation: return m.OldOperation(ctx) case billingusage.FieldCreatedAt: return m.OldCreatedAt(ctx) case billingusage.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown BillingUsage 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 *BillingUsageMutation) SetField(name string, value ent.Value) error { switch name { case billingusage.FieldDeletedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDeletedAt(v) return nil case billingusage.FieldUserID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case billingusage.FieldModelName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetModelName(v) return nil case billingusage.FieldTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTokens(v) return nil case billingusage.FieldOperation: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOperation(v) return nil case billingusage.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case billingusage.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown BillingUsage field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *BillingUsageMutation) AddedFields() []string { var fields []string if m.addtokens != nil { fields = append(fields, billingusage.FieldTokens) } return fields } // 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 *BillingUsageMutation) AddedField(name string) (ent.Value, bool) { switch name { case billingusage.FieldTokens: return m.AddedTokens() } 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 *BillingUsageMutation) AddField(name string, value ent.Value) error { switch name { case billingusage.FieldTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddTokens(v) return nil } return fmt.Errorf("unknown BillingUsage numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *BillingUsageMutation) ClearedFields() []string { var fields []string if m.FieldCleared(billingusage.FieldDeletedAt) { fields = append(fields, billingusage.FieldDeletedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BillingUsageMutation) 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 *BillingUsageMutation) ClearField(name string) error { switch name { case billingusage.FieldDeletedAt: m.ClearDeletedAt() return nil } return fmt.Errorf("unknown BillingUsage 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 *BillingUsageMutation) ResetField(name string) error { switch name { case billingusage.FieldDeletedAt: m.ResetDeletedAt() return nil case billingusage.FieldUserID: m.ResetUserID() return nil case billingusage.FieldModelName: m.ResetModelName() return nil case billingusage.FieldTokens: m.ResetTokens() return nil case billingusage.FieldOperation: m.ResetOperation() return nil case billingusage.FieldCreatedAt: m.ResetCreatedAt() return nil case billingusage.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown BillingUsage field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *BillingUsageMutation) 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 *BillingUsageMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *BillingUsageMutation) 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 *BillingUsageMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BillingUsageMutation) 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 *BillingUsageMutation) 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 *BillingUsageMutation) ClearEdge(name string) error { return fmt.Errorf("unknown BillingUsage 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 *BillingUsageMutation) ResetEdge(name string) error { return fmt.Errorf("unknown BillingUsage edge %s", name) } // InviteCodeMutation represents an operation that mutates the InviteCode nodes in the graph. type InviteCodeMutation struct { config op Op typ string id *uuid.UUID admin_id *uuid.UUID code *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*InviteCode, error) predicates []predicate.InviteCode } var _ ent.Mutation = (*InviteCodeMutation)(nil) // invitecodeOption allows management of the mutation configuration using functional options. type invitecodeOption func(*InviteCodeMutation) // newInviteCodeMutation creates new mutation for the InviteCode entity. func newInviteCodeMutation(c config, op Op, opts ...invitecodeOption) *InviteCodeMutation { m := &InviteCodeMutation{ config: c, op: op, typ: TypeInviteCode, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withInviteCodeID sets the ID field of the mutation. func withInviteCodeID(id uuid.UUID) invitecodeOption { return func(m *InviteCodeMutation) { var ( err error once sync.Once value *InviteCode ) m.oldValue = func(ctx context.Context) (*InviteCode, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().InviteCode.Get(ctx, id) } }) return value, err } m.id = &id } } // withInviteCode sets the old InviteCode of the mutation. func withInviteCode(node *InviteCode) invitecodeOption { return func(m *InviteCodeMutation) { m.oldValue = func(context.Context) (*InviteCode, 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 InviteCodeMutation) 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 InviteCodeMutation) 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 InviteCode entities. func (m *InviteCodeMutation) SetID(id uuid.UUID) { 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 *InviteCodeMutation) ID() (id uuid.UUID, 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 *InviteCodeMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().InviteCode.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetAdminID sets the "admin_id" field. func (m *InviteCodeMutation) SetAdminID(u uuid.UUID) { m.admin_id = &u } // AdminID returns the value of the "admin_id" field in the mutation. func (m *InviteCodeMutation) AdminID() (r uuid.UUID, exists bool) { v := m.admin_id if v == nil { return } return *v, true } // OldAdminID returns the old "admin_id" field's value of the InviteCode entity. // If the InviteCode 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 *InviteCodeMutation) OldAdminID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAdminID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAdminID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAdminID: %w", err) } return oldValue.AdminID, nil } // ResetAdminID resets all changes to the "admin_id" field. func (m *InviteCodeMutation) ResetAdminID() { m.admin_id = nil } // SetCode sets the "code" field. func (m *InviteCodeMutation) SetCode(s string) { m.code = &s } // Code returns the value of the "code" field in the mutation. func (m *InviteCodeMutation) 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 InviteCode entity. // If the InviteCode 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 *InviteCodeMutation) 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 } // ResetCode resets all changes to the "code" field. func (m *InviteCodeMutation) ResetCode() { m.code = nil } // SetCreatedAt sets the "created_at" field. func (m *InviteCodeMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *InviteCodeMutation) 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 InviteCode entity. // If the InviteCode 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 *InviteCodeMutation) 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 *InviteCodeMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *InviteCodeMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *InviteCodeMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the InviteCode entity. // If the InviteCode 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 *InviteCodeMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *InviteCodeMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the InviteCodeMutation builder. func (m *InviteCodeMutation) Where(ps ...predicate.InviteCode) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the InviteCodeMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *InviteCodeMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.InviteCode, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *InviteCodeMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *InviteCodeMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (InviteCode). func (m *InviteCodeMutation) 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 *InviteCodeMutation) Fields() []string { fields := make([]string, 0, 4) if m.admin_id != nil { fields = append(fields, invitecode.FieldAdminID) } if m.code != nil { fields = append(fields, invitecode.FieldCode) } if m.created_at != nil { fields = append(fields, invitecode.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, invitecode.FieldUpdatedAt) } 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 *InviteCodeMutation) Field(name string) (ent.Value, bool) { switch name { case invitecode.FieldAdminID: return m.AdminID() case invitecode.FieldCode: return m.Code() case invitecode.FieldCreatedAt: return m.CreatedAt() case invitecode.FieldUpdatedAt: return m.UpdatedAt() } 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 *InviteCodeMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case invitecode.FieldAdminID: return m.OldAdminID(ctx) case invitecode.FieldCode: return m.OldCode(ctx) case invitecode.FieldCreatedAt: return m.OldCreatedAt(ctx) case invitecode.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown InviteCode 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 *InviteCodeMutation) SetField(name string, value ent.Value) error { switch name { case invitecode.FieldAdminID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAdminID(v) return nil case invitecode.FieldCode: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCode(v) return nil case invitecode.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case invitecode.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown InviteCode field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *InviteCodeMutation) 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 *InviteCodeMutation) 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 *InviteCodeMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown InviteCode numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *InviteCodeMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *InviteCodeMutation) 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 *InviteCodeMutation) ClearField(name string) error { return fmt.Errorf("unknown InviteCode 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 *InviteCodeMutation) ResetField(name string) error { switch name { case invitecode.FieldAdminID: m.ResetAdminID() return nil case invitecode.FieldCode: m.ResetCode() return nil case invitecode.FieldCreatedAt: m.ResetCreatedAt() return nil case invitecode.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown InviteCode field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *InviteCodeMutation) 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 *InviteCodeMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *InviteCodeMutation) 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 *InviteCodeMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *InviteCodeMutation) 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 *InviteCodeMutation) 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 *InviteCodeMutation) ClearEdge(name string) error { return fmt.Errorf("unknown InviteCode 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 *InviteCodeMutation) ResetEdge(name string) error { return fmt.Errorf("unknown InviteCode edge %s", name) } // ModelMutation represents an operation that mutates the Model nodes in the graph. type ModelMutation struct { config op Op typ string id *uuid.UUID model_name *string model_type *consts.ModelType api_base *string api_key *string api_version *string description *string provider *string status *consts.ModelStatus context_length *int addcontext_length *int created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} tasks map[uuid.UUID]struct{} removedtasks map[uuid.UUID]struct{} clearedtasks bool user *uuid.UUID cleareduser bool done bool oldValue func(context.Context) (*Model, error) predicates []predicate.Model } var _ ent.Mutation = (*ModelMutation)(nil) // modelOption allows management of the mutation configuration using functional options. type modelOption func(*ModelMutation) // newModelMutation creates new mutation for the Model entity. func newModelMutation(c config, op Op, opts ...modelOption) *ModelMutation { m := &ModelMutation{ config: c, op: op, typ: TypeModel, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withModelID sets the ID field of the mutation. func withModelID(id uuid.UUID) modelOption { return func(m *ModelMutation) { var ( err error once sync.Once value *Model ) m.oldValue = func(ctx context.Context) (*Model, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Model.Get(ctx, id) } }) return value, err } m.id = &id } } // withModel sets the old Model of the mutation. func withModel(node *Model) modelOption { return func(m *ModelMutation) { m.oldValue = func(context.Context) (*Model, 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 ModelMutation) 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 ModelMutation) 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 Model entities. func (m *ModelMutation) SetID(id uuid.UUID) { 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 *ModelMutation) ID() (id uuid.UUID, 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 *ModelMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Model.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUserID sets the "user_id" field. func (m *ModelMutation) SetUserID(u uuid.UUID) { m.user = &u } // UserID returns the value of the "user_id" field in the mutation. func (m *ModelMutation) UserID() (r uuid.UUID, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the Model entity. // If the Model 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 *ModelMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ClearUserID clears the value of the "user_id" field. func (m *ModelMutation) ClearUserID() { m.user = nil m.clearedFields[model.FieldUserID] = struct{}{} } // UserIDCleared returns if the "user_id" field was cleared in this mutation. func (m *ModelMutation) UserIDCleared() bool { _, ok := m.clearedFields[model.FieldUserID] return ok } // ResetUserID resets all changes to the "user_id" field. func (m *ModelMutation) ResetUserID() { m.user = nil delete(m.clearedFields, model.FieldUserID) } // SetModelName sets the "model_name" field. func (m *ModelMutation) SetModelName(s string) { m.model_name = &s } // ModelName returns the value of the "model_name" field in the mutation. func (m *ModelMutation) ModelName() (r string, exists bool) { v := m.model_name if v == nil { return } return *v, true } // OldModelName returns the old "model_name" field's value of the Model entity. // If the Model 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 *ModelMutation) OldModelName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldModelName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldModelName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldModelName: %w", err) } return oldValue.ModelName, nil } // ResetModelName resets all changes to the "model_name" field. func (m *ModelMutation) ResetModelName() { m.model_name = nil } // SetModelType sets the "model_type" field. func (m *ModelMutation) SetModelType(ct consts.ModelType) { m.model_type = &ct } // ModelType returns the value of the "model_type" field in the mutation. func (m *ModelMutation) ModelType() (r consts.ModelType, exists bool) { v := m.model_type if v == nil { return } return *v, true } // OldModelType returns the old "model_type" field's value of the Model entity. // If the Model 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 *ModelMutation) OldModelType(ctx context.Context) (v consts.ModelType, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldModelType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldModelType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldModelType: %w", err) } return oldValue.ModelType, nil } // ResetModelType resets all changes to the "model_type" field. func (m *ModelMutation) ResetModelType() { m.model_type = nil } // SetAPIBase sets the "api_base" field. func (m *ModelMutation) SetAPIBase(s string) { m.api_base = &s } // APIBase returns the value of the "api_base" field in the mutation. func (m *ModelMutation) APIBase() (r string, exists bool) { v := m.api_base if v == nil { return } return *v, true } // OldAPIBase returns the old "api_base" field's value of the Model entity. // If the Model 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 *ModelMutation) OldAPIBase(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAPIBase is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAPIBase requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAPIBase: %w", err) } return oldValue.APIBase, nil } // ResetAPIBase resets all changes to the "api_base" field. func (m *ModelMutation) ResetAPIBase() { m.api_base = nil } // SetAPIKey sets the "api_key" field. func (m *ModelMutation) SetAPIKey(s string) { m.api_key = &s } // APIKey returns the value of the "api_key" field in the mutation. func (m *ModelMutation) APIKey() (r string, exists bool) { v := m.api_key if v == nil { return } return *v, true } // OldAPIKey returns the old "api_key" field's value of the Model entity. // If the Model 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 *ModelMutation) OldAPIKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAPIKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAPIKey requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAPIKey: %w", err) } return oldValue.APIKey, nil } // ResetAPIKey resets all changes to the "api_key" field. func (m *ModelMutation) ResetAPIKey() { m.api_key = nil } // SetAPIVersion sets the "api_version" field. func (m *ModelMutation) SetAPIVersion(s string) { m.api_version = &s } // APIVersion returns the value of the "api_version" field in the mutation. func (m *ModelMutation) APIVersion() (r string, exists bool) { v := m.api_version if v == nil { return } return *v, true } // OldAPIVersion returns the old "api_version" field's value of the Model entity. // If the Model 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 *ModelMutation) OldAPIVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAPIVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAPIVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAPIVersion: %w", err) } return oldValue.APIVersion, nil } // ClearAPIVersion clears the value of the "api_version" field. func (m *ModelMutation) ClearAPIVersion() { m.api_version = nil m.clearedFields[model.FieldAPIVersion] = struct{}{} } // APIVersionCleared returns if the "api_version" field was cleared in this mutation. func (m *ModelMutation) APIVersionCleared() bool { _, ok := m.clearedFields[model.FieldAPIVersion] return ok } // ResetAPIVersion resets all changes to the "api_version" field. func (m *ModelMutation) ResetAPIVersion() { m.api_version = nil delete(m.clearedFields, model.FieldAPIVersion) } // SetDescription sets the "description" field. func (m *ModelMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *ModelMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the Model entity. // If the Model 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 *ModelMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ClearDescription clears the value of the "description" field. func (m *ModelMutation) ClearDescription() { m.description = nil m.clearedFields[model.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *ModelMutation) DescriptionCleared() bool { _, ok := m.clearedFields[model.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *ModelMutation) ResetDescription() { m.description = nil delete(m.clearedFields, model.FieldDescription) } // SetProvider sets the "provider" field. func (m *ModelMutation) SetProvider(s string) { m.provider = &s } // Provider returns the value of the "provider" field in the mutation. func (m *ModelMutation) Provider() (r string, exists bool) { v := m.provider if v == nil { return } return *v, true } // OldProvider returns the old "provider" field's value of the Model entity. // If the Model 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 *ModelMutation) OldProvider(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProvider is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProvider requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProvider: %w", err) } return oldValue.Provider, nil } // ResetProvider resets all changes to the "provider" field. func (m *ModelMutation) ResetProvider() { m.provider = nil } // SetStatus sets the "status" field. func (m *ModelMutation) SetStatus(cs consts.ModelStatus) { m.status = &cs } // Status returns the value of the "status" field in the mutation. func (m *ModelMutation) Status() (r consts.ModelStatus, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Model entity. // If the Model 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 *ModelMutation) OldStatus(ctx context.Context) (v consts.ModelStatus, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *ModelMutation) ResetStatus() { m.status = nil } // SetContextLength sets the "context_length" field. func (m *ModelMutation) SetContextLength(i int) { m.context_length = &i m.addcontext_length = nil } // ContextLength returns the value of the "context_length" field in the mutation. func (m *ModelMutation) ContextLength() (r int, exists bool) { v := m.context_length if v == nil { return } return *v, true } // OldContextLength returns the old "context_length" field's value of the Model entity. // If the Model 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 *ModelMutation) OldContextLength(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldContextLength is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldContextLength requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldContextLength: %w", err) } return oldValue.ContextLength, nil } // AddContextLength adds i to the "context_length" field. func (m *ModelMutation) AddContextLength(i int) { if m.addcontext_length != nil { *m.addcontext_length += i } else { m.addcontext_length = &i } } // AddedContextLength returns the value that was added to the "context_length" field in this mutation. func (m *ModelMutation) AddedContextLength() (r int, exists bool) { v := m.addcontext_length if v == nil { return } return *v, true } // ClearContextLength clears the value of the "context_length" field. func (m *ModelMutation) ClearContextLength() { m.context_length = nil m.addcontext_length = nil m.clearedFields[model.FieldContextLength] = struct{}{} } // ContextLengthCleared returns if the "context_length" field was cleared in this mutation. func (m *ModelMutation) ContextLengthCleared() bool { _, ok := m.clearedFields[model.FieldContextLength] return ok } // ResetContextLength resets all changes to the "context_length" field. func (m *ModelMutation) ResetContextLength() { m.context_length = nil m.addcontext_length = nil delete(m.clearedFields, model.FieldContextLength) } // SetCreatedAt sets the "created_at" field. func (m *ModelMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *ModelMutation) 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 Model entity. // If the Model 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 *ModelMutation) 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 *ModelMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *ModelMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *ModelMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Model entity. // If the Model 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 *ModelMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *ModelMutation) ResetUpdatedAt() { m.updated_at = nil } // AddTaskIDs adds the "tasks" edge to the Task entity by ids. func (m *ModelMutation) AddTaskIDs(ids ...uuid.UUID) { if m.tasks == nil { m.tasks = make(map[uuid.UUID]struct{}) } for i := range ids { m.tasks[ids[i]] = struct{}{} } } // ClearTasks clears the "tasks" edge to the Task entity. func (m *ModelMutation) ClearTasks() { m.clearedtasks = true } // TasksCleared reports if the "tasks" edge to the Task entity was cleared. func (m *ModelMutation) TasksCleared() bool { return m.clearedtasks } // RemoveTaskIDs removes the "tasks" edge to the Task entity by IDs. func (m *ModelMutation) RemoveTaskIDs(ids ...uuid.UUID) { if m.removedtasks == nil { m.removedtasks = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.tasks, ids[i]) m.removedtasks[ids[i]] = struct{}{} } } // RemovedTasks returns the removed IDs of the "tasks" edge to the Task entity. func (m *ModelMutation) RemovedTasksIDs() (ids []uuid.UUID) { for id := range m.removedtasks { ids = append(ids, id) } return } // TasksIDs returns the "tasks" edge IDs in the mutation. func (m *ModelMutation) TasksIDs() (ids []uuid.UUID) { for id := range m.tasks { ids = append(ids, id) } return } // ResetTasks resets all changes to the "tasks" edge. func (m *ModelMutation) ResetTasks() { m.tasks = nil m.clearedtasks = false m.removedtasks = nil } // ClearUser clears the "user" edge to the User entity. func (m *ModelMutation) ClearUser() { m.cleareduser = true m.clearedFields[model.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *ModelMutation) UserCleared() bool { return m.UserIDCleared() || m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *ModelMutation) UserIDs() (ids []uuid.UUID) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *ModelMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the ModelMutation builder. func (m *ModelMutation) Where(ps ...predicate.Model) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ModelMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ModelMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Model, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ModelMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ModelMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Model). func (m *ModelMutation) 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 *ModelMutation) Fields() []string { fields := make([]string, 0, 12) if m.user != nil { fields = append(fields, model.FieldUserID) } if m.model_name != nil { fields = append(fields, model.FieldModelName) } if m.model_type != nil { fields = append(fields, model.FieldModelType) } if m.api_base != nil { fields = append(fields, model.FieldAPIBase) } if m.api_key != nil { fields = append(fields, model.FieldAPIKey) } if m.api_version != nil { fields = append(fields, model.FieldAPIVersion) } if m.description != nil { fields = append(fields, model.FieldDescription) } if m.provider != nil { fields = append(fields, model.FieldProvider) } if m.status != nil { fields = append(fields, model.FieldStatus) } if m.context_length != nil { fields = append(fields, model.FieldContextLength) } if m.created_at != nil { fields = append(fields, model.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, model.FieldUpdatedAt) } 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 *ModelMutation) Field(name string) (ent.Value, bool) { switch name { case model.FieldUserID: return m.UserID() case model.FieldModelName: return m.ModelName() case model.FieldModelType: return m.ModelType() case model.FieldAPIBase: return m.APIBase() case model.FieldAPIKey: return m.APIKey() case model.FieldAPIVersion: return m.APIVersion() case model.FieldDescription: return m.Description() case model.FieldProvider: return m.Provider() case model.FieldStatus: return m.Status() case model.FieldContextLength: return m.ContextLength() case model.FieldCreatedAt: return m.CreatedAt() case model.FieldUpdatedAt: return m.UpdatedAt() } 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 *ModelMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case model.FieldUserID: return m.OldUserID(ctx) case model.FieldModelName: return m.OldModelName(ctx) case model.FieldModelType: return m.OldModelType(ctx) case model.FieldAPIBase: return m.OldAPIBase(ctx) case model.FieldAPIKey: return m.OldAPIKey(ctx) case model.FieldAPIVersion: return m.OldAPIVersion(ctx) case model.FieldDescription: return m.OldDescription(ctx) case model.FieldProvider: return m.OldProvider(ctx) case model.FieldStatus: return m.OldStatus(ctx) case model.FieldContextLength: return m.OldContextLength(ctx) case model.FieldCreatedAt: return m.OldCreatedAt(ctx) case model.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Model 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 *ModelMutation) SetField(name string, value ent.Value) error { switch name { case model.FieldUserID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case model.FieldModelName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetModelName(v) return nil case model.FieldModelType: v, ok := value.(consts.ModelType) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetModelType(v) return nil case model.FieldAPIBase: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAPIBase(v) return nil case model.FieldAPIKey: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAPIKey(v) return nil case model.FieldAPIVersion: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAPIVersion(v) return nil case model.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case model.FieldProvider: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProvider(v) return nil case model.FieldStatus: v, ok := value.(consts.ModelStatus) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case model.FieldContextLength: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetContextLength(v) return nil case model.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case model.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Model field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ModelMutation) AddedFields() []string { var fields []string if m.addcontext_length != nil { fields = append(fields, model.FieldContextLength) } return fields } // 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 *ModelMutation) AddedField(name string) (ent.Value, bool) { switch name { case model.FieldContextLength: return m.AddedContextLength() } 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 *ModelMutation) AddField(name string, value ent.Value) error { switch name { case model.FieldContextLength: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddContextLength(v) return nil } return fmt.Errorf("unknown Model numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ModelMutation) ClearedFields() []string { var fields []string if m.FieldCleared(model.FieldUserID) { fields = append(fields, model.FieldUserID) } if m.FieldCleared(model.FieldAPIVersion) { fields = append(fields, model.FieldAPIVersion) } if m.FieldCleared(model.FieldDescription) { fields = append(fields, model.FieldDescription) } if m.FieldCleared(model.FieldContextLength) { fields = append(fields, model.FieldContextLength) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ModelMutation) 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 *ModelMutation) ClearField(name string) error { switch name { case model.FieldUserID: m.ClearUserID() return nil case model.FieldAPIVersion: m.ClearAPIVersion() return nil case model.FieldDescription: m.ClearDescription() return nil case model.FieldContextLength: m.ClearContextLength() return nil } return fmt.Errorf("unknown Model 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 *ModelMutation) ResetField(name string) error { switch name { case model.FieldUserID: m.ResetUserID() return nil case model.FieldModelName: m.ResetModelName() return nil case model.FieldModelType: m.ResetModelType() return nil case model.FieldAPIBase: m.ResetAPIBase() return nil case model.FieldAPIKey: m.ResetAPIKey() return nil case model.FieldAPIVersion: m.ResetAPIVersion() return nil case model.FieldDescription: m.ResetDescription() return nil case model.FieldProvider: m.ResetProvider() return nil case model.FieldStatus: m.ResetStatus() return nil case model.FieldContextLength: m.ResetContextLength() return nil case model.FieldCreatedAt: m.ResetCreatedAt() return nil case model.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Model field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ModelMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.tasks != nil { edges = append(edges, model.EdgeTasks) } if m.user != nil { edges = append(edges, model.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ModelMutation) AddedIDs(name string) []ent.Value { switch name { case model.EdgeTasks: ids := make([]ent.Value, 0, len(m.tasks)) for id := range m.tasks { ids = append(ids, id) } return ids case model.EdgeUser: if id := m.user; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ModelMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedtasks != nil { edges = append(edges, model.EdgeTasks) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ModelMutation) RemovedIDs(name string) []ent.Value { switch name { case model.EdgeTasks: ids := make([]ent.Value, 0, len(m.removedtasks)) for id := range m.removedtasks { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ModelMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedtasks { edges = append(edges, model.EdgeTasks) } if m.cleareduser { edges = append(edges, model.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ModelMutation) EdgeCleared(name string) bool { switch name { case model.EdgeTasks: return m.clearedtasks case model.EdgeUser: return m.cleareduser } 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 *ModelMutation) ClearEdge(name string) error { switch name { case model.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown Model 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 *ModelMutation) ResetEdge(name string) error { switch name { case model.EdgeTasks: m.ResetTasks() return nil case model.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown Model edge %s", name) } // SettingMutation represents an operation that mutates the Setting nodes in the graph. type SettingMutation struct { config op Op typ string id *uuid.UUID enable_sso *bool force_two_factor_auth *bool disable_password_login *bool created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Setting, error) predicates []predicate.Setting } var _ ent.Mutation = (*SettingMutation)(nil) // settingOption allows management of the mutation configuration using functional options. type settingOption func(*SettingMutation) // newSettingMutation creates new mutation for the Setting entity. func newSettingMutation(c config, op Op, opts ...settingOption) *SettingMutation { m := &SettingMutation{ config: c, op: op, typ: TypeSetting, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSettingID sets the ID field of the mutation. func withSettingID(id uuid.UUID) settingOption { return func(m *SettingMutation) { var ( err error once sync.Once value *Setting ) m.oldValue = func(ctx context.Context) (*Setting, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Setting.Get(ctx, id) } }) return value, err } m.id = &id } } // withSetting sets the old Setting of the mutation. func withSetting(node *Setting) settingOption { return func(m *SettingMutation) { m.oldValue = func(context.Context) (*Setting, 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 SettingMutation) 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 SettingMutation) 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 Setting entities. func (m *SettingMutation) SetID(id uuid.UUID) { 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 *SettingMutation) ID() (id uuid.UUID, 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 *SettingMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Setting.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetEnableSSO sets the "enable_sso" field. func (m *SettingMutation) SetEnableSSO(b bool) { m.enable_sso = &b } // EnableSSO returns the value of the "enable_sso" field in the mutation. func (m *SettingMutation) EnableSSO() (r bool, exists bool) { v := m.enable_sso if v == nil { return } return *v, true } // OldEnableSSO returns the old "enable_sso" field's value of the Setting entity. // If the Setting 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 *SettingMutation) OldEnableSSO(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEnableSSO is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEnableSSO requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEnableSSO: %w", err) } return oldValue.EnableSSO, nil } // ResetEnableSSO resets all changes to the "enable_sso" field. func (m *SettingMutation) ResetEnableSSO() { m.enable_sso = nil } // SetForceTwoFactorAuth sets the "force_two_factor_auth" field. func (m *SettingMutation) SetForceTwoFactorAuth(b bool) { m.force_two_factor_auth = &b } // ForceTwoFactorAuth returns the value of the "force_two_factor_auth" field in the mutation. func (m *SettingMutation) ForceTwoFactorAuth() (r bool, exists bool) { v := m.force_two_factor_auth if v == nil { return } return *v, true } // OldForceTwoFactorAuth returns the old "force_two_factor_auth" field's value of the Setting entity. // If the Setting 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 *SettingMutation) OldForceTwoFactorAuth(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldForceTwoFactorAuth is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldForceTwoFactorAuth requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldForceTwoFactorAuth: %w", err) } return oldValue.ForceTwoFactorAuth, nil } // ResetForceTwoFactorAuth resets all changes to the "force_two_factor_auth" field. func (m *SettingMutation) ResetForceTwoFactorAuth() { m.force_two_factor_auth = nil } // SetDisablePasswordLogin sets the "disable_password_login" field. func (m *SettingMutation) SetDisablePasswordLogin(b bool) { m.disable_password_login = &b } // DisablePasswordLogin returns the value of the "disable_password_login" field in the mutation. func (m *SettingMutation) DisablePasswordLogin() (r bool, exists bool) { v := m.disable_password_login if v == nil { return } return *v, true } // OldDisablePasswordLogin returns the old "disable_password_login" field's value of the Setting entity. // If the Setting 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 *SettingMutation) OldDisablePasswordLogin(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDisablePasswordLogin is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDisablePasswordLogin requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDisablePasswordLogin: %w", err) } return oldValue.DisablePasswordLogin, nil } // ResetDisablePasswordLogin resets all changes to the "disable_password_login" field. func (m *SettingMutation) ResetDisablePasswordLogin() { m.disable_password_login = nil } // SetCreatedAt sets the "created_at" field. func (m *SettingMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *SettingMutation) 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 Setting entity. // If the Setting 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 *SettingMutation) 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 *SettingMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *SettingMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *SettingMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Setting entity. // If the Setting 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 *SettingMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *SettingMutation) ResetUpdatedAt() { m.updated_at = nil } // Where appends a list predicates to the SettingMutation builder. func (m *SettingMutation) Where(ps ...predicate.Setting) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SettingMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SettingMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Setting, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SettingMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SettingMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Setting). func (m *SettingMutation) 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 *SettingMutation) Fields() []string { fields := make([]string, 0, 5) if m.enable_sso != nil { fields = append(fields, setting.FieldEnableSSO) } if m.force_two_factor_auth != nil { fields = append(fields, setting.FieldForceTwoFactorAuth) } if m.disable_password_login != nil { fields = append(fields, setting.FieldDisablePasswordLogin) } if m.created_at != nil { fields = append(fields, setting.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, setting.FieldUpdatedAt) } 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 *SettingMutation) Field(name string) (ent.Value, bool) { switch name { case setting.FieldEnableSSO: return m.EnableSSO() case setting.FieldForceTwoFactorAuth: return m.ForceTwoFactorAuth() case setting.FieldDisablePasswordLogin: return m.DisablePasswordLogin() case setting.FieldCreatedAt: return m.CreatedAt() case setting.FieldUpdatedAt: return m.UpdatedAt() } 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 *SettingMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case setting.FieldEnableSSO: return m.OldEnableSSO(ctx) case setting.FieldForceTwoFactorAuth: return m.OldForceTwoFactorAuth(ctx) case setting.FieldDisablePasswordLogin: return m.OldDisablePasswordLogin(ctx) case setting.FieldCreatedAt: return m.OldCreatedAt(ctx) case setting.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Setting 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 *SettingMutation) SetField(name string, value ent.Value) error { switch name { case setting.FieldEnableSSO: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEnableSSO(v) return nil case setting.FieldForceTwoFactorAuth: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetForceTwoFactorAuth(v) return nil case setting.FieldDisablePasswordLogin: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDisablePasswordLogin(v) return nil case setting.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case setting.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Setting field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SettingMutation) 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 *SettingMutation) 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 *SettingMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Setting numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SettingMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SettingMutation) 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 *SettingMutation) ClearField(name string) error { return fmt.Errorf("unknown Setting 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 *SettingMutation) ResetField(name string) error { switch name { case setting.FieldEnableSSO: m.ResetEnableSSO() return nil case setting.FieldForceTwoFactorAuth: m.ResetForceTwoFactorAuth() return nil case setting.FieldDisablePasswordLogin: m.ResetDisablePasswordLogin() return nil case setting.FieldCreatedAt: m.ResetCreatedAt() return nil case setting.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Setting field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SettingMutation) 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 *SettingMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SettingMutation) 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 *SettingMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SettingMutation) 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 *SettingMutation) 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 *SettingMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Setting 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 *SettingMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Setting edge %s", name) } // TaskMutation represents an operation that mutates the Task nodes in the graph. type TaskMutation struct { config op Op typ string id *uuid.UUID task_id *string request_id *string model_type *consts.ModelType prompt *string is_accept *bool program_language *string work_mode *string completion *string code_lines *int64 addcode_lines *int64 input_tokens *int64 addinput_tokens *int64 output_tokens *int64 addoutput_tokens *int64 created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} task_records map[uuid.UUID]struct{} removedtask_records map[uuid.UUID]struct{} clearedtask_records bool user *uuid.UUID cleareduser bool model *uuid.UUID clearedmodel bool done bool oldValue func(context.Context) (*Task, error) predicates []predicate.Task } var _ ent.Mutation = (*TaskMutation)(nil) // taskOption allows management of the mutation configuration using functional options. type taskOption func(*TaskMutation) // newTaskMutation creates new mutation for the Task entity. func newTaskMutation(c config, op Op, opts ...taskOption) *TaskMutation { m := &TaskMutation{ config: c, op: op, typ: TypeTask, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withTaskID sets the ID field of the mutation. func withTaskID(id uuid.UUID) taskOption { return func(m *TaskMutation) { var ( err error once sync.Once value *Task ) m.oldValue = func(ctx context.Context) (*Task, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Task.Get(ctx, id) } }) return value, err } m.id = &id } } // withTask sets the old Task of the mutation. func withTask(node *Task) taskOption { return func(m *TaskMutation) { m.oldValue = func(context.Context) (*Task, 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 TaskMutation) 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 TaskMutation) 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 Task entities. func (m *TaskMutation) SetID(id uuid.UUID) { 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 *TaskMutation) ID() (id uuid.UUID, 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 *TaskMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Task.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetTaskID sets the "task_id" field. func (m *TaskMutation) SetTaskID(s string) { m.task_id = &s } // TaskID returns the value of the "task_id" field in the mutation. func (m *TaskMutation) TaskID() (r string, exists bool) { v := m.task_id if v == nil { return } return *v, true } // OldTaskID returns the old "task_id" field's value of the Task entity. // If the Task 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 *TaskMutation) OldTaskID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTaskID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTaskID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTaskID: %w", err) } return oldValue.TaskID, nil } // ResetTaskID resets all changes to the "task_id" field. func (m *TaskMutation) ResetTaskID() { m.task_id = nil } // SetUserID sets the "user_id" field. func (m *TaskMutation) SetUserID(u uuid.UUID) { m.user = &u } // UserID returns the value of the "user_id" field in the mutation. func (m *TaskMutation) UserID() (r uuid.UUID, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the Task entity. // If the Task 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 *TaskMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ClearUserID clears the value of the "user_id" field. func (m *TaskMutation) ClearUserID() { m.user = nil m.clearedFields[task.FieldUserID] = struct{}{} } // UserIDCleared returns if the "user_id" field was cleared in this mutation. func (m *TaskMutation) UserIDCleared() bool { _, ok := m.clearedFields[task.FieldUserID] return ok } // ResetUserID resets all changes to the "user_id" field. func (m *TaskMutation) ResetUserID() { m.user = nil delete(m.clearedFields, task.FieldUserID) } // SetModelID sets the "model_id" field. func (m *TaskMutation) SetModelID(u uuid.UUID) { m.model = &u } // ModelID returns the value of the "model_id" field in the mutation. func (m *TaskMutation) ModelID() (r uuid.UUID, exists bool) { v := m.model if v == nil { return } return *v, true } // OldModelID returns the old "model_id" field's value of the Task entity. // If the Task 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 *TaskMutation) OldModelID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldModelID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldModelID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldModelID: %w", err) } return oldValue.ModelID, nil } // ClearModelID clears the value of the "model_id" field. func (m *TaskMutation) ClearModelID() { m.model = nil m.clearedFields[task.FieldModelID] = struct{}{} } // ModelIDCleared returns if the "model_id" field was cleared in this mutation. func (m *TaskMutation) ModelIDCleared() bool { _, ok := m.clearedFields[task.FieldModelID] return ok } // ResetModelID resets all changes to the "model_id" field. func (m *TaskMutation) ResetModelID() { m.model = nil delete(m.clearedFields, task.FieldModelID) } // SetRequestID sets the "request_id" field. func (m *TaskMutation) SetRequestID(s string) { m.request_id = &s } // RequestID returns the value of the "request_id" field in the mutation. func (m *TaskMutation) RequestID() (r string, exists bool) { v := m.request_id if v == nil { return } return *v, true } // OldRequestID returns the old "request_id" field's value of the Task entity. // If the Task 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 *TaskMutation) OldRequestID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRequestID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRequestID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRequestID: %w", err) } return oldValue.RequestID, nil } // ClearRequestID clears the value of the "request_id" field. func (m *TaskMutation) ClearRequestID() { m.request_id = nil m.clearedFields[task.FieldRequestID] = struct{}{} } // RequestIDCleared returns if the "request_id" field was cleared in this mutation. func (m *TaskMutation) RequestIDCleared() bool { _, ok := m.clearedFields[task.FieldRequestID] return ok } // ResetRequestID resets all changes to the "request_id" field. func (m *TaskMutation) ResetRequestID() { m.request_id = nil delete(m.clearedFields, task.FieldRequestID) } // SetModelType sets the "model_type" field. func (m *TaskMutation) SetModelType(ct consts.ModelType) { m.model_type = &ct } // ModelType returns the value of the "model_type" field in the mutation. func (m *TaskMutation) ModelType() (r consts.ModelType, exists bool) { v := m.model_type if v == nil { return } return *v, true } // OldModelType returns the old "model_type" field's value of the Task entity. // If the Task 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 *TaskMutation) OldModelType(ctx context.Context) (v consts.ModelType, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldModelType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldModelType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldModelType: %w", err) } return oldValue.ModelType, nil } // ResetModelType resets all changes to the "model_type" field. func (m *TaskMutation) ResetModelType() { m.model_type = nil } // SetPrompt sets the "prompt" field. func (m *TaskMutation) SetPrompt(s string) { m.prompt = &s } // Prompt returns the value of the "prompt" field in the mutation. func (m *TaskMutation) Prompt() (r string, exists bool) { v := m.prompt if v == nil { return } return *v, true } // OldPrompt returns the old "prompt" field's value of the Task entity. // If the Task 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 *TaskMutation) OldPrompt(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPrompt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPrompt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPrompt: %w", err) } return oldValue.Prompt, nil } // ClearPrompt clears the value of the "prompt" field. func (m *TaskMutation) ClearPrompt() { m.prompt = nil m.clearedFields[task.FieldPrompt] = struct{}{} } // PromptCleared returns if the "prompt" field was cleared in this mutation. func (m *TaskMutation) PromptCleared() bool { _, ok := m.clearedFields[task.FieldPrompt] return ok } // ResetPrompt resets all changes to the "prompt" field. func (m *TaskMutation) ResetPrompt() { m.prompt = nil delete(m.clearedFields, task.FieldPrompt) } // SetIsAccept sets the "is_accept" field. func (m *TaskMutation) SetIsAccept(b bool) { m.is_accept = &b } // IsAccept returns the value of the "is_accept" field in the mutation. func (m *TaskMutation) IsAccept() (r bool, exists bool) { v := m.is_accept if v == nil { return } return *v, true } // OldIsAccept returns the old "is_accept" field's value of the Task entity. // If the Task 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 *TaskMutation) OldIsAccept(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIsAccept is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIsAccept requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIsAccept: %w", err) } return oldValue.IsAccept, nil } // ResetIsAccept resets all changes to the "is_accept" field. func (m *TaskMutation) ResetIsAccept() { m.is_accept = nil } // SetProgramLanguage sets the "program_language" field. func (m *TaskMutation) SetProgramLanguage(s string) { m.program_language = &s } // ProgramLanguage returns the value of the "program_language" field in the mutation. func (m *TaskMutation) ProgramLanguage() (r string, exists bool) { v := m.program_language if v == nil { return } return *v, true } // OldProgramLanguage returns the old "program_language" field's value of the Task entity. // If the Task 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 *TaskMutation) OldProgramLanguage(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProgramLanguage is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProgramLanguage requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProgramLanguage: %w", err) } return oldValue.ProgramLanguage, nil } // ClearProgramLanguage clears the value of the "program_language" field. func (m *TaskMutation) ClearProgramLanguage() { m.program_language = nil m.clearedFields[task.FieldProgramLanguage] = struct{}{} } // ProgramLanguageCleared returns if the "program_language" field was cleared in this mutation. func (m *TaskMutation) ProgramLanguageCleared() bool { _, ok := m.clearedFields[task.FieldProgramLanguage] return ok } // ResetProgramLanguage resets all changes to the "program_language" field. func (m *TaskMutation) ResetProgramLanguage() { m.program_language = nil delete(m.clearedFields, task.FieldProgramLanguage) } // SetWorkMode sets the "work_mode" field. func (m *TaskMutation) SetWorkMode(s string) { m.work_mode = &s } // WorkMode returns the value of the "work_mode" field in the mutation. func (m *TaskMutation) WorkMode() (r string, exists bool) { v := m.work_mode if v == nil { return } return *v, true } // OldWorkMode returns the old "work_mode" field's value of the Task entity. // If the Task 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 *TaskMutation) OldWorkMode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldWorkMode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldWorkMode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldWorkMode: %w", err) } return oldValue.WorkMode, nil } // ClearWorkMode clears the value of the "work_mode" field. func (m *TaskMutation) ClearWorkMode() { m.work_mode = nil m.clearedFields[task.FieldWorkMode] = struct{}{} } // WorkModeCleared returns if the "work_mode" field was cleared in this mutation. func (m *TaskMutation) WorkModeCleared() bool { _, ok := m.clearedFields[task.FieldWorkMode] return ok } // ResetWorkMode resets all changes to the "work_mode" field. func (m *TaskMutation) ResetWorkMode() { m.work_mode = nil delete(m.clearedFields, task.FieldWorkMode) } // SetCompletion sets the "completion" field. func (m *TaskMutation) SetCompletion(s string) { m.completion = &s } // Completion returns the value of the "completion" field in the mutation. func (m *TaskMutation) Completion() (r string, exists bool) { v := m.completion if v == nil { return } return *v, true } // OldCompletion returns the old "completion" field's value of the Task entity. // If the Task 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 *TaskMutation) OldCompletion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCompletion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCompletion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCompletion: %w", err) } return oldValue.Completion, nil } // ClearCompletion clears the value of the "completion" field. func (m *TaskMutation) ClearCompletion() { m.completion = nil m.clearedFields[task.FieldCompletion] = struct{}{} } // CompletionCleared returns if the "completion" field was cleared in this mutation. func (m *TaskMutation) CompletionCleared() bool { _, ok := m.clearedFields[task.FieldCompletion] return ok } // ResetCompletion resets all changes to the "completion" field. func (m *TaskMutation) ResetCompletion() { m.completion = nil delete(m.clearedFields, task.FieldCompletion) } // SetCodeLines sets the "code_lines" field. func (m *TaskMutation) SetCodeLines(i int64) { m.code_lines = &i m.addcode_lines = nil } // CodeLines returns the value of the "code_lines" field in the mutation. func (m *TaskMutation) CodeLines() (r int64, exists bool) { v := m.code_lines if v == nil { return } return *v, true } // OldCodeLines returns the old "code_lines" field's value of the Task entity. // If the Task 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 *TaskMutation) OldCodeLines(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCodeLines is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCodeLines requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCodeLines: %w", err) } return oldValue.CodeLines, nil } // AddCodeLines adds i to the "code_lines" field. func (m *TaskMutation) AddCodeLines(i int64) { if m.addcode_lines != nil { *m.addcode_lines += i } else { m.addcode_lines = &i } } // AddedCodeLines returns the value that was added to the "code_lines" field in this mutation. func (m *TaskMutation) AddedCodeLines() (r int64, exists bool) { v := m.addcode_lines if v == nil { return } return *v, true } // ClearCodeLines clears the value of the "code_lines" field. func (m *TaskMutation) ClearCodeLines() { m.code_lines = nil m.addcode_lines = nil m.clearedFields[task.FieldCodeLines] = struct{}{} } // CodeLinesCleared returns if the "code_lines" field was cleared in this mutation. func (m *TaskMutation) CodeLinesCleared() bool { _, ok := m.clearedFields[task.FieldCodeLines] return ok } // ResetCodeLines resets all changes to the "code_lines" field. func (m *TaskMutation) ResetCodeLines() { m.code_lines = nil m.addcode_lines = nil delete(m.clearedFields, task.FieldCodeLines) } // SetInputTokens sets the "input_tokens" field. func (m *TaskMutation) SetInputTokens(i int64) { m.input_tokens = &i m.addinput_tokens = nil } // InputTokens returns the value of the "input_tokens" field in the mutation. func (m *TaskMutation) InputTokens() (r int64, exists bool) { v := m.input_tokens if v == nil { return } return *v, true } // OldInputTokens returns the old "input_tokens" field's value of the Task entity. // If the Task 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 *TaskMutation) OldInputTokens(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldInputTokens is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldInputTokens requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldInputTokens: %w", err) } return oldValue.InputTokens, nil } // AddInputTokens adds i to the "input_tokens" field. func (m *TaskMutation) AddInputTokens(i int64) { if m.addinput_tokens != nil { *m.addinput_tokens += i } else { m.addinput_tokens = &i } } // AddedInputTokens returns the value that was added to the "input_tokens" field in this mutation. func (m *TaskMutation) AddedInputTokens() (r int64, exists bool) { v := m.addinput_tokens if v == nil { return } return *v, true } // ClearInputTokens clears the value of the "input_tokens" field. func (m *TaskMutation) ClearInputTokens() { m.input_tokens = nil m.addinput_tokens = nil m.clearedFields[task.FieldInputTokens] = struct{}{} } // InputTokensCleared returns if the "input_tokens" field was cleared in this mutation. func (m *TaskMutation) InputTokensCleared() bool { _, ok := m.clearedFields[task.FieldInputTokens] return ok } // ResetInputTokens resets all changes to the "input_tokens" field. func (m *TaskMutation) ResetInputTokens() { m.input_tokens = nil m.addinput_tokens = nil delete(m.clearedFields, task.FieldInputTokens) } // SetOutputTokens sets the "output_tokens" field. func (m *TaskMutation) SetOutputTokens(i int64) { m.output_tokens = &i m.addoutput_tokens = nil } // OutputTokens returns the value of the "output_tokens" field in the mutation. func (m *TaskMutation) OutputTokens() (r int64, exists bool) { v := m.output_tokens if v == nil { return } return *v, true } // OldOutputTokens returns the old "output_tokens" field's value of the Task entity. // If the Task 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 *TaskMutation) OldOutputTokens(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOutputTokens is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOutputTokens requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOutputTokens: %w", err) } return oldValue.OutputTokens, nil } // AddOutputTokens adds i to the "output_tokens" field. func (m *TaskMutation) AddOutputTokens(i int64) { if m.addoutput_tokens != nil { *m.addoutput_tokens += i } else { m.addoutput_tokens = &i } } // AddedOutputTokens returns the value that was added to the "output_tokens" field in this mutation. func (m *TaskMutation) AddedOutputTokens() (r int64, exists bool) { v := m.addoutput_tokens if v == nil { return } return *v, true } // ClearOutputTokens clears the value of the "output_tokens" field. func (m *TaskMutation) ClearOutputTokens() { m.output_tokens = nil m.addoutput_tokens = nil m.clearedFields[task.FieldOutputTokens] = struct{}{} } // OutputTokensCleared returns if the "output_tokens" field was cleared in this mutation. func (m *TaskMutation) OutputTokensCleared() bool { _, ok := m.clearedFields[task.FieldOutputTokens] return ok } // ResetOutputTokens resets all changes to the "output_tokens" field. func (m *TaskMutation) ResetOutputTokens() { m.output_tokens = nil m.addoutput_tokens = nil delete(m.clearedFields, task.FieldOutputTokens) } // SetCreatedAt sets the "created_at" field. func (m *TaskMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *TaskMutation) 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 Task entity. // If the Task 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 *TaskMutation) 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 *TaskMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *TaskMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *TaskMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Task entity. // If the Task 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 *TaskMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *TaskMutation) ResetUpdatedAt() { m.updated_at = nil } // AddTaskRecordIDs adds the "task_records" edge to the TaskRecord entity by ids. func (m *TaskMutation) AddTaskRecordIDs(ids ...uuid.UUID) { if m.task_records == nil { m.task_records = make(map[uuid.UUID]struct{}) } for i := range ids { m.task_records[ids[i]] = struct{}{} } } // ClearTaskRecords clears the "task_records" edge to the TaskRecord entity. func (m *TaskMutation) ClearTaskRecords() { m.clearedtask_records = true } // TaskRecordsCleared reports if the "task_records" edge to the TaskRecord entity was cleared. func (m *TaskMutation) TaskRecordsCleared() bool { return m.clearedtask_records } // RemoveTaskRecordIDs removes the "task_records" edge to the TaskRecord entity by IDs. func (m *TaskMutation) RemoveTaskRecordIDs(ids ...uuid.UUID) { if m.removedtask_records == nil { m.removedtask_records = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.task_records, ids[i]) m.removedtask_records[ids[i]] = struct{}{} } } // RemovedTaskRecords returns the removed IDs of the "task_records" edge to the TaskRecord entity. func (m *TaskMutation) RemovedTaskRecordsIDs() (ids []uuid.UUID) { for id := range m.removedtask_records { ids = append(ids, id) } return } // TaskRecordsIDs returns the "task_records" edge IDs in the mutation. func (m *TaskMutation) TaskRecordsIDs() (ids []uuid.UUID) { for id := range m.task_records { ids = append(ids, id) } return } // ResetTaskRecords resets all changes to the "task_records" edge. func (m *TaskMutation) ResetTaskRecords() { m.task_records = nil m.clearedtask_records = false m.removedtask_records = nil } // ClearUser clears the "user" edge to the User entity. func (m *TaskMutation) ClearUser() { m.cleareduser = true m.clearedFields[task.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *TaskMutation) UserCleared() bool { return m.UserIDCleared() || m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *TaskMutation) UserIDs() (ids []uuid.UUID) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *TaskMutation) ResetUser() { m.user = nil m.cleareduser = false } // ClearModel clears the "model" edge to the Model entity. func (m *TaskMutation) ClearModel() { m.clearedmodel = true m.clearedFields[task.FieldModelID] = struct{}{} } // ModelCleared reports if the "model" edge to the Model entity was cleared. func (m *TaskMutation) ModelCleared() bool { return m.ModelIDCleared() || m.clearedmodel } // ModelIDs returns the "model" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ModelID instead. It exists only for internal usage by the builders. func (m *TaskMutation) ModelIDs() (ids []uuid.UUID) { if id := m.model; id != nil { ids = append(ids, *id) } return } // ResetModel resets all changes to the "model" edge. func (m *TaskMutation) ResetModel() { m.model = nil m.clearedmodel = false } // Where appends a list predicates to the TaskMutation builder. func (m *TaskMutation) Where(ps ...predicate.Task) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the TaskMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *TaskMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Task, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *TaskMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *TaskMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Task). func (m *TaskMutation) 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 *TaskMutation) Fields() []string { fields := make([]string, 0, 15) if m.task_id != nil { fields = append(fields, task.FieldTaskID) } if m.user != nil { fields = append(fields, task.FieldUserID) } if m.model != nil { fields = append(fields, task.FieldModelID) } if m.request_id != nil { fields = append(fields, task.FieldRequestID) } if m.model_type != nil { fields = append(fields, task.FieldModelType) } if m.prompt != nil { fields = append(fields, task.FieldPrompt) } if m.is_accept != nil { fields = append(fields, task.FieldIsAccept) } if m.program_language != nil { fields = append(fields, task.FieldProgramLanguage) } if m.work_mode != nil { fields = append(fields, task.FieldWorkMode) } if m.completion != nil { fields = append(fields, task.FieldCompletion) } if m.code_lines != nil { fields = append(fields, task.FieldCodeLines) } if m.input_tokens != nil { fields = append(fields, task.FieldInputTokens) } if m.output_tokens != nil { fields = append(fields, task.FieldOutputTokens) } if m.created_at != nil { fields = append(fields, task.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, task.FieldUpdatedAt) } 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 *TaskMutation) Field(name string) (ent.Value, bool) { switch name { case task.FieldTaskID: return m.TaskID() case task.FieldUserID: return m.UserID() case task.FieldModelID: return m.ModelID() case task.FieldRequestID: return m.RequestID() case task.FieldModelType: return m.ModelType() case task.FieldPrompt: return m.Prompt() case task.FieldIsAccept: return m.IsAccept() case task.FieldProgramLanguage: return m.ProgramLanguage() case task.FieldWorkMode: return m.WorkMode() case task.FieldCompletion: return m.Completion() case task.FieldCodeLines: return m.CodeLines() case task.FieldInputTokens: return m.InputTokens() case task.FieldOutputTokens: return m.OutputTokens() case task.FieldCreatedAt: return m.CreatedAt() case task.FieldUpdatedAt: return m.UpdatedAt() } 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 *TaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case task.FieldTaskID: return m.OldTaskID(ctx) case task.FieldUserID: return m.OldUserID(ctx) case task.FieldModelID: return m.OldModelID(ctx) case task.FieldRequestID: return m.OldRequestID(ctx) case task.FieldModelType: return m.OldModelType(ctx) case task.FieldPrompt: return m.OldPrompt(ctx) case task.FieldIsAccept: return m.OldIsAccept(ctx) case task.FieldProgramLanguage: return m.OldProgramLanguage(ctx) case task.FieldWorkMode: return m.OldWorkMode(ctx) case task.FieldCompletion: return m.OldCompletion(ctx) case task.FieldCodeLines: return m.OldCodeLines(ctx) case task.FieldInputTokens: return m.OldInputTokens(ctx) case task.FieldOutputTokens: return m.OldOutputTokens(ctx) case task.FieldCreatedAt: return m.OldCreatedAt(ctx) case task.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Task 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 *TaskMutation) SetField(name string, value ent.Value) error { switch name { case task.FieldTaskID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTaskID(v) return nil case task.FieldUserID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case task.FieldModelID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetModelID(v) return nil case task.FieldRequestID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRequestID(v) return nil case task.FieldModelType: v, ok := value.(consts.ModelType) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetModelType(v) return nil case task.FieldPrompt: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPrompt(v) return nil case task.FieldIsAccept: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIsAccept(v) return nil case task.FieldProgramLanguage: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProgramLanguage(v) return nil case task.FieldWorkMode: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetWorkMode(v) return nil case task.FieldCompletion: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCompletion(v) return nil case task.FieldCodeLines: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCodeLines(v) return nil case task.FieldInputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetInputTokens(v) return nil case task.FieldOutputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOutputTokens(v) return nil case task.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case task.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Task field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *TaskMutation) AddedFields() []string { var fields []string if m.addcode_lines != nil { fields = append(fields, task.FieldCodeLines) } if m.addinput_tokens != nil { fields = append(fields, task.FieldInputTokens) } if m.addoutput_tokens != nil { fields = append(fields, task.FieldOutputTokens) } return fields } // 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 *TaskMutation) AddedField(name string) (ent.Value, bool) { switch name { case task.FieldCodeLines: return m.AddedCodeLines() case task.FieldInputTokens: return m.AddedInputTokens() case task.FieldOutputTokens: return m.AddedOutputTokens() } 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 *TaskMutation) AddField(name string, value ent.Value) error { switch name { case task.FieldCodeLines: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddCodeLines(v) return nil case task.FieldInputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddInputTokens(v) return nil case task.FieldOutputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddOutputTokens(v) return nil } return fmt.Errorf("unknown Task numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TaskMutation) ClearedFields() []string { var fields []string if m.FieldCleared(task.FieldUserID) { fields = append(fields, task.FieldUserID) } if m.FieldCleared(task.FieldModelID) { fields = append(fields, task.FieldModelID) } if m.FieldCleared(task.FieldRequestID) { fields = append(fields, task.FieldRequestID) } if m.FieldCleared(task.FieldPrompt) { fields = append(fields, task.FieldPrompt) } if m.FieldCleared(task.FieldProgramLanguage) { fields = append(fields, task.FieldProgramLanguage) } if m.FieldCleared(task.FieldWorkMode) { fields = append(fields, task.FieldWorkMode) } if m.FieldCleared(task.FieldCompletion) { fields = append(fields, task.FieldCompletion) } if m.FieldCleared(task.FieldCodeLines) { fields = append(fields, task.FieldCodeLines) } if m.FieldCleared(task.FieldInputTokens) { fields = append(fields, task.FieldInputTokens) } if m.FieldCleared(task.FieldOutputTokens) { fields = append(fields, task.FieldOutputTokens) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *TaskMutation) 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 *TaskMutation) ClearField(name string) error { switch name { case task.FieldUserID: m.ClearUserID() return nil case task.FieldModelID: m.ClearModelID() return nil case task.FieldRequestID: m.ClearRequestID() return nil case task.FieldPrompt: m.ClearPrompt() return nil case task.FieldProgramLanguage: m.ClearProgramLanguage() return nil case task.FieldWorkMode: m.ClearWorkMode() return nil case task.FieldCompletion: m.ClearCompletion() return nil case task.FieldCodeLines: m.ClearCodeLines() return nil case task.FieldInputTokens: m.ClearInputTokens() return nil case task.FieldOutputTokens: m.ClearOutputTokens() return nil } return fmt.Errorf("unknown Task 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 *TaskMutation) ResetField(name string) error { switch name { case task.FieldTaskID: m.ResetTaskID() return nil case task.FieldUserID: m.ResetUserID() return nil case task.FieldModelID: m.ResetModelID() return nil case task.FieldRequestID: m.ResetRequestID() return nil case task.FieldModelType: m.ResetModelType() return nil case task.FieldPrompt: m.ResetPrompt() return nil case task.FieldIsAccept: m.ResetIsAccept() return nil case task.FieldProgramLanguage: m.ResetProgramLanguage() return nil case task.FieldWorkMode: m.ResetWorkMode() return nil case task.FieldCompletion: m.ResetCompletion() return nil case task.FieldCodeLines: m.ResetCodeLines() return nil case task.FieldInputTokens: m.ResetInputTokens() return nil case task.FieldOutputTokens: m.ResetOutputTokens() return nil case task.FieldCreatedAt: m.ResetCreatedAt() return nil case task.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Task field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *TaskMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.task_records != nil { edges = append(edges, task.EdgeTaskRecords) } if m.user != nil { edges = append(edges, task.EdgeUser) } if m.model != nil { edges = append(edges, task.EdgeModel) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *TaskMutation) AddedIDs(name string) []ent.Value { switch name { case task.EdgeTaskRecords: ids := make([]ent.Value, 0, len(m.task_records)) for id := range m.task_records { ids = append(ids, id) } return ids case task.EdgeUser: if id := m.user; id != nil { return []ent.Value{*id} } case task.EdgeModel: if id := m.model; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *TaskMutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedtask_records != nil { edges = append(edges, task.EdgeTaskRecords) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *TaskMutation) RemovedIDs(name string) []ent.Value { switch name { case task.EdgeTaskRecords: ids := make([]ent.Value, 0, len(m.removedtask_records)) for id := range m.removedtask_records { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TaskMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedtask_records { edges = append(edges, task.EdgeTaskRecords) } if m.cleareduser { edges = append(edges, task.EdgeUser) } if m.clearedmodel { edges = append(edges, task.EdgeModel) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *TaskMutation) EdgeCleared(name string) bool { switch name { case task.EdgeTaskRecords: return m.clearedtask_records case task.EdgeUser: return m.cleareduser case task.EdgeModel: return m.clearedmodel } 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 *TaskMutation) ClearEdge(name string) error { switch name { case task.EdgeUser: m.ClearUser() return nil case task.EdgeModel: m.ClearModel() return nil } return fmt.Errorf("unknown Task 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 *TaskMutation) ResetEdge(name string) error { switch name { case task.EdgeTaskRecords: m.ResetTaskRecords() return nil case task.EdgeUser: m.ResetUser() return nil case task.EdgeModel: m.ResetModel() return nil } return fmt.Errorf("unknown Task edge %s", name) } // TaskRecordMutation represents an operation that mutates the TaskRecord nodes in the graph. type TaskRecordMutation struct { config op Op typ string id *uuid.UUID completion *string output_tokens *int64 addoutput_tokens *int64 created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} task *uuid.UUID clearedtask bool done bool oldValue func(context.Context) (*TaskRecord, error) predicates []predicate.TaskRecord } var _ ent.Mutation = (*TaskRecordMutation)(nil) // taskrecordOption allows management of the mutation configuration using functional options. type taskrecordOption func(*TaskRecordMutation) // newTaskRecordMutation creates new mutation for the TaskRecord entity. func newTaskRecordMutation(c config, op Op, opts ...taskrecordOption) *TaskRecordMutation { m := &TaskRecordMutation{ config: c, op: op, typ: TypeTaskRecord, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withTaskRecordID sets the ID field of the mutation. func withTaskRecordID(id uuid.UUID) taskrecordOption { return func(m *TaskRecordMutation) { var ( err error once sync.Once value *TaskRecord ) m.oldValue = func(ctx context.Context) (*TaskRecord, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().TaskRecord.Get(ctx, id) } }) return value, err } m.id = &id } } // withTaskRecord sets the old TaskRecord of the mutation. func withTaskRecord(node *TaskRecord) taskrecordOption { return func(m *TaskRecordMutation) { m.oldValue = func(context.Context) (*TaskRecord, 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 TaskRecordMutation) 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 TaskRecordMutation) 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 TaskRecord entities. func (m *TaskRecordMutation) SetID(id uuid.UUID) { 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 *TaskRecordMutation) ID() (id uuid.UUID, 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 *TaskRecordMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().TaskRecord.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetTaskID sets the "task_id" field. func (m *TaskRecordMutation) SetTaskID(u uuid.UUID) { m.task = &u } // TaskID returns the value of the "task_id" field in the mutation. func (m *TaskRecordMutation) TaskID() (r uuid.UUID, exists bool) { v := m.task if v == nil { return } return *v, true } // OldTaskID returns the old "task_id" field's value of the TaskRecord entity. // If the TaskRecord 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 *TaskRecordMutation) OldTaskID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTaskID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTaskID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTaskID: %w", err) } return oldValue.TaskID, nil } // ClearTaskID clears the value of the "task_id" field. func (m *TaskRecordMutation) ClearTaskID() { m.task = nil m.clearedFields[taskrecord.FieldTaskID] = struct{}{} } // TaskIDCleared returns if the "task_id" field was cleared in this mutation. func (m *TaskRecordMutation) TaskIDCleared() bool { _, ok := m.clearedFields[taskrecord.FieldTaskID] return ok } // ResetTaskID resets all changes to the "task_id" field. func (m *TaskRecordMutation) ResetTaskID() { m.task = nil delete(m.clearedFields, taskrecord.FieldTaskID) } // SetCompletion sets the "completion" field. func (m *TaskRecordMutation) SetCompletion(s string) { m.completion = &s } // Completion returns the value of the "completion" field in the mutation. func (m *TaskRecordMutation) Completion() (r string, exists bool) { v := m.completion if v == nil { return } return *v, true } // OldCompletion returns the old "completion" field's value of the TaskRecord entity. // If the TaskRecord 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 *TaskRecordMutation) OldCompletion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCompletion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCompletion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCompletion: %w", err) } return oldValue.Completion, nil } // ResetCompletion resets all changes to the "completion" field. func (m *TaskRecordMutation) ResetCompletion() { m.completion = nil } // SetOutputTokens sets the "output_tokens" field. func (m *TaskRecordMutation) SetOutputTokens(i int64) { m.output_tokens = &i m.addoutput_tokens = nil } // OutputTokens returns the value of the "output_tokens" field in the mutation. func (m *TaskRecordMutation) OutputTokens() (r int64, exists bool) { v := m.output_tokens if v == nil { return } return *v, true } // OldOutputTokens returns the old "output_tokens" field's value of the TaskRecord entity. // If the TaskRecord 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 *TaskRecordMutation) OldOutputTokens(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOutputTokens is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOutputTokens requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOutputTokens: %w", err) } return oldValue.OutputTokens, nil } // AddOutputTokens adds i to the "output_tokens" field. func (m *TaskRecordMutation) AddOutputTokens(i int64) { if m.addoutput_tokens != nil { *m.addoutput_tokens += i } else { m.addoutput_tokens = &i } } // AddedOutputTokens returns the value that was added to the "output_tokens" field in this mutation. func (m *TaskRecordMutation) AddedOutputTokens() (r int64, exists bool) { v := m.addoutput_tokens if v == nil { return } return *v, true } // ResetOutputTokens resets all changes to the "output_tokens" field. func (m *TaskRecordMutation) ResetOutputTokens() { m.output_tokens = nil m.addoutput_tokens = nil } // SetCreatedAt sets the "created_at" field. func (m *TaskRecordMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *TaskRecordMutation) 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 TaskRecord entity. // If the TaskRecord 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 *TaskRecordMutation) 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 *TaskRecordMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *TaskRecordMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *TaskRecordMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the TaskRecord entity. // If the TaskRecord 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 *TaskRecordMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *TaskRecordMutation) ResetUpdatedAt() { m.updated_at = nil } // ClearTask clears the "task" edge to the Task entity. func (m *TaskRecordMutation) ClearTask() { m.clearedtask = true m.clearedFields[taskrecord.FieldTaskID] = struct{}{} } // TaskCleared reports if the "task" edge to the Task entity was cleared. func (m *TaskRecordMutation) TaskCleared() bool { return m.TaskIDCleared() || m.clearedtask } // TaskIDs returns the "task" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // TaskID instead. It exists only for internal usage by the builders. func (m *TaskRecordMutation) TaskIDs() (ids []uuid.UUID) { if id := m.task; id != nil { ids = append(ids, *id) } return } // ResetTask resets all changes to the "task" edge. func (m *TaskRecordMutation) ResetTask() { m.task = nil m.clearedtask = false } // Where appends a list predicates to the TaskRecordMutation builder. func (m *TaskRecordMutation) Where(ps ...predicate.TaskRecord) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the TaskRecordMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *TaskRecordMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.TaskRecord, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *TaskRecordMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *TaskRecordMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (TaskRecord). func (m *TaskRecordMutation) 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 *TaskRecordMutation) Fields() []string { fields := make([]string, 0, 5) if m.task != nil { fields = append(fields, taskrecord.FieldTaskID) } if m.completion != nil { fields = append(fields, taskrecord.FieldCompletion) } if m.output_tokens != nil { fields = append(fields, taskrecord.FieldOutputTokens) } if m.created_at != nil { fields = append(fields, taskrecord.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, taskrecord.FieldUpdatedAt) } 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 *TaskRecordMutation) Field(name string) (ent.Value, bool) { switch name { case taskrecord.FieldTaskID: return m.TaskID() case taskrecord.FieldCompletion: return m.Completion() case taskrecord.FieldOutputTokens: return m.OutputTokens() case taskrecord.FieldCreatedAt: return m.CreatedAt() case taskrecord.FieldUpdatedAt: return m.UpdatedAt() } 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 *TaskRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case taskrecord.FieldTaskID: return m.OldTaskID(ctx) case taskrecord.FieldCompletion: return m.OldCompletion(ctx) case taskrecord.FieldOutputTokens: return m.OldOutputTokens(ctx) case taskrecord.FieldCreatedAt: return m.OldCreatedAt(ctx) case taskrecord.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown TaskRecord 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 *TaskRecordMutation) SetField(name string, value ent.Value) error { switch name { case taskrecord.FieldTaskID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTaskID(v) return nil case taskrecord.FieldCompletion: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCompletion(v) return nil case taskrecord.FieldOutputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOutputTokens(v) return nil case taskrecord.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case taskrecord.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown TaskRecord field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *TaskRecordMutation) AddedFields() []string { var fields []string if m.addoutput_tokens != nil { fields = append(fields, taskrecord.FieldOutputTokens) } return fields } // 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 *TaskRecordMutation) AddedField(name string) (ent.Value, bool) { switch name { case taskrecord.FieldOutputTokens: return m.AddedOutputTokens() } 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 *TaskRecordMutation) AddField(name string, value ent.Value) error { switch name { case taskrecord.FieldOutputTokens: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddOutputTokens(v) return nil } return fmt.Errorf("unknown TaskRecord numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TaskRecordMutation) ClearedFields() []string { var fields []string if m.FieldCleared(taskrecord.FieldTaskID) { fields = append(fields, taskrecord.FieldTaskID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *TaskRecordMutation) 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 *TaskRecordMutation) ClearField(name string) error { switch name { case taskrecord.FieldTaskID: m.ClearTaskID() return nil } return fmt.Errorf("unknown TaskRecord 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 *TaskRecordMutation) ResetField(name string) error { switch name { case taskrecord.FieldTaskID: m.ResetTaskID() return nil case taskrecord.FieldCompletion: m.ResetCompletion() return nil case taskrecord.FieldOutputTokens: m.ResetOutputTokens() return nil case taskrecord.FieldCreatedAt: m.ResetCreatedAt() return nil case taskrecord.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown TaskRecord field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *TaskRecordMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.task != nil { edges = append(edges, taskrecord.EdgeTask) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *TaskRecordMutation) AddedIDs(name string) []ent.Value { switch name { case taskrecord.EdgeTask: if id := m.task; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *TaskRecordMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *TaskRecordMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TaskRecordMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedtask { edges = append(edges, taskrecord.EdgeTask) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *TaskRecordMutation) EdgeCleared(name string) bool { switch name { case taskrecord.EdgeTask: return m.clearedtask } 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 *TaskRecordMutation) ClearEdge(name string) error { switch name { case taskrecord.EdgeTask: m.ClearTask() return nil } return fmt.Errorf("unknown TaskRecord 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 *TaskRecordMutation) ResetEdge(name string) error { switch name { case taskrecord.EdgeTask: m.ResetTask() return nil } return fmt.Errorf("unknown TaskRecord edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config op Op typ string id *uuid.UUID username *string password *string email *string status *consts.UserStatus created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} login_histories map[uuid.UUID]struct{} removedlogin_histories map[uuid.UUID]struct{} clearedlogin_histories bool models map[uuid.UUID]struct{} removedmodels map[uuid.UUID]struct{} clearedmodels bool tasks map[uuid.UUID]struct{} removedtasks map[uuid.UUID]struct{} clearedtasks bool done bool oldValue func(context.Context) (*User, error) predicates []predicate.User } var _ ent.Mutation = (*UserMutation)(nil) // userOption allows management of the mutation configuration using functional options. type userOption func(*UserMutation) // newUserMutation creates new mutation for the User entity. func newUserMutation(c config, op Op, opts ...userOption) *UserMutation { m := &UserMutation{ config: c, op: op, typ: TypeUser, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserID sets the ID field of the mutation. func withUserID(id uuid.UUID) userOption { return func(m *UserMutation) { var ( err error once sync.Once value *User ) m.oldValue = func(ctx context.Context) (*User, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().User.Get(ctx, id) } }) return value, err } m.id = &id } } // withUser sets the old User of the mutation. func withUser(node *User) userOption { return func(m *UserMutation) { m.oldValue = func(context.Context) (*User, 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 UserMutation) 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 UserMutation) 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 User entities. func (m *UserMutation) SetID(id uuid.UUID) { 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 *UserMutation) ID() (id uuid.UUID, 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 *UserMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().User.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUsername sets the "username" field. func (m *UserMutation) SetUsername(s string) { m.username = &s } // Username returns the value of the "username" field in the mutation. func (m *UserMutation) Username() (r string, exists bool) { v := m.username if v == nil { return } return *v, true } // OldUsername returns the old "username" field's value of the User entity. // If the User 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 *UserMutation) OldUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUsername: %w", err) } return oldValue.Username, nil } // ResetUsername resets all changes to the "username" field. func (m *UserMutation) ResetUsername() { m.username = nil } // SetPassword sets the "password" field. func (m *UserMutation) SetPassword(s string) { m.password = &s } // Password returns the value of the "password" field in the mutation. func (m *UserMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old "password" field's value of the User entity. // If the User 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 *UserMutation) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPassword requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPassword: %w", err) } return oldValue.Password, nil } // ResetPassword resets all changes to the "password" field. func (m *UserMutation) ResetPassword() { m.password = nil } // SetEmail sets the "email" field. func (m *UserMutation) SetEmail(s string) { m.email = &s } // Email returns the value of the "email" field in the mutation. func (m *UserMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old "email" field's value of the User entity. // If the User 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 *UserMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmail: %w", err) } return oldValue.Email, nil } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil } // SetStatus sets the "status" field. func (m *UserMutation) SetStatus(cs consts.UserStatus) { m.status = &cs } // Status returns the value of the "status" field in the mutation. func (m *UserMutation) Status() (r consts.UserStatus, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the User entity. // If the User 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 *UserMutation) OldStatus(ctx context.Context) (v consts.UserStatus, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *UserMutation) ResetStatus() { m.status = nil } // SetCreatedAt sets the "created_at" field. func (m *UserMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserMutation) 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 User entity. // If the User 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 *UserMutation) 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 *UserMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *UserMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the User entity. // If the User 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 *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *UserMutation) ResetUpdatedAt() { m.updated_at = nil } // AddLoginHistoryIDs adds the "login_histories" edge to the UserLoginHistory entity by ids. func (m *UserMutation) AddLoginHistoryIDs(ids ...uuid.UUID) { if m.login_histories == nil { m.login_histories = make(map[uuid.UUID]struct{}) } for i := range ids { m.login_histories[ids[i]] = struct{}{} } } // ClearLoginHistories clears the "login_histories" edge to the UserLoginHistory entity. func (m *UserMutation) ClearLoginHistories() { m.clearedlogin_histories = true } // LoginHistoriesCleared reports if the "login_histories" edge to the UserLoginHistory entity was cleared. func (m *UserMutation) LoginHistoriesCleared() bool { return m.clearedlogin_histories } // RemoveLoginHistoryIDs removes the "login_histories" edge to the UserLoginHistory entity by IDs. func (m *UserMutation) RemoveLoginHistoryIDs(ids ...uuid.UUID) { if m.removedlogin_histories == nil { m.removedlogin_histories = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.login_histories, ids[i]) m.removedlogin_histories[ids[i]] = struct{}{} } } // RemovedLoginHistories returns the removed IDs of the "login_histories" edge to the UserLoginHistory entity. func (m *UserMutation) RemovedLoginHistoriesIDs() (ids []uuid.UUID) { for id := range m.removedlogin_histories { ids = append(ids, id) } return } // LoginHistoriesIDs returns the "login_histories" edge IDs in the mutation. func (m *UserMutation) LoginHistoriesIDs() (ids []uuid.UUID) { for id := range m.login_histories { ids = append(ids, id) } return } // ResetLoginHistories resets all changes to the "login_histories" edge. func (m *UserMutation) ResetLoginHistories() { m.login_histories = nil m.clearedlogin_histories = false m.removedlogin_histories = nil } // AddModelIDs adds the "models" edge to the Model entity by ids. func (m *UserMutation) AddModelIDs(ids ...uuid.UUID) { if m.models == nil { m.models = make(map[uuid.UUID]struct{}) } for i := range ids { m.models[ids[i]] = struct{}{} } } // ClearModels clears the "models" edge to the Model entity. func (m *UserMutation) ClearModels() { m.clearedmodels = true } // ModelsCleared reports if the "models" edge to the Model entity was cleared. func (m *UserMutation) ModelsCleared() bool { return m.clearedmodels } // RemoveModelIDs removes the "models" edge to the Model entity by IDs. func (m *UserMutation) RemoveModelIDs(ids ...uuid.UUID) { if m.removedmodels == nil { m.removedmodels = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.models, ids[i]) m.removedmodels[ids[i]] = struct{}{} } } // RemovedModels returns the removed IDs of the "models" edge to the Model entity. func (m *UserMutation) RemovedModelsIDs() (ids []uuid.UUID) { for id := range m.removedmodels { ids = append(ids, id) } return } // ModelsIDs returns the "models" edge IDs in the mutation. func (m *UserMutation) ModelsIDs() (ids []uuid.UUID) { for id := range m.models { ids = append(ids, id) } return } // ResetModels resets all changes to the "models" edge. func (m *UserMutation) ResetModels() { m.models = nil m.clearedmodels = false m.removedmodels = nil } // AddTaskIDs adds the "tasks" edge to the Task entity by ids. func (m *UserMutation) AddTaskIDs(ids ...uuid.UUID) { if m.tasks == nil { m.tasks = make(map[uuid.UUID]struct{}) } for i := range ids { m.tasks[ids[i]] = struct{}{} } } // ClearTasks clears the "tasks" edge to the Task entity. func (m *UserMutation) ClearTasks() { m.clearedtasks = true } // TasksCleared reports if the "tasks" edge to the Task entity was cleared. func (m *UserMutation) TasksCleared() bool { return m.clearedtasks } // RemoveTaskIDs removes the "tasks" edge to the Task entity by IDs. func (m *UserMutation) RemoveTaskIDs(ids ...uuid.UUID) { if m.removedtasks == nil { m.removedtasks = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.tasks, ids[i]) m.removedtasks[ids[i]] = struct{}{} } } // RemovedTasks returns the removed IDs of the "tasks" edge to the Task entity. func (m *UserMutation) RemovedTasksIDs() (ids []uuid.UUID) { for id := range m.removedtasks { ids = append(ids, id) } return } // TasksIDs returns the "tasks" edge IDs in the mutation. func (m *UserMutation) TasksIDs() (ids []uuid.UUID) { for id := range m.tasks { ids = append(ids, id) } return } // ResetTasks resets all changes to the "tasks" edge. func (m *UserMutation) ResetTasks() { m.tasks = nil m.clearedtasks = false m.removedtasks = nil } // Where appends a list predicates to the UserMutation builder. func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.User, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (User). func (m *UserMutation) 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 *UserMutation) Fields() []string { fields := make([]string, 0, 6) if m.username != nil { fields = append(fields, user.FieldUsername) } if m.password != nil { fields = append(fields, user.FieldPassword) } if m.email != nil { fields = append(fields, user.FieldEmail) } if m.status != nil { fields = append(fields, user.FieldStatus) } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } 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 *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldUsername: return m.Username() case user.FieldPassword: return m.Password() case user.FieldEmail: return m.Email() case user.FieldStatus: return m.Status() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() } 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 *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case user.FieldUsername: return m.OldUsername(ctx) case user.FieldPassword: return m.OldPassword(ctx) case user.FieldEmail: return m.OldEmail(ctx) case user.FieldStatus: return m.OldStatus(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown User 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 *UserMutation) SetField(name string, value ent.Value) error { switch name { case user.FieldUsername: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsername(v) return nil case user.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(v) return nil case user.FieldEmail: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmail(v) return nil case user.FieldStatus: v, ok := value.(consts.UserStatus) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case user.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case user.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown User field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserMutation) 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 *UserMutation) 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 *UserMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown User numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMutation) 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 *UserMutation) ClearField(name string) error { return fmt.Errorf("unknown User 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 *UserMutation) ResetField(name string) error { switch name { case user.FieldUsername: m.ResetUsername() return nil case user.FieldPassword: m.ResetPassword() return nil case user.FieldEmail: m.ResetEmail() return nil case user.FieldStatus: m.ResetStatus() return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown User field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.login_histories != nil { edges = append(edges, user.EdgeLoginHistories) } if m.models != nil { edges = append(edges, user.EdgeModels) } if m.tasks != nil { edges = append(edges, user.EdgeTasks) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserMutation) AddedIDs(name string) []ent.Value { switch name { case user.EdgeLoginHistories: ids := make([]ent.Value, 0, len(m.login_histories)) for id := range m.login_histories { ids = append(ids, id) } return ids case user.EdgeModels: ids := make([]ent.Value, 0, len(m.models)) for id := range m.models { ids = append(ids, id) } return ids case user.EdgeTasks: ids := make([]ent.Value, 0, len(m.tasks)) for id := range m.tasks { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedlogin_histories != nil { edges = append(edges, user.EdgeLoginHistories) } if m.removedmodels != nil { edges = append(edges, user.EdgeModels) } if m.removedtasks != nil { edges = append(edges, user.EdgeTasks) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *UserMutation) RemovedIDs(name string) []ent.Value { switch name { case user.EdgeLoginHistories: ids := make([]ent.Value, 0, len(m.removedlogin_histories)) for id := range m.removedlogin_histories { ids = append(ids, id) } return ids case user.EdgeModels: ids := make([]ent.Value, 0, len(m.removedmodels)) for id := range m.removedmodels { ids = append(ids, id) } return ids case user.EdgeTasks: ids := make([]ent.Value, 0, len(m.removedtasks)) for id := range m.removedtasks { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedlogin_histories { edges = append(edges, user.EdgeLoginHistories) } if m.clearedmodels { edges = append(edges, user.EdgeModels) } if m.clearedtasks { edges = append(edges, user.EdgeTasks) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserMutation) EdgeCleared(name string) bool { switch name { case user.EdgeLoginHistories: return m.clearedlogin_histories case user.EdgeModels: return m.clearedmodels case user.EdgeTasks: return m.clearedtasks } 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 *UserMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown User 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 *UserMutation) ResetEdge(name string) error { switch name { case user.EdgeLoginHistories: m.ResetLoginHistories() return nil case user.EdgeModels: m.ResetModels() return nil case user.EdgeTasks: m.ResetTasks() return nil } return fmt.Errorf("unknown User edge %s", name) } // UserLoginHistoryMutation represents an operation that mutates the UserLoginHistory nodes in the graph. type UserLoginHistoryMutation struct { config op Op typ string id *uuid.UUID user_id *uuid.UUID ip *string country *string province *string city *string isp *string asn *string client_version *string device *string created_at *time.Time clearedFields map[string]struct{} owner *uuid.UUID clearedowner bool done bool oldValue func(context.Context) (*UserLoginHistory, error) predicates []predicate.UserLoginHistory } var _ ent.Mutation = (*UserLoginHistoryMutation)(nil) // userloginhistoryOption allows management of the mutation configuration using functional options. type userloginhistoryOption func(*UserLoginHistoryMutation) // newUserLoginHistoryMutation creates new mutation for the UserLoginHistory entity. func newUserLoginHistoryMutation(c config, op Op, opts ...userloginhistoryOption) *UserLoginHistoryMutation { m := &UserLoginHistoryMutation{ config: c, op: op, typ: TypeUserLoginHistory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserLoginHistoryID sets the ID field of the mutation. func withUserLoginHistoryID(id uuid.UUID) userloginhistoryOption { return func(m *UserLoginHistoryMutation) { var ( err error once sync.Once value *UserLoginHistory ) m.oldValue = func(ctx context.Context) (*UserLoginHistory, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserLoginHistory.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserLoginHistory sets the old UserLoginHistory of the mutation. func withUserLoginHistory(node *UserLoginHistory) userloginhistoryOption { return func(m *UserLoginHistoryMutation) { m.oldValue = func(context.Context) (*UserLoginHistory, 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 UserLoginHistoryMutation) 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 UserLoginHistoryMutation) 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 UserLoginHistory entities. func (m *UserLoginHistoryMutation) SetID(id uuid.UUID) { 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 *UserLoginHistoryMutation) ID() (id uuid.UUID, 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 *UserLoginHistoryMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().UserLoginHistory.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUserID sets the "user_id" field. func (m *UserLoginHistoryMutation) SetUserID(u uuid.UUID) { m.user_id = &u } // UserID returns the value of the "user_id" field in the mutation. func (m *UserLoginHistoryMutation) UserID() (r uuid.UUID, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *UserLoginHistoryMutation) ResetUserID() { m.user_id = nil } // SetIP sets the "ip" field. func (m *UserLoginHistoryMutation) SetIP(s string) { m.ip = &s } // IP returns the value of the "ip" field in the mutation. func (m *UserLoginHistoryMutation) IP() (r string, exists bool) { v := m.ip if v == nil { return } return *v, true } // OldIP returns the old "ip" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldIP(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIP requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIP: %w", err) } return oldValue.IP, nil } // ResetIP resets all changes to the "ip" field. func (m *UserLoginHistoryMutation) ResetIP() { m.ip = nil } // SetCountry sets the "country" field. func (m *UserLoginHistoryMutation) SetCountry(s string) { m.country = &s } // Country returns the value of the "country" field in the mutation. func (m *UserLoginHistoryMutation) Country() (r string, exists bool) { v := m.country if v == nil { return } return *v, true } // OldCountry returns the old "country" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldCountry(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCountry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCountry requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCountry: %w", err) } return oldValue.Country, nil } // ResetCountry resets all changes to the "country" field. func (m *UserLoginHistoryMutation) ResetCountry() { m.country = nil } // SetProvince sets the "province" field. func (m *UserLoginHistoryMutation) SetProvince(s string) { m.province = &s } // Province returns the value of the "province" field in the mutation. func (m *UserLoginHistoryMutation) Province() (r string, exists bool) { v := m.province if v == nil { return } return *v, true } // OldProvince returns the old "province" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldProvince(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProvince is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProvince requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProvince: %w", err) } return oldValue.Province, nil } // ResetProvince resets all changes to the "province" field. func (m *UserLoginHistoryMutation) ResetProvince() { m.province = nil } // SetCity sets the "city" field. func (m *UserLoginHistoryMutation) SetCity(s string) { m.city = &s } // City returns the value of the "city" field in the mutation. func (m *UserLoginHistoryMutation) City() (r string, exists bool) { v := m.city if v == nil { return } return *v, true } // OldCity returns the old "city" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldCity(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCity is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCity requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCity: %w", err) } return oldValue.City, nil } // ResetCity resets all changes to the "city" field. func (m *UserLoginHistoryMutation) ResetCity() { m.city = nil } // SetIsp sets the "isp" field. func (m *UserLoginHistoryMutation) SetIsp(s string) { m.isp = &s } // Isp returns the value of the "isp" field in the mutation. func (m *UserLoginHistoryMutation) Isp() (r string, exists bool) { v := m.isp if v == nil { return } return *v, true } // OldIsp returns the old "isp" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldIsp(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIsp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIsp requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIsp: %w", err) } return oldValue.Isp, nil } // ResetIsp resets all changes to the "isp" field. func (m *UserLoginHistoryMutation) ResetIsp() { m.isp = nil } // SetAsn sets the "asn" field. func (m *UserLoginHistoryMutation) SetAsn(s string) { m.asn = &s } // Asn returns the value of the "asn" field in the mutation. func (m *UserLoginHistoryMutation) Asn() (r string, exists bool) { v := m.asn if v == nil { return } return *v, true } // OldAsn returns the old "asn" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldAsn(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAsn is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAsn requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAsn: %w", err) } return oldValue.Asn, nil } // ResetAsn resets all changes to the "asn" field. func (m *UserLoginHistoryMutation) ResetAsn() { m.asn = nil } // SetClientVersion sets the "client_version" field. func (m *UserLoginHistoryMutation) SetClientVersion(s string) { m.client_version = &s } // ClientVersion returns the value of the "client_version" field in the mutation. func (m *UserLoginHistoryMutation) ClientVersion() (r string, exists bool) { v := m.client_version if v == nil { return } return *v, true } // OldClientVersion returns the old "client_version" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldClientVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldClientVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldClientVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldClientVersion: %w", err) } return oldValue.ClientVersion, nil } // ResetClientVersion resets all changes to the "client_version" field. func (m *UserLoginHistoryMutation) ResetClientVersion() { m.client_version = nil } // SetDevice sets the "device" field. func (m *UserLoginHistoryMutation) SetDevice(s string) { m.device = &s } // Device returns the value of the "device" field in the mutation. func (m *UserLoginHistoryMutation) Device() (r string, exists bool) { v := m.device if v == nil { return } return *v, true } // OldDevice returns the old "device" field's value of the UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) OldDevice(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDevice is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDevice requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDevice: %w", err) } return oldValue.Device, nil } // ResetDevice resets all changes to the "device" field. func (m *UserLoginHistoryMutation) ResetDevice() { m.device = nil } // SetCreatedAt sets the "created_at" field. func (m *UserLoginHistoryMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserLoginHistoryMutation) 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 UserLoginHistory entity. // If the UserLoginHistory 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 *UserLoginHistoryMutation) 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 *UserLoginHistoryMutation) ResetCreatedAt() { m.created_at = nil } // SetOwnerID sets the "owner" edge to the User entity by id. func (m *UserLoginHistoryMutation) SetOwnerID(id uuid.UUID) { m.owner = &id } // ClearOwner clears the "owner" edge to the User entity. func (m *UserLoginHistoryMutation) ClearOwner() { m.clearedowner = true } // OwnerCleared reports if the "owner" edge to the User entity was cleared. func (m *UserLoginHistoryMutation) OwnerCleared() bool { return m.clearedowner } // OwnerID returns the "owner" edge ID in the mutation. func (m *UserLoginHistoryMutation) OwnerID() (id uuid.UUID, exists bool) { if m.owner != nil { return *m.owner, true } return } // OwnerIDs returns the "owner" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *UserLoginHistoryMutation) OwnerIDs() (ids []uuid.UUID) { if id := m.owner; id != nil { ids = append(ids, *id) } return } // ResetOwner resets all changes to the "owner" edge. func (m *UserLoginHistoryMutation) ResetOwner() { m.owner = nil m.clearedowner = false } // Where appends a list predicates to the UserLoginHistoryMutation builder. func (m *UserLoginHistoryMutation) Where(ps ...predicate.UserLoginHistory) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserLoginHistoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserLoginHistoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserLoginHistory, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserLoginHistoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserLoginHistoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserLoginHistory). func (m *UserLoginHistoryMutation) 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 *UserLoginHistoryMutation) Fields() []string { fields := make([]string, 0, 10) if m.user_id != nil { fields = append(fields, userloginhistory.FieldUserID) } if m.ip != nil { fields = append(fields, userloginhistory.FieldIP) } if m.country != nil { fields = append(fields, userloginhistory.FieldCountry) } if m.province != nil { fields = append(fields, userloginhistory.FieldProvince) } if m.city != nil { fields = append(fields, userloginhistory.FieldCity) } if m.isp != nil { fields = append(fields, userloginhistory.FieldIsp) } if m.asn != nil { fields = append(fields, userloginhistory.FieldAsn) } if m.client_version != nil { fields = append(fields, userloginhistory.FieldClientVersion) } if m.device != nil { fields = append(fields, userloginhistory.FieldDevice) } if m.created_at != nil { fields = append(fields, userloginhistory.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 *UserLoginHistoryMutation) Field(name string) (ent.Value, bool) { switch name { case userloginhistory.FieldUserID: return m.UserID() case userloginhistory.FieldIP: return m.IP() case userloginhistory.FieldCountry: return m.Country() case userloginhistory.FieldProvince: return m.Province() case userloginhistory.FieldCity: return m.City() case userloginhistory.FieldIsp: return m.Isp() case userloginhistory.FieldAsn: return m.Asn() case userloginhistory.FieldClientVersion: return m.ClientVersion() case userloginhistory.FieldDevice: return m.Device() case userloginhistory.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 *UserLoginHistoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case userloginhistory.FieldUserID: return m.OldUserID(ctx) case userloginhistory.FieldIP: return m.OldIP(ctx) case userloginhistory.FieldCountry: return m.OldCountry(ctx) case userloginhistory.FieldProvince: return m.OldProvince(ctx) case userloginhistory.FieldCity: return m.OldCity(ctx) case userloginhistory.FieldIsp: return m.OldIsp(ctx) case userloginhistory.FieldAsn: return m.OldAsn(ctx) case userloginhistory.FieldClientVersion: return m.OldClientVersion(ctx) case userloginhistory.FieldDevice: return m.OldDevice(ctx) case userloginhistory.FieldCreatedAt: return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown UserLoginHistory 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 *UserLoginHistoryMutation) SetField(name string, value ent.Value) error { switch name { case userloginhistory.FieldUserID: v, ok := value.(uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case userloginhistory.FieldIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIP(v) return nil case userloginhistory.FieldCountry: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCountry(v) return nil case userloginhistory.FieldProvince: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProvince(v) return nil case userloginhistory.FieldCity: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCity(v) return nil case userloginhistory.FieldIsp: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIsp(v) return nil case userloginhistory.FieldAsn: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAsn(v) return nil case userloginhistory.FieldClientVersion: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetClientVersion(v) return nil case userloginhistory.FieldDevice: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDevice(v) return nil case userloginhistory.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 UserLoginHistory field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserLoginHistoryMutation) 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 *UserLoginHistoryMutation) 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 *UserLoginHistoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown UserLoginHistory numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserLoginHistoryMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserLoginHistoryMutation) 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 *UserLoginHistoryMutation) ClearField(name string) error { return fmt.Errorf("unknown UserLoginHistory 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 *UserLoginHistoryMutation) ResetField(name string) error { switch name { case userloginhistory.FieldUserID: m.ResetUserID() return nil case userloginhistory.FieldIP: m.ResetIP() return nil case userloginhistory.FieldCountry: m.ResetCountry() return nil case userloginhistory.FieldProvince: m.ResetProvince() return nil case userloginhistory.FieldCity: m.ResetCity() return nil case userloginhistory.FieldIsp: m.ResetIsp() return nil case userloginhistory.FieldAsn: m.ResetAsn() return nil case userloginhistory.FieldClientVersion: m.ResetClientVersion() return nil case userloginhistory.FieldDevice: m.ResetDevice() return nil case userloginhistory.FieldCreatedAt: m.ResetCreatedAt() return nil } return fmt.Errorf("unknown UserLoginHistory field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserLoginHistoryMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { edges = append(edges, userloginhistory.EdgeOwner) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserLoginHistoryMutation) AddedIDs(name string) []ent.Value { switch name { case userloginhistory.EdgeOwner: if id := m.owner; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserLoginHistoryMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *UserLoginHistoryMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserLoginHistoryMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { edges = append(edges, userloginhistory.EdgeOwner) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserLoginHistoryMutation) EdgeCleared(name string) bool { switch name { case userloginhistory.EdgeOwner: return m.clearedowner } 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 *UserLoginHistoryMutation) ClearEdge(name string) error { switch name { case userloginhistory.EdgeOwner: m.ClearOwner() return nil } return fmt.Errorf("unknown UserLoginHistory 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 *UserLoginHistoryMutation) ResetEdge(name string) error { switch name { case userloginhistory.EdgeOwner: m.ResetOwner() return nil } return fmt.Errorf("unknown UserLoginHistory edge %s", name) }