// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "gitserver.in/patialtech/rano/db/ent/accesscontrol" "gitserver.in/patialtech/rano/db/ent/audit" "gitserver.in/patialtech/rano/db/ent/predicate" "gitserver.in/patialtech/rano/db/ent/role" "gitserver.in/patialtech/rano/db/ent/user" "gitserver.in/patialtech/rano/db/ent/usersession" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeAccessControl = "AccessControl" TypeAudit = "Audit" TypeRole = "Role" TypeTodo = "Todo" TypeUser = "User" TypeUserSession = "UserSession" ) // AccessControlMutation represents an operation that mutates the AccessControl nodes in the graph. type AccessControlMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time ptype *string v0 *string v1 *string v2 *string v3 *string v4 *string v5 *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*AccessControl, error) predicates []predicate.AccessControl } var _ ent.Mutation = (*AccessControlMutation)(nil) // accesscontrolOption allows management of the mutation configuration using functional options. type accesscontrolOption func(*AccessControlMutation) // newAccessControlMutation creates new mutation for the AccessControl entity. func newAccessControlMutation(c config, op Op, opts ...accesscontrolOption) *AccessControlMutation { m := &AccessControlMutation{ config: c, op: op, typ: TypeAccessControl, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAccessControlID sets the ID field of the mutation. func withAccessControlID(id int64) accesscontrolOption { return func(m *AccessControlMutation) { var ( err error once sync.Once value *AccessControl ) m.oldValue = func(ctx context.Context) (*AccessControl, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AccessControl.Get(ctx, id) } }) return value, err } m.id = &id } } // withAccessControl sets the old AccessControl of the mutation. func withAccessControl(node *AccessControl) accesscontrolOption { return func(m *AccessControlMutation) { m.oldValue = func(context.Context) (*AccessControl, 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 AccessControlMutation) 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 AccessControlMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: 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 AccessControl entities. func (m *AccessControlMutation) SetID(id int64) { 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 *AccessControlMutation) ID() (id int64, 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 *AccessControlMutation) IDs(ctx context.Context) ([]int64, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int64{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().AccessControl.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *AccessControlMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *AccessControlMutation) 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 AccessControl entity. // If the AccessControl 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 *AccessControlMutation) 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 *AccessControlMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *AccessControlMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *AccessControlMutation) 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 AccessControl entity. // If the AccessControl 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 *AccessControlMutation) 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 *AccessControlMutation) ResetUpdatedAt() { m.updated_at = nil } // SetPtype sets the "ptype" field. func (m *AccessControlMutation) SetPtype(s string) { m.ptype = &s } // Ptype returns the value of the "ptype" field in the mutation. func (m *AccessControlMutation) Ptype() (r string, exists bool) { v := m.ptype if v == nil { return } return *v, true } // OldPtype returns the old "ptype" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldPtype(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPtype is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPtype requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPtype: %w", err) } return oldValue.Ptype, nil } // ResetPtype resets all changes to the "ptype" field. func (m *AccessControlMutation) ResetPtype() { m.ptype = nil } // SetV0 sets the "v0" field. func (m *AccessControlMutation) SetV0(s string) { m.v0 = &s } // V0 returns the value of the "v0" field in the mutation. func (m *AccessControlMutation) V0() (r string, exists bool) { v := m.v0 if v == nil { return } return *v, true } // OldV0 returns the old "v0" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldV0(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldV0 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldV0 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldV0: %w", err) } return oldValue.V0, nil } // ResetV0 resets all changes to the "v0" field. func (m *AccessControlMutation) ResetV0() { m.v0 = nil } // SetV1 sets the "v1" field. func (m *AccessControlMutation) SetV1(s string) { m.v1 = &s } // V1 returns the value of the "v1" field in the mutation. func (m *AccessControlMutation) V1() (r string, exists bool) { v := m.v1 if v == nil { return } return *v, true } // OldV1 returns the old "v1" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldV1(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldV1 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldV1 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldV1: %w", err) } return oldValue.V1, nil } // ResetV1 resets all changes to the "v1" field. func (m *AccessControlMutation) ResetV1() { m.v1 = nil } // SetV2 sets the "v2" field. func (m *AccessControlMutation) SetV2(s string) { m.v2 = &s } // V2 returns the value of the "v2" field in the mutation. func (m *AccessControlMutation) V2() (r string, exists bool) { v := m.v2 if v == nil { return } return *v, true } // OldV2 returns the old "v2" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldV2(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldV2 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldV2 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldV2: %w", err) } return oldValue.V2, nil } // ResetV2 resets all changes to the "v2" field. func (m *AccessControlMutation) ResetV2() { m.v2 = nil } // SetV3 sets the "v3" field. func (m *AccessControlMutation) SetV3(s string) { m.v3 = &s } // V3 returns the value of the "v3" field in the mutation. func (m *AccessControlMutation) V3() (r string, exists bool) { v := m.v3 if v == nil { return } return *v, true } // OldV3 returns the old "v3" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldV3(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldV3 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldV3 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldV3: %w", err) } return oldValue.V3, nil } // ResetV3 resets all changes to the "v3" field. func (m *AccessControlMutation) ResetV3() { m.v3 = nil } // SetV4 sets the "v4" field. func (m *AccessControlMutation) SetV4(s string) { m.v4 = &s } // V4 returns the value of the "v4" field in the mutation. func (m *AccessControlMutation) V4() (r string, exists bool) { v := m.v4 if v == nil { return } return *v, true } // OldV4 returns the old "v4" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldV4(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldV4 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldV4 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldV4: %w", err) } return oldValue.V4, nil } // ResetV4 resets all changes to the "v4" field. func (m *AccessControlMutation) ResetV4() { m.v4 = nil } // SetV5 sets the "v5" field. func (m *AccessControlMutation) SetV5(s string) { m.v5 = &s } // V5 returns the value of the "v5" field in the mutation. func (m *AccessControlMutation) V5() (r string, exists bool) { v := m.v5 if v == nil { return } return *v, true } // OldV5 returns the old "v5" field's value of the AccessControl entity. // If the AccessControl 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 *AccessControlMutation) OldV5(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldV5 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldV5 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldV5: %w", err) } return oldValue.V5, nil } // ResetV5 resets all changes to the "v5" field. func (m *AccessControlMutation) ResetV5() { m.v5 = nil } // Where appends a list predicates to the AccessControlMutation builder. func (m *AccessControlMutation) Where(ps ...predicate.AccessControl) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AccessControlMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AccessControlMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.AccessControl, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AccessControlMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AccessControlMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (AccessControl). func (m *AccessControlMutation) 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 *AccessControlMutation) Fields() []string { fields := make([]string, 0, 9) if m.created_at != nil { fields = append(fields, accesscontrol.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, accesscontrol.FieldUpdatedAt) } if m.ptype != nil { fields = append(fields, accesscontrol.FieldPtype) } if m.v0 != nil { fields = append(fields, accesscontrol.FieldV0) } if m.v1 != nil { fields = append(fields, accesscontrol.FieldV1) } if m.v2 != nil { fields = append(fields, accesscontrol.FieldV2) } if m.v3 != nil { fields = append(fields, accesscontrol.FieldV3) } if m.v4 != nil { fields = append(fields, accesscontrol.FieldV4) } if m.v5 != nil { fields = append(fields, accesscontrol.FieldV5) } 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 *AccessControlMutation) Field(name string) (ent.Value, bool) { switch name { case accesscontrol.FieldCreatedAt: return m.CreatedAt() case accesscontrol.FieldUpdatedAt: return m.UpdatedAt() case accesscontrol.FieldPtype: return m.Ptype() case accesscontrol.FieldV0: return m.V0() case accesscontrol.FieldV1: return m.V1() case accesscontrol.FieldV2: return m.V2() case accesscontrol.FieldV3: return m.V3() case accesscontrol.FieldV4: return m.V4() case accesscontrol.FieldV5: return m.V5() } 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 *AccessControlMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case accesscontrol.FieldCreatedAt: return m.OldCreatedAt(ctx) case accesscontrol.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case accesscontrol.FieldPtype: return m.OldPtype(ctx) case accesscontrol.FieldV0: return m.OldV0(ctx) case accesscontrol.FieldV1: return m.OldV1(ctx) case accesscontrol.FieldV2: return m.OldV2(ctx) case accesscontrol.FieldV3: return m.OldV3(ctx) case accesscontrol.FieldV4: return m.OldV4(ctx) case accesscontrol.FieldV5: return m.OldV5(ctx) } return nil, fmt.Errorf("unknown AccessControl 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 *AccessControlMutation) SetField(name string, value ent.Value) error { switch name { case accesscontrol.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 accesscontrol.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case accesscontrol.FieldPtype: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPtype(v) return nil case accesscontrol.FieldV0: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetV0(v) return nil case accesscontrol.FieldV1: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetV1(v) return nil case accesscontrol.FieldV2: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetV2(v) return nil case accesscontrol.FieldV3: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetV3(v) return nil case accesscontrol.FieldV4: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetV4(v) return nil case accesscontrol.FieldV5: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetV5(v) return nil } return fmt.Errorf("unknown AccessControl field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AccessControlMutation) 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 *AccessControlMutation) 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 *AccessControlMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown AccessControl numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AccessControlMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AccessControlMutation) 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 *AccessControlMutation) ClearField(name string) error { return fmt.Errorf("unknown AccessControl 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 *AccessControlMutation) ResetField(name string) error { switch name { case accesscontrol.FieldCreatedAt: m.ResetCreatedAt() return nil case accesscontrol.FieldUpdatedAt: m.ResetUpdatedAt() return nil case accesscontrol.FieldPtype: m.ResetPtype() return nil case accesscontrol.FieldV0: m.ResetV0() return nil case accesscontrol.FieldV1: m.ResetV1() return nil case accesscontrol.FieldV2: m.ResetV2() return nil case accesscontrol.FieldV3: m.ResetV3() return nil case accesscontrol.FieldV4: m.ResetV4() return nil case accesscontrol.FieldV5: m.ResetV5() return nil } return fmt.Errorf("unknown AccessControl field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AccessControlMutation) 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 *AccessControlMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AccessControlMutation) 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 *AccessControlMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AccessControlMutation) 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 *AccessControlMutation) 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 *AccessControlMutation) ClearEdge(name string) error { return fmt.Errorf("unknown AccessControl 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 *AccessControlMutation) ResetEdge(name string) error { return fmt.Errorf("unknown AccessControl edge %s", name) } // AuditMutation represents an operation that mutates the Audit nodes in the graph. type AuditMutation struct { config op Op typ string id *int64 created_at *time.Time ent_name *string ent_id *int64 addent_id *int64 operation *audit.Operation description *string ip *string user_name *string clearedFields map[string]struct{} user *int64 cleareduser bool done bool oldValue func(context.Context) (*Audit, error) predicates []predicate.Audit } var _ ent.Mutation = (*AuditMutation)(nil) // auditOption allows management of the mutation configuration using functional options. type auditOption func(*AuditMutation) // newAuditMutation creates new mutation for the Audit entity. func newAuditMutation(c config, op Op, opts ...auditOption) *AuditMutation { m := &AuditMutation{ config: c, op: op, typ: TypeAudit, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAuditID sets the ID field of the mutation. func withAuditID(id int64) auditOption { return func(m *AuditMutation) { var ( err error once sync.Once value *Audit ) m.oldValue = func(ctx context.Context) (*Audit, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Audit.Get(ctx, id) } }) return value, err } m.id = &id } } // withAudit sets the old Audit of the mutation. func withAudit(node *Audit) auditOption { return func(m *AuditMutation) { m.oldValue = func(context.Context) (*Audit, 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 AuditMutation) 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 AuditMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: 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 Audit entities. func (m *AuditMutation) SetID(id int64) { 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 *AuditMutation) ID() (id int64, 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 *AuditMutation) IDs(ctx context.Context) ([]int64, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int64{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Audit.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *AuditMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *AuditMutation) 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 Audit entity. // If the Audit 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 *AuditMutation) 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 *AuditMutation) ResetCreatedAt() { m.created_at = nil } // SetEntName sets the "ent_name" field. func (m *AuditMutation) SetEntName(s string) { m.ent_name = &s } // EntName returns the value of the "ent_name" field in the mutation. func (m *AuditMutation) EntName() (r string, exists bool) { v := m.ent_name if v == nil { return } return *v, true } // OldEntName returns the old "ent_name" field's value of the Audit entity. // If the Audit 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 *AuditMutation) OldEntName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEntName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEntName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEntName: %w", err) } return oldValue.EntName, nil } // ResetEntName resets all changes to the "ent_name" field. func (m *AuditMutation) ResetEntName() { m.ent_name = nil } // SetEntID sets the "ent_id" field. func (m *AuditMutation) SetEntID(i int64) { m.ent_id = &i m.addent_id = nil } // EntID returns the value of the "ent_id" field in the mutation. func (m *AuditMutation) EntID() (r int64, exists bool) { v := m.ent_id if v == nil { return } return *v, true } // OldEntID returns the old "ent_id" field's value of the Audit entity. // If the Audit 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 *AuditMutation) OldEntID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEntID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEntID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEntID: %w", err) } return oldValue.EntID, nil } // AddEntID adds i to the "ent_id" field. func (m *AuditMutation) AddEntID(i int64) { if m.addent_id != nil { *m.addent_id += i } else { m.addent_id = &i } } // AddedEntID returns the value that was added to the "ent_id" field in this mutation. func (m *AuditMutation) AddedEntID() (r int64, exists bool) { v := m.addent_id if v == nil { return } return *v, true } // ResetEntID resets all changes to the "ent_id" field. func (m *AuditMutation) ResetEntID() { m.ent_id = nil m.addent_id = nil } // SetOperation sets the "operation" field. func (m *AuditMutation) SetOperation(a audit.Operation) { m.operation = &a } // Operation returns the value of the "operation" field in the mutation. func (m *AuditMutation) Operation() (r audit.Operation, exists bool) { v := m.operation if v == nil { return } return *v, true } // OldOperation returns the old "operation" field's value of the Audit entity. // If the Audit 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 *AuditMutation) OldOperation(ctx context.Context) (v audit.Operation, 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 *AuditMutation) ResetOperation() { m.operation = nil } // SetDescription sets the "description" field. func (m *AuditMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *AuditMutation) 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 Audit entity. // If the Audit 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 *AuditMutation) 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 *AuditMutation) ResetDescription() { m.description = nil } // SetIP sets the "ip" field. func (m *AuditMutation) SetIP(s string) { m.ip = &s } // IP returns the value of the "ip" field in the mutation. func (m *AuditMutation) 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 Audit entity. // If the Audit 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 *AuditMutation) 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 } // ClearIP clears the value of the "ip" field. func (m *AuditMutation) ClearIP() { m.ip = nil m.clearedFields[audit.FieldIP] = struct{}{} } // IPCleared returns if the "ip" field was cleared in this mutation. func (m *AuditMutation) IPCleared() bool { _, ok := m.clearedFields[audit.FieldIP] return ok } // ResetIP resets all changes to the "ip" field. func (m *AuditMutation) ResetIP() { m.ip = nil delete(m.clearedFields, audit.FieldIP) } // SetUserName sets the "user_name" field. func (m *AuditMutation) SetUserName(s string) { m.user_name = &s } // UserName returns the value of the "user_name" field in the mutation. func (m *AuditMutation) UserName() (r string, exists bool) { v := m.user_name if v == nil { return } return *v, true } // OldUserName returns the old "user_name" field's value of the Audit entity. // If the Audit 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 *AuditMutation) 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 } // ClearUserName clears the value of the "user_name" field. func (m *AuditMutation) ClearUserName() { m.user_name = nil m.clearedFields[audit.FieldUserName] = struct{}{} } // UserNameCleared returns if the "user_name" field was cleared in this mutation. func (m *AuditMutation) UserNameCleared() bool { _, ok := m.clearedFields[audit.FieldUserName] return ok } // ResetUserName resets all changes to the "user_name" field. func (m *AuditMutation) ResetUserName() { m.user_name = nil delete(m.clearedFields, audit.FieldUserName) } // SetUserID sets the "user" edge to the User entity by id. func (m *AuditMutation) SetUserID(id int64) { m.user = &id } // ClearUser clears the "user" edge to the User entity. func (m *AuditMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *AuditMutation) UserCleared() bool { return m.cleareduser } // UserID returns the "user" edge ID in the mutation. func (m *AuditMutation) UserID() (id int64, exists bool) { if m.user != nil { return *m.user, true } return } // 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 *AuditMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *AuditMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the AuditMutation builder. func (m *AuditMutation) Where(ps ...predicate.Audit) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AuditMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AuditMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Audit, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AuditMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AuditMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Audit). func (m *AuditMutation) 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 *AuditMutation) Fields() []string { fields := make([]string, 0, 7) if m.created_at != nil { fields = append(fields, audit.FieldCreatedAt) } if m.ent_name != nil { fields = append(fields, audit.FieldEntName) } if m.ent_id != nil { fields = append(fields, audit.FieldEntID) } if m.operation != nil { fields = append(fields, audit.FieldOperation) } if m.description != nil { fields = append(fields, audit.FieldDescription) } if m.ip != nil { fields = append(fields, audit.FieldIP) } if m.user_name != nil { fields = append(fields, audit.FieldUserName) } 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 *AuditMutation) Field(name string) (ent.Value, bool) { switch name { case audit.FieldCreatedAt: return m.CreatedAt() case audit.FieldEntName: return m.EntName() case audit.FieldEntID: return m.EntID() case audit.FieldOperation: return m.Operation() case audit.FieldDescription: return m.Description() case audit.FieldIP: return m.IP() case audit.FieldUserName: return m.UserName() } 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 *AuditMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case audit.FieldCreatedAt: return m.OldCreatedAt(ctx) case audit.FieldEntName: return m.OldEntName(ctx) case audit.FieldEntID: return m.OldEntID(ctx) case audit.FieldOperation: return m.OldOperation(ctx) case audit.FieldDescription: return m.OldDescription(ctx) case audit.FieldIP: return m.OldIP(ctx) case audit.FieldUserName: return m.OldUserName(ctx) } return nil, fmt.Errorf("unknown Audit 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 *AuditMutation) SetField(name string, value ent.Value) error { switch name { case audit.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 audit.FieldEntName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEntName(v) return nil case audit.FieldEntID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEntID(v) return nil case audit.FieldOperation: v, ok := value.(audit.Operation) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOperation(v) return nil case audit.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case audit.FieldIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIP(v) return nil case audit.FieldUserName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserName(v) return nil } return fmt.Errorf("unknown Audit field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AuditMutation) AddedFields() []string { var fields []string if m.addent_id != nil { fields = append(fields, audit.FieldEntID) } 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 *AuditMutation) AddedField(name string) (ent.Value, bool) { switch name { case audit.FieldEntID: return m.AddedEntID() } 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 *AuditMutation) AddField(name string, value ent.Value) error { switch name { case audit.FieldEntID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddEntID(v) return nil } return fmt.Errorf("unknown Audit numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AuditMutation) ClearedFields() []string { var fields []string if m.FieldCleared(audit.FieldIP) { fields = append(fields, audit.FieldIP) } if m.FieldCleared(audit.FieldUserName) { fields = append(fields, audit.FieldUserName) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AuditMutation) 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 *AuditMutation) ClearField(name string) error { switch name { case audit.FieldIP: m.ClearIP() return nil case audit.FieldUserName: m.ClearUserName() return nil } return fmt.Errorf("unknown Audit 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 *AuditMutation) ResetField(name string) error { switch name { case audit.FieldCreatedAt: m.ResetCreatedAt() return nil case audit.FieldEntName: m.ResetEntName() return nil case audit.FieldEntID: m.ResetEntID() return nil case audit.FieldOperation: m.ResetOperation() return nil case audit.FieldDescription: m.ResetDescription() return nil case audit.FieldIP: m.ResetIP() return nil case audit.FieldUserName: m.ResetUserName() return nil } return fmt.Errorf("unknown Audit field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AuditMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, audit.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AuditMutation) AddedIDs(name string) []ent.Value { switch name { case audit.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 *AuditMutation) 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 *AuditMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AuditMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, audit.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AuditMutation) EdgeCleared(name string) bool { switch name { case audit.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 *AuditMutation) ClearEdge(name string) error { switch name { case audit.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown Audit 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 *AuditMutation) ResetEdge(name string) error { switch name { case audit.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown Audit edge %s", name) } // RoleMutation represents an operation that mutates the Role nodes in the graph. type RoleMutation struct { config op Op typ string id *int64 name *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Role, error) predicates []predicate.Role } var _ ent.Mutation = (*RoleMutation)(nil) // roleOption allows management of the mutation configuration using functional options. type roleOption func(*RoleMutation) // newRoleMutation creates new mutation for the Role entity. func newRoleMutation(c config, op Op, opts ...roleOption) *RoleMutation { m := &RoleMutation{ config: c, op: op, typ: TypeRole, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withRoleID sets the ID field of the mutation. func withRoleID(id int64) roleOption { return func(m *RoleMutation) { var ( err error once sync.Once value *Role ) m.oldValue = func(ctx context.Context) (*Role, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Role.Get(ctx, id) } }) return value, err } m.id = &id } } // withRole sets the old Role of the mutation. func withRole(node *Role) roleOption { return func(m *RoleMutation) { m.oldValue = func(context.Context) (*Role, 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 RoleMutation) 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 RoleMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: 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 Role entities. func (m *RoleMutation) SetID(id int64) { 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 *RoleMutation) ID() (id int64, 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 *RoleMutation) IDs(ctx context.Context) ([]int64, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int64{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Role.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 *RoleMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 *RoleMutation) ResetName() { m.name = nil } // Where appends a list predicates to the RoleMutation builder. func (m *RoleMutation) Where(ps ...predicate.Role) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the RoleMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *RoleMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Role, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *RoleMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *RoleMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Role). func (m *RoleMutation) 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 *RoleMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, role.FieldName) } 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 *RoleMutation) Field(name string) (ent.Value, bool) { switch name { case role.FieldName: return m.Name() } 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 *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case role.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown Role 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 *RoleMutation) SetField(name string, value ent.Value) error { switch name { case role.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown Role field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *RoleMutation) 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 *RoleMutation) 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 *RoleMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Role numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *RoleMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *RoleMutation) 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 *RoleMutation) ClearField(name string) error { return fmt.Errorf("unknown Role 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 *RoleMutation) ResetField(name string) error { switch name { case role.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown Role field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *RoleMutation) 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 *RoleMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *RoleMutation) 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 *RoleMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RoleMutation) 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 *RoleMutation) 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 *RoleMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Role 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 *RoleMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Role edge %s", name) } // TodoMutation represents an operation that mutates the Todo nodes in the graph. type TodoMutation struct { config op Op typ string id *int clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Todo, error) predicates []predicate.Todo } var _ ent.Mutation = (*TodoMutation)(nil) // todoOption allows management of the mutation configuration using functional options. type todoOption func(*TodoMutation) // newTodoMutation creates new mutation for the Todo entity. func newTodoMutation(c config, op Op, opts ...todoOption) *TodoMutation { m := &TodoMutation{ config: c, op: op, typ: TypeTodo, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withTodoID sets the ID field of the mutation. func withTodoID(id int) todoOption { return func(m *TodoMutation) { var ( err error once sync.Once value *Todo ) m.oldValue = func(ctx context.Context) (*Todo, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Todo.Get(ctx, id) } }) return value, err } m.id = &id } } // withTodo sets the old Todo of the mutation. func withTodo(node *Todo) todoOption { return func(m *TodoMutation) { m.oldValue = func(context.Context) (*Todo, 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 TodoMutation) 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 TodoMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // 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 *TodoMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *TodoMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Todo.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // Where appends a list predicates to the TodoMutation builder. func (m *TodoMutation) Where(ps ...predicate.Todo) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the TodoMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *TodoMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Todo, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *TodoMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *TodoMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Todo). func (m *TodoMutation) 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 *TodoMutation) Fields() []string { fields := make([]string, 0, 0) 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 *TodoMutation) Field(name string) (ent.Value, bool) { 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 *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { return nil, fmt.Errorf("unknown Todo 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 *TodoMutation) SetField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Todo field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *TodoMutation) 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 *TodoMutation) 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 *TodoMutation) AddField(name string, value ent.Value) error { return fmt.Errorf("unknown Todo numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TodoMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *TodoMutation) 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 *TodoMutation) ClearField(name string) error { return fmt.Errorf("unknown Todo 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 *TodoMutation) ResetField(name string) error { return fmt.Errorf("unknown Todo field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *TodoMutation) 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 *TodoMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *TodoMutation) 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 *TodoMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TodoMutation) 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 *TodoMutation) 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 *TodoMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Todo 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 *TodoMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Todo edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time email *string email_verified *bool phone *string phone_verified *bool pwd_salt *string pwd_hash *string login_failed_count *uint8 addlogin_failed_count *int8 login_attempt_on *time.Time login_locked_until *time.Time first_name *string middle_name *string last_name *string status *user.Status clearedFields map[string]struct{} sessions map[int64]struct{} removedsessions map[int64]struct{} clearedsessions bool audit_logs map[int64]struct{} removedaudit_logs map[int64]struct{} clearedaudit_logs 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 int64) 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("ent: 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 int64) { 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 int64, 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) ([]int64, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int64{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) } } // 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 } // 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 } // SetEmailVerified sets the "email_verified" field. func (m *UserMutation) SetEmailVerified(b bool) { m.email_verified = &b } // EmailVerified returns the value of the "email_verified" field in the mutation. func (m *UserMutation) EmailVerified() (r bool, exists bool) { v := m.email_verified if v == nil { return } return *v, true } // OldEmailVerified returns the old "email_verified" 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) OldEmailVerified(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmailVerified is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmailVerified requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmailVerified: %w", err) } return oldValue.EmailVerified, nil } // ResetEmailVerified resets all changes to the "email_verified" field. func (m *UserMutation) ResetEmailVerified() { m.email_verified = nil } // SetPhone sets the "phone" field. func (m *UserMutation) SetPhone(s string) { m.phone = &s } // Phone returns the value of the "phone" field in the mutation. func (m *UserMutation) Phone() (r string, exists bool) { v := m.phone if v == nil { return } return *v, true } // OldPhone returns the old "phone" 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) OldPhone(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPhone is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPhone requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPhone: %w", err) } return oldValue.Phone, nil } // ResetPhone resets all changes to the "phone" field. func (m *UserMutation) ResetPhone() { m.phone = nil } // SetPhoneVerified sets the "phone_verified" field. func (m *UserMutation) SetPhoneVerified(b bool) { m.phone_verified = &b } // PhoneVerified returns the value of the "phone_verified" field in the mutation. func (m *UserMutation) PhoneVerified() (r bool, exists bool) { v := m.phone_verified if v == nil { return } return *v, true } // OldPhoneVerified returns the old "phone_verified" 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) OldPhoneVerified(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPhoneVerified is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPhoneVerified requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPhoneVerified: %w", err) } return oldValue.PhoneVerified, nil } // ResetPhoneVerified resets all changes to the "phone_verified" field. func (m *UserMutation) ResetPhoneVerified() { m.phone_verified = nil } // SetPwdSalt sets the "pwd_salt" field. func (m *UserMutation) SetPwdSalt(s string) { m.pwd_salt = &s } // PwdSalt returns the value of the "pwd_salt" field in the mutation. func (m *UserMutation) PwdSalt() (r string, exists bool) { v := m.pwd_salt if v == nil { return } return *v, true } // OldPwdSalt returns the old "pwd_salt" 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) OldPwdSalt(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPwdSalt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPwdSalt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPwdSalt: %w", err) } return oldValue.PwdSalt, nil } // ResetPwdSalt resets all changes to the "pwd_salt" field. func (m *UserMutation) ResetPwdSalt() { m.pwd_salt = nil } // SetPwdHash sets the "pwd_hash" field. func (m *UserMutation) SetPwdHash(s string) { m.pwd_hash = &s } // PwdHash returns the value of the "pwd_hash" field in the mutation. func (m *UserMutation) PwdHash() (r string, exists bool) { v := m.pwd_hash if v == nil { return } return *v, true } // OldPwdHash returns the old "pwd_hash" 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) OldPwdHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPwdHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPwdHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPwdHash: %w", err) } return oldValue.PwdHash, nil } // ResetPwdHash resets all changes to the "pwd_hash" field. func (m *UserMutation) ResetPwdHash() { m.pwd_hash = nil } // SetLoginFailedCount sets the "login_failed_count" field. func (m *UserMutation) SetLoginFailedCount(u uint8) { m.login_failed_count = &u m.addlogin_failed_count = nil } // LoginFailedCount returns the value of the "login_failed_count" field in the mutation. func (m *UserMutation) LoginFailedCount() (r uint8, exists bool) { v := m.login_failed_count if v == nil { return } return *v, true } // OldLoginFailedCount returns the old "login_failed_count" 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) OldLoginFailedCount(ctx context.Context) (v uint8, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLoginFailedCount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLoginFailedCount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLoginFailedCount: %w", err) } return oldValue.LoginFailedCount, nil } // AddLoginFailedCount adds u to the "login_failed_count" field. func (m *UserMutation) AddLoginFailedCount(u int8) { if m.addlogin_failed_count != nil { *m.addlogin_failed_count += u } else { m.addlogin_failed_count = &u } } // AddedLoginFailedCount returns the value that was added to the "login_failed_count" field in this mutation. func (m *UserMutation) AddedLoginFailedCount() (r int8, exists bool) { v := m.addlogin_failed_count if v == nil { return } return *v, true } // ClearLoginFailedCount clears the value of the "login_failed_count" field. func (m *UserMutation) ClearLoginFailedCount() { m.login_failed_count = nil m.addlogin_failed_count = nil m.clearedFields[user.FieldLoginFailedCount] = struct{}{} } // LoginFailedCountCleared returns if the "login_failed_count" field was cleared in this mutation. func (m *UserMutation) LoginFailedCountCleared() bool { _, ok := m.clearedFields[user.FieldLoginFailedCount] return ok } // ResetLoginFailedCount resets all changes to the "login_failed_count" field. func (m *UserMutation) ResetLoginFailedCount() { m.login_failed_count = nil m.addlogin_failed_count = nil delete(m.clearedFields, user.FieldLoginFailedCount) } // SetLoginAttemptOn sets the "login_attempt_on" field. func (m *UserMutation) SetLoginAttemptOn(t time.Time) { m.login_attempt_on = &t } // LoginAttemptOn returns the value of the "login_attempt_on" field in the mutation. func (m *UserMutation) LoginAttemptOn() (r time.Time, exists bool) { v := m.login_attempt_on if v == nil { return } return *v, true } // OldLoginAttemptOn returns the old "login_attempt_on" 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) OldLoginAttemptOn(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLoginAttemptOn is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLoginAttemptOn requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLoginAttemptOn: %w", err) } return oldValue.LoginAttemptOn, nil } // ClearLoginAttemptOn clears the value of the "login_attempt_on" field. func (m *UserMutation) ClearLoginAttemptOn() { m.login_attempt_on = nil m.clearedFields[user.FieldLoginAttemptOn] = struct{}{} } // LoginAttemptOnCleared returns if the "login_attempt_on" field was cleared in this mutation. func (m *UserMutation) LoginAttemptOnCleared() bool { _, ok := m.clearedFields[user.FieldLoginAttemptOn] return ok } // ResetLoginAttemptOn resets all changes to the "login_attempt_on" field. func (m *UserMutation) ResetLoginAttemptOn() { m.login_attempt_on = nil delete(m.clearedFields, user.FieldLoginAttemptOn) } // SetLoginLockedUntil sets the "login_locked_until" field. func (m *UserMutation) SetLoginLockedUntil(t time.Time) { m.login_locked_until = &t } // LoginLockedUntil returns the value of the "login_locked_until" field in the mutation. func (m *UserMutation) LoginLockedUntil() (r time.Time, exists bool) { v := m.login_locked_until if v == nil { return } return *v, true } // OldLoginLockedUntil returns the old "login_locked_until" 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) OldLoginLockedUntil(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLoginLockedUntil is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLoginLockedUntil requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLoginLockedUntil: %w", err) } return oldValue.LoginLockedUntil, nil } // ClearLoginLockedUntil clears the value of the "login_locked_until" field. func (m *UserMutation) ClearLoginLockedUntil() { m.login_locked_until = nil m.clearedFields[user.FieldLoginLockedUntil] = struct{}{} } // LoginLockedUntilCleared returns if the "login_locked_until" field was cleared in this mutation. func (m *UserMutation) LoginLockedUntilCleared() bool { _, ok := m.clearedFields[user.FieldLoginLockedUntil] return ok } // ResetLoginLockedUntil resets all changes to the "login_locked_until" field. func (m *UserMutation) ResetLoginLockedUntil() { m.login_locked_until = nil delete(m.clearedFields, user.FieldLoginLockedUntil) } // SetFirstName sets the "first_name" field. func (m *UserMutation) SetFirstName(s string) { m.first_name = &s } // FirstName returns the value of the "first_name" field in the mutation. func (m *UserMutation) FirstName() (r string, exists bool) { v := m.first_name if v == nil { return } return *v, true } // OldFirstName returns the old "first_name" 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) OldFirstName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldFirstName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldFirstName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldFirstName: %w", err) } return oldValue.FirstName, nil } // ResetFirstName resets all changes to the "first_name" field. func (m *UserMutation) ResetFirstName() { m.first_name = nil } // SetMiddleName sets the "middle_name" field. func (m *UserMutation) SetMiddleName(s string) { m.middle_name = &s } // MiddleName returns the value of the "middle_name" field in the mutation. func (m *UserMutation) MiddleName() (r string, exists bool) { v := m.middle_name if v == nil { return } return *v, true } // OldMiddleName returns the old "middle_name" 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) OldMiddleName(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldMiddleName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldMiddleName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldMiddleName: %w", err) } return oldValue.MiddleName, nil } // ResetMiddleName resets all changes to the "middle_name" field. func (m *UserMutation) ResetMiddleName() { m.middle_name = nil } // SetLastName sets the "last_name" field. func (m *UserMutation) SetLastName(s string) { m.last_name = &s } // LastName returns the value of the "last_name" field in the mutation. func (m *UserMutation) LastName() (r string, exists bool) { v := m.last_name if v == nil { return } return *v, true } // OldLastName returns the old "last_name" 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) OldLastName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastName: %w", err) } return oldValue.LastName, nil } // ResetLastName resets all changes to the "last_name" field. func (m *UserMutation) ResetLastName() { m.last_name = nil } // SetStatus sets the "status" field. func (m *UserMutation) SetStatus(u user.Status) { m.status = &u } // Status returns the value of the "status" field in the mutation. func (m *UserMutation) Status() (r user.Status, 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 user.Status, 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 } // AddSessionIDs adds the "sessions" edge to the UserSession entity by ids. func (m *UserMutation) AddSessionIDs(ids ...int64) { if m.sessions == nil { m.sessions = make(map[int64]struct{}) } for i := range ids { m.sessions[ids[i]] = struct{}{} } } // ClearSessions clears the "sessions" edge to the UserSession entity. func (m *UserMutation) ClearSessions() { m.clearedsessions = true } // SessionsCleared reports if the "sessions" edge to the UserSession entity was cleared. func (m *UserMutation) SessionsCleared() bool { return m.clearedsessions } // RemoveSessionIDs removes the "sessions" edge to the UserSession entity by IDs. func (m *UserMutation) RemoveSessionIDs(ids ...int64) { if m.removedsessions == nil { m.removedsessions = make(map[int64]struct{}) } for i := range ids { delete(m.sessions, ids[i]) m.removedsessions[ids[i]] = struct{}{} } } // RemovedSessions returns the removed IDs of the "sessions" edge to the UserSession entity. func (m *UserMutation) RemovedSessionsIDs() (ids []int64) { for id := range m.removedsessions { ids = append(ids, id) } return } // SessionsIDs returns the "sessions" edge IDs in the mutation. func (m *UserMutation) SessionsIDs() (ids []int64) { for id := range m.sessions { ids = append(ids, id) } return } // ResetSessions resets all changes to the "sessions" edge. func (m *UserMutation) ResetSessions() { m.sessions = nil m.clearedsessions = false m.removedsessions = nil } // AddAuditLogIDs adds the "audit_logs" edge to the Audit entity by ids. func (m *UserMutation) AddAuditLogIDs(ids ...int64) { if m.audit_logs == nil { m.audit_logs = make(map[int64]struct{}) } for i := range ids { m.audit_logs[ids[i]] = struct{}{} } } // ClearAuditLogs clears the "audit_logs" edge to the Audit entity. func (m *UserMutation) ClearAuditLogs() { m.clearedaudit_logs = true } // AuditLogsCleared reports if the "audit_logs" edge to the Audit entity was cleared. func (m *UserMutation) AuditLogsCleared() bool { return m.clearedaudit_logs } // RemoveAuditLogIDs removes the "audit_logs" edge to the Audit entity by IDs. func (m *UserMutation) RemoveAuditLogIDs(ids ...int64) { if m.removedaudit_logs == nil { m.removedaudit_logs = make(map[int64]struct{}) } for i := range ids { delete(m.audit_logs, ids[i]) m.removedaudit_logs[ids[i]] = struct{}{} } } // RemovedAuditLogs returns the removed IDs of the "audit_logs" edge to the Audit entity. func (m *UserMutation) RemovedAuditLogsIDs() (ids []int64) { for id := range m.removedaudit_logs { ids = append(ids, id) } return } // AuditLogsIDs returns the "audit_logs" edge IDs in the mutation. func (m *UserMutation) AuditLogsIDs() (ids []int64) { for id := range m.audit_logs { ids = append(ids, id) } return } // ResetAuditLogs resets all changes to the "audit_logs" edge. func (m *UserMutation) ResetAuditLogs() { m.audit_logs = nil m.clearedaudit_logs = false m.removedaudit_logs = 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, 15) if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } if m.email != nil { fields = append(fields, user.FieldEmail) } if m.email_verified != nil { fields = append(fields, user.FieldEmailVerified) } if m.phone != nil { fields = append(fields, user.FieldPhone) } if m.phone_verified != nil { fields = append(fields, user.FieldPhoneVerified) } if m.pwd_salt != nil { fields = append(fields, user.FieldPwdSalt) } if m.pwd_hash != nil { fields = append(fields, user.FieldPwdHash) } if m.login_failed_count != nil { fields = append(fields, user.FieldLoginFailedCount) } if m.login_attempt_on != nil { fields = append(fields, user.FieldLoginAttemptOn) } if m.login_locked_until != nil { fields = append(fields, user.FieldLoginLockedUntil) } if m.first_name != nil { fields = append(fields, user.FieldFirstName) } if m.middle_name != nil { fields = append(fields, user.FieldMiddleName) } if m.last_name != nil { fields = append(fields, user.FieldLastName) } if m.status != nil { fields = append(fields, user.FieldStatus) } 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.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() case user.FieldEmail: return m.Email() case user.FieldEmailVerified: return m.EmailVerified() case user.FieldPhone: return m.Phone() case user.FieldPhoneVerified: return m.PhoneVerified() case user.FieldPwdSalt: return m.PwdSalt() case user.FieldPwdHash: return m.PwdHash() case user.FieldLoginFailedCount: return m.LoginFailedCount() case user.FieldLoginAttemptOn: return m.LoginAttemptOn() case user.FieldLoginLockedUntil: return m.LoginLockedUntil() case user.FieldFirstName: return m.FirstName() case user.FieldMiddleName: return m.MiddleName() case user.FieldLastName: return m.LastName() case user.FieldStatus: return m.Status() } 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.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case user.FieldEmail: return m.OldEmail(ctx) case user.FieldEmailVerified: return m.OldEmailVerified(ctx) case user.FieldPhone: return m.OldPhone(ctx) case user.FieldPhoneVerified: return m.OldPhoneVerified(ctx) case user.FieldPwdSalt: return m.OldPwdSalt(ctx) case user.FieldPwdHash: return m.OldPwdHash(ctx) case user.FieldLoginFailedCount: return m.OldLoginFailedCount(ctx) case user.FieldLoginAttemptOn: return m.OldLoginAttemptOn(ctx) case user.FieldLoginLockedUntil: return m.OldLoginLockedUntil(ctx) case user.FieldFirstName: return m.OldFirstName(ctx) case user.FieldMiddleName: return m.OldMiddleName(ctx) case user.FieldLastName: return m.OldLastName(ctx) case user.FieldStatus: return m.OldStatus(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.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 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.FieldEmailVerified: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmailVerified(v) return nil case user.FieldPhone: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhone(v) return nil case user.FieldPhoneVerified: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhoneVerified(v) return nil case user.FieldPwdSalt: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPwdSalt(v) return nil case user.FieldPwdHash: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPwdHash(v) return nil case user.FieldLoginFailedCount: v, ok := value.(uint8) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLoginFailedCount(v) return nil case user.FieldLoginAttemptOn: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLoginAttemptOn(v) return nil case user.FieldLoginLockedUntil: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLoginLockedUntil(v) return nil case user.FieldFirstName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetFirstName(v) return nil case user.FieldMiddleName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMiddleName(v) return nil case user.FieldLastName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastName(v) return nil case user.FieldStatus: v, ok := value.(user.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(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 { var fields []string if m.addlogin_failed_count != nil { fields = append(fields, user.FieldLoginFailedCount) } 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 *UserMutation) AddedField(name string) (ent.Value, bool) { switch name { case user.FieldLoginFailedCount: return m.AddedLoginFailedCount() } 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 { case user.FieldLoginFailedCount: v, ok := value.(int8) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddLoginFailedCount(v) return nil } 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 { var fields []string if m.FieldCleared(user.FieldLoginFailedCount) { fields = append(fields, user.FieldLoginFailedCount) } if m.FieldCleared(user.FieldLoginAttemptOn) { fields = append(fields, user.FieldLoginAttemptOn) } if m.FieldCleared(user.FieldLoginLockedUntil) { fields = append(fields, user.FieldLoginLockedUntil) } return fields } // 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 { switch name { case user.FieldLoginFailedCount: m.ClearLoginFailedCount() return nil case user.FieldLoginAttemptOn: m.ClearLoginAttemptOn() return nil case user.FieldLoginLockedUntil: m.ClearLoginLockedUntil() return nil } 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.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() return nil case user.FieldEmail: m.ResetEmail() return nil case user.FieldEmailVerified: m.ResetEmailVerified() return nil case user.FieldPhone: m.ResetPhone() return nil case user.FieldPhoneVerified: m.ResetPhoneVerified() return nil case user.FieldPwdSalt: m.ResetPwdSalt() return nil case user.FieldPwdHash: m.ResetPwdHash() return nil case user.FieldLoginFailedCount: m.ResetLoginFailedCount() return nil case user.FieldLoginAttemptOn: m.ResetLoginAttemptOn() return nil case user.FieldLoginLockedUntil: m.ResetLoginLockedUntil() return nil case user.FieldFirstName: m.ResetFirstName() return nil case user.FieldMiddleName: m.ResetMiddleName() return nil case user.FieldLastName: m.ResetLastName() return nil case user.FieldStatus: m.ResetStatus() 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, 2) if m.sessions != nil { edges = append(edges, user.EdgeSessions) } if m.audit_logs != nil { edges = append(edges, user.EdgeAuditLogs) } 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.EdgeSessions: ids := make([]ent.Value, 0, len(m.sessions)) for id := range m.sessions { ids = append(ids, id) } return ids case user.EdgeAuditLogs: ids := make([]ent.Value, 0, len(m.audit_logs)) for id := range m.audit_logs { 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, 2) if m.removedsessions != nil { edges = append(edges, user.EdgeSessions) } if m.removedaudit_logs != nil { edges = append(edges, user.EdgeAuditLogs) } 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.EdgeSessions: ids := make([]ent.Value, 0, len(m.removedsessions)) for id := range m.removedsessions { ids = append(ids, id) } return ids case user.EdgeAuditLogs: ids := make([]ent.Value, 0, len(m.removedaudit_logs)) for id := range m.removedaudit_logs { 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, 2) if m.clearedsessions { edges = append(edges, user.EdgeSessions) } if m.clearedaudit_logs { edges = append(edges, user.EdgeAuditLogs) } 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.EdgeSessions: return m.clearedsessions case user.EdgeAuditLogs: return m.clearedaudit_logs } 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.EdgeSessions: m.ResetSessions() return nil case user.EdgeAuditLogs: m.ResetAuditLogs() return nil } return fmt.Errorf("unknown User edge %s", name) } // UserSessionMutation represents an operation that mutates the UserSession nodes in the graph. type UserSessionMutation struct { config op Op typ string id *int64 issued_at *time.Time expires_at *time.Time invalidated *bool user_agent *string ip *string clearedFields map[string]struct{} user *int64 cleareduser bool done bool oldValue func(context.Context) (*UserSession, error) predicates []predicate.UserSession } var _ ent.Mutation = (*UserSessionMutation)(nil) // usersessionOption allows management of the mutation configuration using functional options. type usersessionOption func(*UserSessionMutation) // newUserSessionMutation creates new mutation for the UserSession entity. func newUserSessionMutation(c config, op Op, opts ...usersessionOption) *UserSessionMutation { m := &UserSessionMutation{ config: c, op: op, typ: TypeUserSession, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserSessionID sets the ID field of the mutation. func withUserSessionID(id int64) usersessionOption { return func(m *UserSessionMutation) { var ( err error once sync.Once value *UserSession ) m.oldValue = func(ctx context.Context) (*UserSession, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserSession.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserSession sets the old UserSession of the mutation. func withUserSession(node *UserSession) usersessionOption { return func(m *UserSessionMutation) { m.oldValue = func(context.Context) (*UserSession, 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 UserSessionMutation) 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 UserSessionMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: 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 UserSession entities. func (m *UserSessionMutation) SetID(id int64) { 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 *UserSessionMutation) ID() (id int64, 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 *UserSessionMutation) IDs(ctx context.Context) ([]int64, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int64{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().UserSession.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetIssuedAt sets the "issued_at" field. func (m *UserSessionMutation) SetIssuedAt(t time.Time) { m.issued_at = &t } // IssuedAt returns the value of the "issued_at" field in the mutation. func (m *UserSessionMutation) IssuedAt() (r time.Time, exists bool) { v := m.issued_at if v == nil { return } return *v, true } // OldIssuedAt returns the old "issued_at" field's value of the UserSession entity. // If the UserSession 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 *UserSessionMutation) OldIssuedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIssuedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIssuedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIssuedAt: %w", err) } return oldValue.IssuedAt, nil } // ResetIssuedAt resets all changes to the "issued_at" field. func (m *UserSessionMutation) ResetIssuedAt() { m.issued_at = nil } // SetExpiresAt sets the "expires_at" field. func (m *UserSessionMutation) SetExpiresAt(t time.Time) { m.expires_at = &t } // ExpiresAt returns the value of the "expires_at" field in the mutation. func (m *UserSessionMutation) ExpiresAt() (r time.Time, exists bool) { v := m.expires_at if v == nil { return } return *v, true } // OldExpiresAt returns the old "expires_at" field's value of the UserSession entity. // If the UserSession 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 *UserSessionMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldExpiresAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err) } return oldValue.ExpiresAt, nil } // ResetExpiresAt resets all changes to the "expires_at" field. func (m *UserSessionMutation) ResetExpiresAt() { m.expires_at = nil } // SetInvalidated sets the "invalidated" field. func (m *UserSessionMutation) SetInvalidated(b bool) { m.invalidated = &b } // Invalidated returns the value of the "invalidated" field in the mutation. func (m *UserSessionMutation) Invalidated() (r bool, exists bool) { v := m.invalidated if v == nil { return } return *v, true } // OldInvalidated returns the old "invalidated" field's value of the UserSession entity. // If the UserSession 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 *UserSessionMutation) OldInvalidated(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldInvalidated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldInvalidated requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldInvalidated: %w", err) } return oldValue.Invalidated, nil } // ClearInvalidated clears the value of the "invalidated" field. func (m *UserSessionMutation) ClearInvalidated() { m.invalidated = nil m.clearedFields[usersession.FieldInvalidated] = struct{}{} } // InvalidatedCleared returns if the "invalidated" field was cleared in this mutation. func (m *UserSessionMutation) InvalidatedCleared() bool { _, ok := m.clearedFields[usersession.FieldInvalidated] return ok } // ResetInvalidated resets all changes to the "invalidated" field. func (m *UserSessionMutation) ResetInvalidated() { m.invalidated = nil delete(m.clearedFields, usersession.FieldInvalidated) } // SetUserAgent sets the "user_agent" field. func (m *UserSessionMutation) SetUserAgent(s string) { m.user_agent = &s } // UserAgent returns the value of the "user_agent" field in the mutation. func (m *UserSessionMutation) UserAgent() (r string, exists bool) { v := m.user_agent if v == nil { return } return *v, true } // OldUserAgent returns the old "user_agent" field's value of the UserSession entity. // If the UserSession 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 *UserSessionMutation) OldUserAgent(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserAgent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserAgent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserAgent: %w", err) } return oldValue.UserAgent, nil } // ResetUserAgent resets all changes to the "user_agent" field. func (m *UserSessionMutation) ResetUserAgent() { m.user_agent = nil } // SetIP sets the "ip" field. func (m *UserSessionMutation) SetIP(s string) { m.ip = &s } // IP returns the value of the "ip" field in the mutation. func (m *UserSessionMutation) 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 UserSession entity. // If the UserSession 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 *UserSessionMutation) 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 *UserSessionMutation) ResetIP() { m.ip = nil } // SetUserID sets the "user" edge to the User entity by id. func (m *UserSessionMutation) SetUserID(id int64) { m.user = &id } // ClearUser clears the "user" edge to the User entity. func (m *UserSessionMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *UserSessionMutation) UserCleared() bool { return m.cleareduser } // UserID returns the "user" edge ID in the mutation. func (m *UserSessionMutation) UserID() (id int64, exists bool) { if m.user != nil { return *m.user, true } return } // 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 *UserSessionMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *UserSessionMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the UserSessionMutation builder. func (m *UserSessionMutation) Where(ps ...predicate.UserSession) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserSessionMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserSessionMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserSession, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserSessionMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserSessionMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserSession). func (m *UserSessionMutation) 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 *UserSessionMutation) Fields() []string { fields := make([]string, 0, 5) if m.issued_at != nil { fields = append(fields, usersession.FieldIssuedAt) } if m.expires_at != nil { fields = append(fields, usersession.FieldExpiresAt) } if m.invalidated != nil { fields = append(fields, usersession.FieldInvalidated) } if m.user_agent != nil { fields = append(fields, usersession.FieldUserAgent) } if m.ip != nil { fields = append(fields, usersession.FieldIP) } 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 *UserSessionMutation) Field(name string) (ent.Value, bool) { switch name { case usersession.FieldIssuedAt: return m.IssuedAt() case usersession.FieldExpiresAt: return m.ExpiresAt() case usersession.FieldInvalidated: return m.Invalidated() case usersession.FieldUserAgent: return m.UserAgent() case usersession.FieldIP: return m.IP() } 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 *UserSessionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case usersession.FieldIssuedAt: return m.OldIssuedAt(ctx) case usersession.FieldExpiresAt: return m.OldExpiresAt(ctx) case usersession.FieldInvalidated: return m.OldInvalidated(ctx) case usersession.FieldUserAgent: return m.OldUserAgent(ctx) case usersession.FieldIP: return m.OldIP(ctx) } return nil, fmt.Errorf("unknown UserSession 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 *UserSessionMutation) SetField(name string, value ent.Value) error { switch name { case usersession.FieldIssuedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIssuedAt(v) return nil case usersession.FieldExpiresAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetExpiresAt(v) return nil case usersession.FieldInvalidated: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetInvalidated(v) return nil case usersession.FieldUserAgent: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserAgent(v) return nil case usersession.FieldIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIP(v) return nil } return fmt.Errorf("unknown UserSession field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserSessionMutation) 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 *UserSessionMutation) 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 *UserSessionMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown UserSession numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserSessionMutation) ClearedFields() []string { var fields []string if m.FieldCleared(usersession.FieldInvalidated) { fields = append(fields, usersession.FieldInvalidated) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserSessionMutation) 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 *UserSessionMutation) ClearField(name string) error { switch name { case usersession.FieldInvalidated: m.ClearInvalidated() return nil } return fmt.Errorf("unknown UserSession 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 *UserSessionMutation) ResetField(name string) error { switch name { case usersession.FieldIssuedAt: m.ResetIssuedAt() return nil case usersession.FieldExpiresAt: m.ResetExpiresAt() return nil case usersession.FieldInvalidated: m.ResetInvalidated() return nil case usersession.FieldUserAgent: m.ResetUserAgent() return nil case usersession.FieldIP: m.ResetIP() return nil } return fmt.Errorf("unknown UserSession field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserSessionMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, usersession.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserSessionMutation) AddedIDs(name string) []ent.Value { switch name { case usersession.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 *UserSessionMutation) 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 *UserSessionMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserSessionMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, usersession.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserSessionMutation) EdgeCleared(name string) bool { switch name { case usersession.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 *UserSessionMutation) ClearEdge(name string) error { switch name { case usersession.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown UserSession 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 *UserSessionMutation) ResetEdge(name string) error { switch name { case usersession.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown UserSession edge %s", name) }