// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/department" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionarydetail" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/district" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/loginrecord" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/oauthprovider" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/role" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/token" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/user" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usermeta" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usersocial" "git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeDepartment = "Department" TypeDictionary = "Dictionary" TypeDictionaryDetail = "DictionaryDetail" TypeDistrict = "District" TypeLoginRecord = "LoginRecord" TypeOauthProvider = "OauthProvider" TypeRole = "Role" TypeToken = "Token" TypeUser = "User" TypeUserMeta = "UserMeta" TypeUserSocial = "UserSocial" ) // DepartmentMutation represents an operation that mutates the Department nodes in the graph. type DepartmentMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time status *types.Status version *int64 addversion *int64 name *string remark *string clearedFields map[string]struct{} parent *int64 clearedparent bool children map[int64]struct{} removedchildren map[int64]struct{} clearedchildren bool users map[int64]struct{} removedusers map[int64]struct{} clearedusers bool leader *int64 clearedleader bool done bool oldValue func(context.Context) (*Department, error) predicates []predicate.Department } var _ ent.Mutation = (*DepartmentMutation)(nil) // departmentOption allows management of the mutation configuration using functional options. type departmentOption func(*DepartmentMutation) // newDepartmentMutation creates new mutation for the Department entity. func newDepartmentMutation(c config, op Op, opts ...departmentOption) *DepartmentMutation { m := &DepartmentMutation{ config: c, op: op, typ: TypeDepartment, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDepartmentID sets the ID field of the mutation. func withDepartmentID(id int64) departmentOption { return func(m *DepartmentMutation) { var ( err error once sync.Once value *Department ) m.oldValue = func(ctx context.Context) (*Department, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Department.Get(ctx, id) } }) return value, err } m.id = &id } } // withDepartment sets the old Department of the mutation. func withDepartment(node *Department) departmentOption { return func(m *DepartmentMutation) { m.oldValue = func(context.Context) (*Department, 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 DepartmentMutation) 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 DepartmentMutation) 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 Department entities. func (m *DepartmentMutation) 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 *DepartmentMutation) 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 *DepartmentMutation) 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().Department.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 *DepartmentMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DepartmentMutation) 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 Department entity. // If the Department 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 *DepartmentMutation) 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 *DepartmentMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DepartmentMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DepartmentMutation) 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 Department entity. // If the Department 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 *DepartmentMutation) 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 *DepartmentMutation) ResetUpdatedAt() { m.updated_at = nil } // SetStatus sets the "status" field. func (m *DepartmentMutation) SetStatus(t types.Status) { m.status = &t } // Status returns the value of the "status" field in the mutation. func (m *DepartmentMutation) Status() (r types.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Department entity. // If the Department 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 *DepartmentMutation) OldStatus(ctx context.Context) (v types.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 *DepartmentMutation) ResetStatus() { m.status = nil } // SetVersion sets the "version" field. func (m *DepartmentMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *DepartmentMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" field's value of the Department entity. // If the Department 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 *DepartmentMutation) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *DepartmentMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *DepartmentMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *DepartmentMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetName sets the "name" field. func (m *DepartmentMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *DepartmentMutation) 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 Department entity. // If the Department 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 *DepartmentMutation) 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 *DepartmentMutation) ResetName() { m.name = nil } // SetLeaderID sets the "leader_id" field. func (m *DepartmentMutation) SetLeaderID(i int64) { m.leader = &i } // LeaderID returns the value of the "leader_id" field in the mutation. func (m *DepartmentMutation) LeaderID() (r int64, exists bool) { v := m.leader if v == nil { return } return *v, true } // OldLeaderID returns the old "leader_id" field's value of the Department entity. // If the Department 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 *DepartmentMutation) OldLeaderID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLeaderID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLeaderID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLeaderID: %w", err) } return oldValue.LeaderID, nil } // ClearLeaderID clears the value of the "leader_id" field. func (m *DepartmentMutation) ClearLeaderID() { m.leader = nil m.clearedFields[department.FieldLeaderID] = struct{}{} } // LeaderIDCleared returns if the "leader_id" field was cleared in this mutation. func (m *DepartmentMutation) LeaderIDCleared() bool { _, ok := m.clearedFields[department.FieldLeaderID] return ok } // ResetLeaderID resets all changes to the "leader_id" field. func (m *DepartmentMutation) ResetLeaderID() { m.leader = nil delete(m.clearedFields, department.FieldLeaderID) } // SetRemark sets the "remark" field. func (m *DepartmentMutation) SetRemark(s string) { m.remark = &s } // Remark returns the value of the "remark" field in the mutation. func (m *DepartmentMutation) Remark() (r string, exists bool) { v := m.remark if v == nil { return } return *v, true } // OldRemark returns the old "remark" field's value of the Department entity. // If the Department 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 *DepartmentMutation) OldRemark(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRemark is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRemark requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRemark: %w", err) } return oldValue.Remark, nil } // ClearRemark clears the value of the "remark" field. func (m *DepartmentMutation) ClearRemark() { m.remark = nil m.clearedFields[department.FieldRemark] = struct{}{} } // RemarkCleared returns if the "remark" field was cleared in this mutation. func (m *DepartmentMutation) RemarkCleared() bool { _, ok := m.clearedFields[department.FieldRemark] return ok } // ResetRemark resets all changes to the "remark" field. func (m *DepartmentMutation) ResetRemark() { m.remark = nil delete(m.clearedFields, department.FieldRemark) } // SetParentID sets the "parent_id" field. func (m *DepartmentMutation) SetParentID(i int64) { m.parent = &i } // ParentID returns the value of the "parent_id" field in the mutation. func (m *DepartmentMutation) ParentID() (r int64, exists bool) { v := m.parent if v == nil { return } return *v, true } // OldParentID returns the old "parent_id" field's value of the Department entity. // If the Department 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 *DepartmentMutation) OldParentID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldParentID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldParentID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldParentID: %w", err) } return oldValue.ParentID, nil } // ClearParentID clears the value of the "parent_id" field. func (m *DepartmentMutation) ClearParentID() { m.parent = nil m.clearedFields[department.FieldParentID] = struct{}{} } // ParentIDCleared returns if the "parent_id" field was cleared in this mutation. func (m *DepartmentMutation) ParentIDCleared() bool { _, ok := m.clearedFields[department.FieldParentID] return ok } // ResetParentID resets all changes to the "parent_id" field. func (m *DepartmentMutation) ResetParentID() { m.parent = nil delete(m.clearedFields, department.FieldParentID) } // ClearParent clears the "parent" edge to the Department entity. func (m *DepartmentMutation) ClearParent() { m.clearedparent = true } // ParentCleared reports if the "parent" edge to the Department entity was cleared. func (m *DepartmentMutation) ParentCleared() bool { return m.ParentIDCleared() || m.clearedparent } // ParentIDs returns the "parent" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ParentID instead. It exists only for internal usage by the builders. func (m *DepartmentMutation) ParentIDs() (ids []int64) { if id := m.parent; id != nil { ids = append(ids, *id) } return } // ResetParent resets all changes to the "parent" edge. func (m *DepartmentMutation) ResetParent() { m.parent = nil m.clearedparent = false } // AddChildIDs adds the "children" edge to the Department entity by ids. func (m *DepartmentMutation) AddChildIDs(ids ...int64) { if m.children == nil { m.children = make(map[int64]struct{}) } for i := range ids { m.children[ids[i]] = struct{}{} } } // ClearChildren clears the "children" edge to the Department entity. func (m *DepartmentMutation) ClearChildren() { m.clearedchildren = true } // ChildrenCleared reports if the "children" edge to the Department entity was cleared. func (m *DepartmentMutation) ChildrenCleared() bool { return m.clearedchildren } // RemoveChildIDs removes the "children" edge to the Department entity by IDs. func (m *DepartmentMutation) RemoveChildIDs(ids ...int64) { if m.removedchildren == nil { m.removedchildren = make(map[int64]struct{}) } for i := range ids { delete(m.children, ids[i]) m.removedchildren[ids[i]] = struct{}{} } } // RemovedChildren returns the removed IDs of the "children" edge to the Department entity. func (m *DepartmentMutation) RemovedChildrenIDs() (ids []int64) { for id := range m.removedchildren { ids = append(ids, id) } return } // ChildrenIDs returns the "children" edge IDs in the mutation. func (m *DepartmentMutation) ChildrenIDs() (ids []int64) { for id := range m.children { ids = append(ids, id) } return } // ResetChildren resets all changes to the "children" edge. func (m *DepartmentMutation) ResetChildren() { m.children = nil m.clearedchildren = false m.removedchildren = nil } // AddUserIDs adds the "users" edge to the User entity by ids. func (m *DepartmentMutation) AddUserIDs(ids ...int64) { if m.users == nil { m.users = make(map[int64]struct{}) } for i := range ids { m.users[ids[i]] = struct{}{} } } // ClearUsers clears the "users" edge to the User entity. func (m *DepartmentMutation) ClearUsers() { m.clearedusers = true } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *DepartmentMutation) UsersCleared() bool { return m.clearedusers } // RemoveUserIDs removes the "users" edge to the User entity by IDs. func (m *DepartmentMutation) RemoveUserIDs(ids ...int64) { if m.removedusers == nil { m.removedusers = make(map[int64]struct{}) } for i := range ids { delete(m.users, ids[i]) m.removedusers[ids[i]] = struct{}{} } } // RemovedUsers returns the removed IDs of the "users" edge to the User entity. func (m *DepartmentMutation) RemovedUsersIDs() (ids []int64) { for id := range m.removedusers { ids = append(ids, id) } return } // UsersIDs returns the "users" edge IDs in the mutation. func (m *DepartmentMutation) UsersIDs() (ids []int64) { for id := range m.users { ids = append(ids, id) } return } // ResetUsers resets all changes to the "users" edge. func (m *DepartmentMutation) ResetUsers() { m.users = nil m.clearedusers = false m.removedusers = nil } // ClearLeader clears the "leader" edge to the User entity. func (m *DepartmentMutation) ClearLeader() { m.clearedleader = true } // LeaderCleared reports if the "leader" edge to the User entity was cleared. func (m *DepartmentMutation) LeaderCleared() bool { return m.LeaderIDCleared() || m.clearedleader } // LeaderIDs returns the "leader" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // LeaderID instead. It exists only for internal usage by the builders. func (m *DepartmentMutation) LeaderIDs() (ids []int64) { if id := m.leader; id != nil { ids = append(ids, *id) } return } // ResetLeader resets all changes to the "leader" edge. func (m *DepartmentMutation) ResetLeader() { m.leader = nil m.clearedleader = false } // Where appends a list predicates to the DepartmentMutation builder. func (m *DepartmentMutation) Where(ps ...predicate.Department) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DepartmentMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DepartmentMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Department, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DepartmentMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DepartmentMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Department). func (m *DepartmentMutation) 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 *DepartmentMutation) Fields() []string { fields := make([]string, 0, 8) if m.created_at != nil { fields = append(fields, department.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, department.FieldUpdatedAt) } if m.status != nil { fields = append(fields, department.FieldStatus) } if m.version != nil { fields = append(fields, department.FieldVersion) } if m.name != nil { fields = append(fields, department.FieldName) } if m.leader != nil { fields = append(fields, department.FieldLeaderID) } if m.remark != nil { fields = append(fields, department.FieldRemark) } if m.parent != nil { fields = append(fields, department.FieldParentID) } 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 *DepartmentMutation) Field(name string) (ent.Value, bool) { switch name { case department.FieldCreatedAt: return m.CreatedAt() case department.FieldUpdatedAt: return m.UpdatedAt() case department.FieldStatus: return m.Status() case department.FieldVersion: return m.Version() case department.FieldName: return m.Name() case department.FieldLeaderID: return m.LeaderID() case department.FieldRemark: return m.Remark() case department.FieldParentID: return m.ParentID() } 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 *DepartmentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case department.FieldCreatedAt: return m.OldCreatedAt(ctx) case department.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case department.FieldStatus: return m.OldStatus(ctx) case department.FieldVersion: return m.OldVersion(ctx) case department.FieldName: return m.OldName(ctx) case department.FieldLeaderID: return m.OldLeaderID(ctx) case department.FieldRemark: return m.OldRemark(ctx) case department.FieldParentID: return m.OldParentID(ctx) } return nil, fmt.Errorf("unknown Department 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 *DepartmentMutation) SetField(name string, value ent.Value) error { switch name { case department.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 department.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 department.FieldStatus: v, ok := value.(types.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case department.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case department.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case department.FieldLeaderID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLeaderID(v) return nil case department.FieldRemark: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRemark(v) return nil case department.FieldParentID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetParentID(v) return nil } return fmt.Errorf("unknown Department field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DepartmentMutation) AddedFields() []string { var fields []string if m.addversion != nil { fields = append(fields, department.FieldVersion) } 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 *DepartmentMutation) AddedField(name string) (ent.Value, bool) { switch name { case department.FieldVersion: return m.AddedVersion() } 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 *DepartmentMutation) AddField(name string, value ent.Value) error { switch name { case department.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil } return fmt.Errorf("unknown Department numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DepartmentMutation) ClearedFields() []string { var fields []string if m.FieldCleared(department.FieldLeaderID) { fields = append(fields, department.FieldLeaderID) } if m.FieldCleared(department.FieldRemark) { fields = append(fields, department.FieldRemark) } if m.FieldCleared(department.FieldParentID) { fields = append(fields, department.FieldParentID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DepartmentMutation) 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 *DepartmentMutation) ClearField(name string) error { switch name { case department.FieldLeaderID: m.ClearLeaderID() return nil case department.FieldRemark: m.ClearRemark() return nil case department.FieldParentID: m.ClearParentID() return nil } return fmt.Errorf("unknown Department 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 *DepartmentMutation) ResetField(name string) error { switch name { case department.FieldCreatedAt: m.ResetCreatedAt() return nil case department.FieldUpdatedAt: m.ResetUpdatedAt() return nil case department.FieldStatus: m.ResetStatus() return nil case department.FieldVersion: m.ResetVersion() return nil case department.FieldName: m.ResetName() return nil case department.FieldLeaderID: m.ResetLeaderID() return nil case department.FieldRemark: m.ResetRemark() return nil case department.FieldParentID: m.ResetParentID() return nil } return fmt.Errorf("unknown Department field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DepartmentMutation) AddedEdges() []string { edges := make([]string, 0, 4) if m.parent != nil { edges = append(edges, department.EdgeParent) } if m.children != nil { edges = append(edges, department.EdgeChildren) } if m.users != nil { edges = append(edges, department.EdgeUsers) } if m.leader != nil { edges = append(edges, department.EdgeLeader) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DepartmentMutation) AddedIDs(name string) []ent.Value { switch name { case department.EdgeParent: if id := m.parent; id != nil { return []ent.Value{*id} } case department.EdgeChildren: ids := make([]ent.Value, 0, len(m.children)) for id := range m.children { ids = append(ids, id) } return ids case department.EdgeUsers: ids := make([]ent.Value, 0, len(m.users)) for id := range m.users { ids = append(ids, id) } return ids case department.EdgeLeader: if id := m.leader; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DepartmentMutation) RemovedEdges() []string { edges := make([]string, 0, 4) if m.removedchildren != nil { edges = append(edges, department.EdgeChildren) } if m.removedusers != nil { edges = append(edges, department.EdgeUsers) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DepartmentMutation) RemovedIDs(name string) []ent.Value { switch name { case department.EdgeChildren: ids := make([]ent.Value, 0, len(m.removedchildren)) for id := range m.removedchildren { ids = append(ids, id) } return ids case department.EdgeUsers: ids := make([]ent.Value, 0, len(m.removedusers)) for id := range m.removedusers { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DepartmentMutation) ClearedEdges() []string { edges := make([]string, 0, 4) if m.clearedparent { edges = append(edges, department.EdgeParent) } if m.clearedchildren { edges = append(edges, department.EdgeChildren) } if m.clearedusers { edges = append(edges, department.EdgeUsers) } if m.clearedleader { edges = append(edges, department.EdgeLeader) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DepartmentMutation) EdgeCleared(name string) bool { switch name { case department.EdgeParent: return m.clearedparent case department.EdgeChildren: return m.clearedchildren case department.EdgeUsers: return m.clearedusers case department.EdgeLeader: return m.clearedleader } 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 *DepartmentMutation) ClearEdge(name string) error { switch name { case department.EdgeParent: m.ClearParent() return nil case department.EdgeLeader: m.ClearLeader() return nil } return fmt.Errorf("unknown Department 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 *DepartmentMutation) ResetEdge(name string) error { switch name { case department.EdgeParent: m.ResetParent() return nil case department.EdgeChildren: m.ResetChildren() return nil case department.EdgeUsers: m.ResetUsers() return nil case department.EdgeLeader: m.ResetLeader() return nil } return fmt.Errorf("unknown Department edge %s", name) } // DictionaryMutation represents an operation that mutates the Dictionary nodes in the graph. type DictionaryMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time status *types.Status version *int64 addversion *int64 title *string name *string description *string clearedFields map[string]struct{} details map[int64]struct{} removeddetails map[int64]struct{} cleareddetails bool done bool oldValue func(context.Context) (*Dictionary, error) predicates []predicate.Dictionary } var _ ent.Mutation = (*DictionaryMutation)(nil) // dictionaryOption allows management of the mutation configuration using functional options. type dictionaryOption func(*DictionaryMutation) // newDictionaryMutation creates new mutation for the Dictionary entity. func newDictionaryMutation(c config, op Op, opts ...dictionaryOption) *DictionaryMutation { m := &DictionaryMutation{ config: c, op: op, typ: TypeDictionary, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDictionaryID sets the ID field of the mutation. func withDictionaryID(id int64) dictionaryOption { return func(m *DictionaryMutation) { var ( err error once sync.Once value *Dictionary ) m.oldValue = func(ctx context.Context) (*Dictionary, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Dictionary.Get(ctx, id) } }) return value, err } m.id = &id } } // withDictionary sets the old Dictionary of the mutation. func withDictionary(node *Dictionary) dictionaryOption { return func(m *DictionaryMutation) { m.oldValue = func(context.Context) (*Dictionary, 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 DictionaryMutation) 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 DictionaryMutation) 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 Dictionary entities. func (m *DictionaryMutation) 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 *DictionaryMutation) 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 *DictionaryMutation) 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().Dictionary.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 *DictionaryMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DictionaryMutation) 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 Dictionary entity. // If the Dictionary 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 *DictionaryMutation) 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 *DictionaryMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DictionaryMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DictionaryMutation) 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 Dictionary entity. // If the Dictionary 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 *DictionaryMutation) 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 *DictionaryMutation) ResetUpdatedAt() { m.updated_at = nil } // SetStatus sets the "status" field. func (m *DictionaryMutation) SetStatus(t types.Status) { m.status = &t } // Status returns the value of the "status" field in the mutation. func (m *DictionaryMutation) Status() (r types.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Dictionary entity. // If the Dictionary 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 *DictionaryMutation) OldStatus(ctx context.Context) (v types.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 *DictionaryMutation) ResetStatus() { m.status = nil } // SetVersion sets the "version" field. func (m *DictionaryMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *DictionaryMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" field's value of the Dictionary entity. // If the Dictionary 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 *DictionaryMutation) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *DictionaryMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *DictionaryMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *DictionaryMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetTitle sets the "title" field. func (m *DictionaryMutation) SetTitle(s string) { m.title = &s } // Title returns the value of the "title" field in the mutation. func (m *DictionaryMutation) Title() (r string, exists bool) { v := m.title if v == nil { return } return *v, true } // OldTitle returns the old "title" field's value of the Dictionary entity. // If the Dictionary 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 *DictionaryMutation) OldTitle(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTitle is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTitle requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTitle: %w", err) } return oldValue.Title, nil } // ResetTitle resets all changes to the "title" field. func (m *DictionaryMutation) ResetTitle() { m.title = nil } // SetName sets the "name" field. func (m *DictionaryMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *DictionaryMutation) 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 Dictionary entity. // If the Dictionary 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 *DictionaryMutation) 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 *DictionaryMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *DictionaryMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *DictionaryMutation) 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 Dictionary entity. // If the Dictionary 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 *DictionaryMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ClearDescription clears the value of the "description" field. func (m *DictionaryMutation) ClearDescription() { m.description = nil m.clearedFields[dictionary.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *DictionaryMutation) DescriptionCleared() bool { _, ok := m.clearedFields[dictionary.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *DictionaryMutation) ResetDescription() { m.description = nil delete(m.clearedFields, dictionary.FieldDescription) } // AddDetailIDs adds the "details" edge to the DictionaryDetail entity by ids. func (m *DictionaryMutation) AddDetailIDs(ids ...int64) { if m.details == nil { m.details = make(map[int64]struct{}) } for i := range ids { m.details[ids[i]] = struct{}{} } } // ClearDetails clears the "details" edge to the DictionaryDetail entity. func (m *DictionaryMutation) ClearDetails() { m.cleareddetails = true } // DetailsCleared reports if the "details" edge to the DictionaryDetail entity was cleared. func (m *DictionaryMutation) DetailsCleared() bool { return m.cleareddetails } // RemoveDetailIDs removes the "details" edge to the DictionaryDetail entity by IDs. func (m *DictionaryMutation) RemoveDetailIDs(ids ...int64) { if m.removeddetails == nil { m.removeddetails = make(map[int64]struct{}) } for i := range ids { delete(m.details, ids[i]) m.removeddetails[ids[i]] = struct{}{} } } // RemovedDetails returns the removed IDs of the "details" edge to the DictionaryDetail entity. func (m *DictionaryMutation) RemovedDetailsIDs() (ids []int64) { for id := range m.removeddetails { ids = append(ids, id) } return } // DetailsIDs returns the "details" edge IDs in the mutation. func (m *DictionaryMutation) DetailsIDs() (ids []int64) { for id := range m.details { ids = append(ids, id) } return } // ResetDetails resets all changes to the "details" edge. func (m *DictionaryMutation) ResetDetails() { m.details = nil m.cleareddetails = false m.removeddetails = nil } // Where appends a list predicates to the DictionaryMutation builder. func (m *DictionaryMutation) Where(ps ...predicate.Dictionary) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DictionaryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DictionaryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Dictionary, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DictionaryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DictionaryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Dictionary). func (m *DictionaryMutation) 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 *DictionaryMutation) Fields() []string { fields := make([]string, 0, 7) if m.created_at != nil { fields = append(fields, dictionary.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, dictionary.FieldUpdatedAt) } if m.status != nil { fields = append(fields, dictionary.FieldStatus) } if m.version != nil { fields = append(fields, dictionary.FieldVersion) } if m.title != nil { fields = append(fields, dictionary.FieldTitle) } if m.name != nil { fields = append(fields, dictionary.FieldName) } if m.description != nil { fields = append(fields, dictionary.FieldDescription) } 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 *DictionaryMutation) Field(name string) (ent.Value, bool) { switch name { case dictionary.FieldCreatedAt: return m.CreatedAt() case dictionary.FieldUpdatedAt: return m.UpdatedAt() case dictionary.FieldStatus: return m.Status() case dictionary.FieldVersion: return m.Version() case dictionary.FieldTitle: return m.Title() case dictionary.FieldName: return m.Name() case dictionary.FieldDescription: return m.Description() } 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 *DictionaryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case dictionary.FieldCreatedAt: return m.OldCreatedAt(ctx) case dictionary.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case dictionary.FieldStatus: return m.OldStatus(ctx) case dictionary.FieldVersion: return m.OldVersion(ctx) case dictionary.FieldTitle: return m.OldTitle(ctx) case dictionary.FieldName: return m.OldName(ctx) case dictionary.FieldDescription: return m.OldDescription(ctx) } return nil, fmt.Errorf("unknown Dictionary 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 *DictionaryMutation) SetField(name string, value ent.Value) error { switch name { case dictionary.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 dictionary.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 dictionary.FieldStatus: v, ok := value.(types.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case dictionary.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case dictionary.FieldTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTitle(v) return nil case dictionary.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case dictionary.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil } return fmt.Errorf("unknown Dictionary field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DictionaryMutation) AddedFields() []string { var fields []string if m.addversion != nil { fields = append(fields, dictionary.FieldVersion) } 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 *DictionaryMutation) AddedField(name string) (ent.Value, bool) { switch name { case dictionary.FieldVersion: return m.AddedVersion() } 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 *DictionaryMutation) AddField(name string, value ent.Value) error { switch name { case dictionary.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil } return fmt.Errorf("unknown Dictionary numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DictionaryMutation) ClearedFields() []string { var fields []string if m.FieldCleared(dictionary.FieldDescription) { fields = append(fields, dictionary.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DictionaryMutation) 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 *DictionaryMutation) ClearField(name string) error { switch name { case dictionary.FieldDescription: m.ClearDescription() return nil } return fmt.Errorf("unknown Dictionary 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 *DictionaryMutation) ResetField(name string) error { switch name { case dictionary.FieldCreatedAt: m.ResetCreatedAt() return nil case dictionary.FieldUpdatedAt: m.ResetUpdatedAt() return nil case dictionary.FieldStatus: m.ResetStatus() return nil case dictionary.FieldVersion: m.ResetVersion() return nil case dictionary.FieldTitle: m.ResetTitle() return nil case dictionary.FieldName: m.ResetName() return nil case dictionary.FieldDescription: m.ResetDescription() return nil } return fmt.Errorf("unknown Dictionary field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DictionaryMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.details != nil { edges = append(edges, dictionary.EdgeDetails) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DictionaryMutation) AddedIDs(name string) []ent.Value { switch name { case dictionary.EdgeDetails: ids := make([]ent.Value, 0, len(m.details)) for id := range m.details { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DictionaryMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removeddetails != nil { edges = append(edges, dictionary.EdgeDetails) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DictionaryMutation) RemovedIDs(name string) []ent.Value { switch name { case dictionary.EdgeDetails: ids := make([]ent.Value, 0, len(m.removeddetails)) for id := range m.removeddetails { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DictionaryMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareddetails { edges = append(edges, dictionary.EdgeDetails) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DictionaryMutation) EdgeCleared(name string) bool { switch name { case dictionary.EdgeDetails: return m.cleareddetails } 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 *DictionaryMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Dictionary 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 *DictionaryMutation) ResetEdge(name string) error { switch name { case dictionary.EdgeDetails: m.ResetDetails() return nil } return fmt.Errorf("unknown Dictionary edge %s", name) } // DictionaryDetailMutation represents an operation that mutates the DictionaryDetail nodes in the graph. type DictionaryDetailMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time status *types.Status sort *uint32 addsort *int32 version *int64 addversion *int64 title *string key *string value *string clearedFields map[string]struct{} dictionary *int64 cleareddictionary bool done bool oldValue func(context.Context) (*DictionaryDetail, error) predicates []predicate.DictionaryDetail } var _ ent.Mutation = (*DictionaryDetailMutation)(nil) // dictionarydetailOption allows management of the mutation configuration using functional options. type dictionarydetailOption func(*DictionaryDetailMutation) // newDictionaryDetailMutation creates new mutation for the DictionaryDetail entity. func newDictionaryDetailMutation(c config, op Op, opts ...dictionarydetailOption) *DictionaryDetailMutation { m := &DictionaryDetailMutation{ config: c, op: op, typ: TypeDictionaryDetail, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDictionaryDetailID sets the ID field of the mutation. func withDictionaryDetailID(id int64) dictionarydetailOption { return func(m *DictionaryDetailMutation) { var ( err error once sync.Once value *DictionaryDetail ) m.oldValue = func(ctx context.Context) (*DictionaryDetail, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().DictionaryDetail.Get(ctx, id) } }) return value, err } m.id = &id } } // withDictionaryDetail sets the old DictionaryDetail of the mutation. func withDictionaryDetail(node *DictionaryDetail) dictionarydetailOption { return func(m *DictionaryDetailMutation) { m.oldValue = func(context.Context) (*DictionaryDetail, 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 DictionaryDetailMutation) 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 DictionaryDetailMutation) 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 DictionaryDetail entities. func (m *DictionaryDetailMutation) 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 *DictionaryDetailMutation) 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 *DictionaryDetailMutation) 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().DictionaryDetail.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 *DictionaryDetailMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DictionaryDetailMutation) 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 DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) 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 *DictionaryDetailMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DictionaryDetailMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DictionaryDetailMutation) 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 DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) 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 *DictionaryDetailMutation) ResetUpdatedAt() { m.updated_at = nil } // SetStatus sets the "status" field. func (m *DictionaryDetailMutation) SetStatus(t types.Status) { m.status = &t } // Status returns the value of the "status" field in the mutation. func (m *DictionaryDetailMutation) Status() (r types.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldStatus(ctx context.Context) (v types.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 *DictionaryDetailMutation) ResetStatus() { m.status = nil } // SetSort sets the "sort" field. func (m *DictionaryDetailMutation) SetSort(u uint32) { m.sort = &u m.addsort = nil } // Sort returns the value of the "sort" field in the mutation. func (m *DictionaryDetailMutation) Sort() (r uint32, exists bool) { v := m.sort if v == nil { return } return *v, true } // OldSort returns the old "sort" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldSort(ctx context.Context) (v uint32, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSort is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSort requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSort: %w", err) } return oldValue.Sort, nil } // AddSort adds u to the "sort" field. func (m *DictionaryDetailMutation) AddSort(u int32) { if m.addsort != nil { *m.addsort += u } else { m.addsort = &u } } // AddedSort returns the value that was added to the "sort" field in this mutation. func (m *DictionaryDetailMutation) AddedSort() (r int32, exists bool) { v := m.addsort if v == nil { return } return *v, true } // ResetSort resets all changes to the "sort" field. func (m *DictionaryDetailMutation) ResetSort() { m.sort = nil m.addsort = nil } // SetVersion sets the "version" field. func (m *DictionaryDetailMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *DictionaryDetailMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *DictionaryDetailMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *DictionaryDetailMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *DictionaryDetailMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetTitle sets the "title" field. func (m *DictionaryDetailMutation) SetTitle(s string) { m.title = &s } // Title returns the value of the "title" field in the mutation. func (m *DictionaryDetailMutation) Title() (r string, exists bool) { v := m.title if v == nil { return } return *v, true } // OldTitle returns the old "title" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldTitle(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTitle is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTitle requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTitle: %w", err) } return oldValue.Title, nil } // ResetTitle resets all changes to the "title" field. func (m *DictionaryDetailMutation) ResetTitle() { m.title = nil } // SetKey sets the "key" field. func (m *DictionaryDetailMutation) SetKey(s string) { m.key = &s } // Key returns the value of the "key" field in the mutation. func (m *DictionaryDetailMutation) Key() (r string, exists bool) { v := m.key if v == nil { return } return *v, true } // OldKey returns the old "key" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldKey requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldKey: %w", err) } return oldValue.Key, nil } // ResetKey resets all changes to the "key" field. func (m *DictionaryDetailMutation) ResetKey() { m.key = nil } // SetValue sets the "value" field. func (m *DictionaryDetailMutation) SetValue(s string) { m.value = &s } // Value returns the value of the "value" field in the mutation. func (m *DictionaryDetailMutation) Value() (r string, exists bool) { v := m.value if v == nil { return } return *v, true } // OldValue returns the old "value" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldValue requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldValue: %w", err) } return oldValue.Value, nil } // ResetValue resets all changes to the "value" field. func (m *DictionaryDetailMutation) ResetValue() { m.value = nil } // SetDictionaryID sets the "dictionary_id" field. func (m *DictionaryDetailMutation) SetDictionaryID(i int64) { m.dictionary = &i } // DictionaryID returns the value of the "dictionary_id" field in the mutation. func (m *DictionaryDetailMutation) DictionaryID() (r int64, exists bool) { v := m.dictionary if v == nil { return } return *v, true } // OldDictionaryID returns the old "dictionary_id" field's value of the DictionaryDetail entity. // If the DictionaryDetail 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 *DictionaryDetailMutation) OldDictionaryID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDictionaryID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDictionaryID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDictionaryID: %w", err) } return oldValue.DictionaryID, nil } // ResetDictionaryID resets all changes to the "dictionary_id" field. func (m *DictionaryDetailMutation) ResetDictionaryID() { m.dictionary = nil } // ClearDictionary clears the "dictionary" edge to the Dictionary entity. func (m *DictionaryDetailMutation) ClearDictionary() { m.cleareddictionary = true } // DictionaryCleared reports if the "dictionary" edge to the Dictionary entity was cleared. func (m *DictionaryDetailMutation) DictionaryCleared() bool { return m.cleareddictionary } // DictionaryIDs returns the "dictionary" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // DictionaryID instead. It exists only for internal usage by the builders. func (m *DictionaryDetailMutation) DictionaryIDs() (ids []int64) { if id := m.dictionary; id != nil { ids = append(ids, *id) } return } // ResetDictionary resets all changes to the "dictionary" edge. func (m *DictionaryDetailMutation) ResetDictionary() { m.dictionary = nil m.cleareddictionary = false } // Where appends a list predicates to the DictionaryDetailMutation builder. func (m *DictionaryDetailMutation) Where(ps ...predicate.DictionaryDetail) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DictionaryDetailMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DictionaryDetailMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.DictionaryDetail, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DictionaryDetailMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DictionaryDetailMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (DictionaryDetail). func (m *DictionaryDetailMutation) 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 *DictionaryDetailMutation) Fields() []string { fields := make([]string, 0, 9) if m.created_at != nil { fields = append(fields, dictionarydetail.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, dictionarydetail.FieldUpdatedAt) } if m.status != nil { fields = append(fields, dictionarydetail.FieldStatus) } if m.sort != nil { fields = append(fields, dictionarydetail.FieldSort) } if m.version != nil { fields = append(fields, dictionarydetail.FieldVersion) } if m.title != nil { fields = append(fields, dictionarydetail.FieldTitle) } if m.key != nil { fields = append(fields, dictionarydetail.FieldKey) } if m.value != nil { fields = append(fields, dictionarydetail.FieldValue) } if m.dictionary != nil { fields = append(fields, dictionarydetail.FieldDictionaryID) } 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 *DictionaryDetailMutation) Field(name string) (ent.Value, bool) { switch name { case dictionarydetail.FieldCreatedAt: return m.CreatedAt() case dictionarydetail.FieldUpdatedAt: return m.UpdatedAt() case dictionarydetail.FieldStatus: return m.Status() case dictionarydetail.FieldSort: return m.Sort() case dictionarydetail.FieldVersion: return m.Version() case dictionarydetail.FieldTitle: return m.Title() case dictionarydetail.FieldKey: return m.Key() case dictionarydetail.FieldValue: return m.Value() case dictionarydetail.FieldDictionaryID: return m.DictionaryID() } 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 *DictionaryDetailMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case dictionarydetail.FieldCreatedAt: return m.OldCreatedAt(ctx) case dictionarydetail.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case dictionarydetail.FieldStatus: return m.OldStatus(ctx) case dictionarydetail.FieldSort: return m.OldSort(ctx) case dictionarydetail.FieldVersion: return m.OldVersion(ctx) case dictionarydetail.FieldTitle: return m.OldTitle(ctx) case dictionarydetail.FieldKey: return m.OldKey(ctx) case dictionarydetail.FieldValue: return m.OldValue(ctx) case dictionarydetail.FieldDictionaryID: return m.OldDictionaryID(ctx) } return nil, fmt.Errorf("unknown DictionaryDetail 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 *DictionaryDetailMutation) SetField(name string, value ent.Value) error { switch name { case dictionarydetail.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 dictionarydetail.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 dictionarydetail.FieldStatus: v, ok := value.(types.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case dictionarydetail.FieldSort: v, ok := value.(uint32) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSort(v) return nil case dictionarydetail.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case dictionarydetail.FieldTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTitle(v) return nil case dictionarydetail.FieldKey: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetKey(v) return nil case dictionarydetail.FieldValue: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetValue(v) return nil case dictionarydetail.FieldDictionaryID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDictionaryID(v) return nil } return fmt.Errorf("unknown DictionaryDetail field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DictionaryDetailMutation) AddedFields() []string { var fields []string if m.addsort != nil { fields = append(fields, dictionarydetail.FieldSort) } if m.addversion != nil { fields = append(fields, dictionarydetail.FieldVersion) } 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 *DictionaryDetailMutation) AddedField(name string) (ent.Value, bool) { switch name { case dictionarydetail.FieldSort: return m.AddedSort() case dictionarydetail.FieldVersion: return m.AddedVersion() } 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 *DictionaryDetailMutation) AddField(name string, value ent.Value) error { switch name { case dictionarydetail.FieldSort: v, ok := value.(int32) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddSort(v) return nil case dictionarydetail.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil } return fmt.Errorf("unknown DictionaryDetail numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DictionaryDetailMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DictionaryDetailMutation) 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 *DictionaryDetailMutation) ClearField(name string) error { return fmt.Errorf("unknown DictionaryDetail 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 *DictionaryDetailMutation) ResetField(name string) error { switch name { case dictionarydetail.FieldCreatedAt: m.ResetCreatedAt() return nil case dictionarydetail.FieldUpdatedAt: m.ResetUpdatedAt() return nil case dictionarydetail.FieldStatus: m.ResetStatus() return nil case dictionarydetail.FieldSort: m.ResetSort() return nil case dictionarydetail.FieldVersion: m.ResetVersion() return nil case dictionarydetail.FieldTitle: m.ResetTitle() return nil case dictionarydetail.FieldKey: m.ResetKey() return nil case dictionarydetail.FieldValue: m.ResetValue() return nil case dictionarydetail.FieldDictionaryID: m.ResetDictionaryID() return nil } return fmt.Errorf("unknown DictionaryDetail field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DictionaryDetailMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.dictionary != nil { edges = append(edges, dictionarydetail.EdgeDictionary) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DictionaryDetailMutation) AddedIDs(name string) []ent.Value { switch name { case dictionarydetail.EdgeDictionary: if id := m.dictionary; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DictionaryDetailMutation) 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 *DictionaryDetailMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DictionaryDetailMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareddictionary { edges = append(edges, dictionarydetail.EdgeDictionary) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DictionaryDetailMutation) EdgeCleared(name string) bool { switch name { case dictionarydetail.EdgeDictionary: return m.cleareddictionary } 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 *DictionaryDetailMutation) ClearEdge(name string) error { switch name { case dictionarydetail.EdgeDictionary: m.ClearDictionary() return nil } return fmt.Errorf("unknown DictionaryDetail 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 *DictionaryDetailMutation) ResetEdge(name string) error { switch name { case dictionarydetail.EdgeDictionary: m.ResetDictionary() return nil } return fmt.Errorf("unknown DictionaryDetail edge %s", name) } // DistrictMutation represents an operation that mutates the District nodes in the graph. type DistrictMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time name *string short_name *string code *string province *string city *string area *string street *string level *uint32 addlevel *int32 latitude *float64 addlatitude *float64 longitude *float64 addlongitude *float64 clearedFields map[string]struct{} done bool oldValue func(context.Context) (*District, error) predicates []predicate.District } var _ ent.Mutation = (*DistrictMutation)(nil) // districtOption allows management of the mutation configuration using functional options. type districtOption func(*DistrictMutation) // newDistrictMutation creates new mutation for the District entity. func newDistrictMutation(c config, op Op, opts ...districtOption) *DistrictMutation { m := &DistrictMutation{ config: c, op: op, typ: TypeDistrict, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDistrictID sets the ID field of the mutation. func withDistrictID(id int64) districtOption { return func(m *DistrictMutation) { var ( err error once sync.Once value *District ) m.oldValue = func(ctx context.Context) (*District, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().District.Get(ctx, id) } }) return value, err } m.id = &id } } // withDistrict sets the old District of the mutation. func withDistrict(node *District) districtOption { return func(m *DistrictMutation) { m.oldValue = func(context.Context) (*District, 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 DistrictMutation) 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 DistrictMutation) 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 District entities. func (m *DistrictMutation) 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 *DistrictMutation) 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 *DistrictMutation) 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().District.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 *DistrictMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DistrictMutation) 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 District entity. // If the District 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 *DistrictMutation) 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 *DistrictMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DistrictMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DistrictMutation) 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 District entity. // If the District 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 *DistrictMutation) 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 *DistrictMutation) ResetUpdatedAt() { m.updated_at = nil } // SetName sets the "name" field. func (m *DistrictMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *DistrictMutation) 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 District entity. // If the District 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 *DistrictMutation) 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 *DistrictMutation) ResetName() { m.name = nil } // SetShortName sets the "short_name" field. func (m *DistrictMutation) SetShortName(s string) { m.short_name = &s } // ShortName returns the value of the "short_name" field in the mutation. func (m *DistrictMutation) ShortName() (r string, exists bool) { v := m.short_name if v == nil { return } return *v, true } // OldShortName returns the old "short_name" field's value of the District entity. // If the District 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 *DistrictMutation) OldShortName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldShortName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldShortName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldShortName: %w", err) } return oldValue.ShortName, nil } // ClearShortName clears the value of the "short_name" field. func (m *DistrictMutation) ClearShortName() { m.short_name = nil m.clearedFields[district.FieldShortName] = struct{}{} } // ShortNameCleared returns if the "short_name" field was cleared in this mutation. func (m *DistrictMutation) ShortNameCleared() bool { _, ok := m.clearedFields[district.FieldShortName] return ok } // ResetShortName resets all changes to the "short_name" field. func (m *DistrictMutation) ResetShortName() { m.short_name = nil delete(m.clearedFields, district.FieldShortName) } // SetCode sets the "code" field. func (m *DistrictMutation) SetCode(s string) { m.code = &s } // Code returns the value of the "code" field in the mutation. func (m *DistrictMutation) Code() (r string, exists bool) { v := m.code if v == nil { return } return *v, true } // OldCode returns the old "code" field's value of the District entity. // If the District 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 *DistrictMutation) OldCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCode: %w", err) } return oldValue.Code, nil } // ResetCode resets all changes to the "code" field. func (m *DistrictMutation) ResetCode() { m.code = nil } // SetProvince sets the "province" field. func (m *DistrictMutation) SetProvince(s string) { m.province = &s } // Province returns the value of the "province" field in the mutation. func (m *DistrictMutation) Province() (r string, exists bool) { v := m.province if v == nil { return } return *v, true } // OldProvince returns the old "province" field's value of the District entity. // If the District 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 *DistrictMutation) OldProvince(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProvince is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProvince requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProvince: %w", err) } return oldValue.Province, nil } // ResetProvince resets all changes to the "province" field. func (m *DistrictMutation) ResetProvince() { m.province = nil } // SetCity sets the "city" field. func (m *DistrictMutation) SetCity(s string) { m.city = &s } // City returns the value of the "city" field in the mutation. func (m *DistrictMutation) City() (r string, exists bool) { v := m.city if v == nil { return } return *v, true } // OldCity returns the old "city" field's value of the District entity. // If the District 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 *DistrictMutation) OldCity(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCity is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCity requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCity: %w", err) } return oldValue.City, nil } // ClearCity clears the value of the "city" field. func (m *DistrictMutation) ClearCity() { m.city = nil m.clearedFields[district.FieldCity] = struct{}{} } // CityCleared returns if the "city" field was cleared in this mutation. func (m *DistrictMutation) CityCleared() bool { _, ok := m.clearedFields[district.FieldCity] return ok } // ResetCity resets all changes to the "city" field. func (m *DistrictMutation) ResetCity() { m.city = nil delete(m.clearedFields, district.FieldCity) } // SetArea sets the "area" field. func (m *DistrictMutation) SetArea(s string) { m.area = &s } // Area returns the value of the "area" field in the mutation. func (m *DistrictMutation) Area() (r string, exists bool) { v := m.area if v == nil { return } return *v, true } // OldArea returns the old "area" field's value of the District entity. // If the District 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 *DistrictMutation) OldArea(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldArea is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldArea requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldArea: %w", err) } return oldValue.Area, nil } // ClearArea clears the value of the "area" field. func (m *DistrictMutation) ClearArea() { m.area = nil m.clearedFields[district.FieldArea] = struct{}{} } // AreaCleared returns if the "area" field was cleared in this mutation. func (m *DistrictMutation) AreaCleared() bool { _, ok := m.clearedFields[district.FieldArea] return ok } // ResetArea resets all changes to the "area" field. func (m *DistrictMutation) ResetArea() { m.area = nil delete(m.clearedFields, district.FieldArea) } // SetStreet sets the "street" field. func (m *DistrictMutation) SetStreet(s string) { m.street = &s } // Street returns the value of the "street" field in the mutation. func (m *DistrictMutation) Street() (r string, exists bool) { v := m.street if v == nil { return } return *v, true } // OldStreet returns the old "street" field's value of the District entity. // If the District 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 *DistrictMutation) OldStreet(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStreet is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStreet requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStreet: %w", err) } return oldValue.Street, nil } // ClearStreet clears the value of the "street" field. func (m *DistrictMutation) ClearStreet() { m.street = nil m.clearedFields[district.FieldStreet] = struct{}{} } // StreetCleared returns if the "street" field was cleared in this mutation. func (m *DistrictMutation) StreetCleared() bool { _, ok := m.clearedFields[district.FieldStreet] return ok } // ResetStreet resets all changes to the "street" field. func (m *DistrictMutation) ResetStreet() { m.street = nil delete(m.clearedFields, district.FieldStreet) } // SetLevel sets the "level" field. func (m *DistrictMutation) SetLevel(u uint32) { m.level = &u m.addlevel = nil } // Level returns the value of the "level" field in the mutation. func (m *DistrictMutation) Level() (r uint32, exists bool) { v := m.level if v == nil { return } return *v, true } // OldLevel returns the old "level" field's value of the District entity. // If the District 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 *DistrictMutation) OldLevel(ctx context.Context) (v uint32, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLevel is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLevel requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLevel: %w", err) } return oldValue.Level, nil } // AddLevel adds u to the "level" field. func (m *DistrictMutation) AddLevel(u int32) { if m.addlevel != nil { *m.addlevel += u } else { m.addlevel = &u } } // AddedLevel returns the value that was added to the "level" field in this mutation. func (m *DistrictMutation) AddedLevel() (r int32, exists bool) { v := m.addlevel if v == nil { return } return *v, true } // ResetLevel resets all changes to the "level" field. func (m *DistrictMutation) ResetLevel() { m.level = nil m.addlevel = nil } // SetLatitude sets the "latitude" field. func (m *DistrictMutation) SetLatitude(f float64) { m.latitude = &f m.addlatitude = nil } // Latitude returns the value of the "latitude" field in the mutation. func (m *DistrictMutation) Latitude() (r float64, exists bool) { v := m.latitude if v == nil { return } return *v, true } // OldLatitude returns the old "latitude" field's value of the District entity. // If the District 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 *DistrictMutation) OldLatitude(ctx context.Context) (v float64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLatitude is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLatitude requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLatitude: %w", err) } return oldValue.Latitude, nil } // AddLatitude adds f to the "latitude" field. func (m *DistrictMutation) AddLatitude(f float64) { if m.addlatitude != nil { *m.addlatitude += f } else { m.addlatitude = &f } } // AddedLatitude returns the value that was added to the "latitude" field in this mutation. func (m *DistrictMutation) AddedLatitude() (r float64, exists bool) { v := m.addlatitude if v == nil { return } return *v, true } // ResetLatitude resets all changes to the "latitude" field. func (m *DistrictMutation) ResetLatitude() { m.latitude = nil m.addlatitude = nil } // SetLongitude sets the "longitude" field. func (m *DistrictMutation) SetLongitude(f float64) { m.longitude = &f m.addlongitude = nil } // Longitude returns the value of the "longitude" field in the mutation. func (m *DistrictMutation) Longitude() (r float64, exists bool) { v := m.longitude if v == nil { return } return *v, true } // OldLongitude returns the old "longitude" field's value of the District entity. // If the District 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 *DistrictMutation) OldLongitude(ctx context.Context) (v float64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLongitude is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLongitude requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLongitude: %w", err) } return oldValue.Longitude, nil } // AddLongitude adds f to the "longitude" field. func (m *DistrictMutation) AddLongitude(f float64) { if m.addlongitude != nil { *m.addlongitude += f } else { m.addlongitude = &f } } // AddedLongitude returns the value that was added to the "longitude" field in this mutation. func (m *DistrictMutation) AddedLongitude() (r float64, exists bool) { v := m.addlongitude if v == nil { return } return *v, true } // ResetLongitude resets all changes to the "longitude" field. func (m *DistrictMutation) ResetLongitude() { m.longitude = nil m.addlongitude = nil } // Where appends a list predicates to the DistrictMutation builder. func (m *DistrictMutation) Where(ps ...predicate.District) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DistrictMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DistrictMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.District, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DistrictMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DistrictMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (District). func (m *DistrictMutation) 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 *DistrictMutation) Fields() []string { fields := make([]string, 0, 12) if m.created_at != nil { fields = append(fields, district.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, district.FieldUpdatedAt) } if m.name != nil { fields = append(fields, district.FieldName) } if m.short_name != nil { fields = append(fields, district.FieldShortName) } if m.code != nil { fields = append(fields, district.FieldCode) } if m.province != nil { fields = append(fields, district.FieldProvince) } if m.city != nil { fields = append(fields, district.FieldCity) } if m.area != nil { fields = append(fields, district.FieldArea) } if m.street != nil { fields = append(fields, district.FieldStreet) } if m.level != nil { fields = append(fields, district.FieldLevel) } if m.latitude != nil { fields = append(fields, district.FieldLatitude) } if m.longitude != nil { fields = append(fields, district.FieldLongitude) } 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 *DistrictMutation) Field(name string) (ent.Value, bool) { switch name { case district.FieldCreatedAt: return m.CreatedAt() case district.FieldUpdatedAt: return m.UpdatedAt() case district.FieldName: return m.Name() case district.FieldShortName: return m.ShortName() case district.FieldCode: return m.Code() case district.FieldProvince: return m.Province() case district.FieldCity: return m.City() case district.FieldArea: return m.Area() case district.FieldStreet: return m.Street() case district.FieldLevel: return m.Level() case district.FieldLatitude: return m.Latitude() case district.FieldLongitude: return m.Longitude() } 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 *DistrictMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case district.FieldCreatedAt: return m.OldCreatedAt(ctx) case district.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case district.FieldName: return m.OldName(ctx) case district.FieldShortName: return m.OldShortName(ctx) case district.FieldCode: return m.OldCode(ctx) case district.FieldProvince: return m.OldProvince(ctx) case district.FieldCity: return m.OldCity(ctx) case district.FieldArea: return m.OldArea(ctx) case district.FieldStreet: return m.OldStreet(ctx) case district.FieldLevel: return m.OldLevel(ctx) case district.FieldLatitude: return m.OldLatitude(ctx) case district.FieldLongitude: return m.OldLongitude(ctx) } return nil, fmt.Errorf("unknown District 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 *DistrictMutation) SetField(name string, value ent.Value) error { switch name { case district.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 district.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 district.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case district.FieldShortName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetShortName(v) return nil case district.FieldCode: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCode(v) return nil case district.FieldProvince: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProvince(v) return nil case district.FieldCity: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCity(v) return nil case district.FieldArea: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetArea(v) return nil case district.FieldStreet: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStreet(v) return nil case district.FieldLevel: v, ok := value.(uint32) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLevel(v) return nil case district.FieldLatitude: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLatitude(v) return nil case district.FieldLongitude: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLongitude(v) return nil } return fmt.Errorf("unknown District field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DistrictMutation) AddedFields() []string { var fields []string if m.addlevel != nil { fields = append(fields, district.FieldLevel) } if m.addlatitude != nil { fields = append(fields, district.FieldLatitude) } if m.addlongitude != nil { fields = append(fields, district.FieldLongitude) } 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 *DistrictMutation) AddedField(name string) (ent.Value, bool) { switch name { case district.FieldLevel: return m.AddedLevel() case district.FieldLatitude: return m.AddedLatitude() case district.FieldLongitude: return m.AddedLongitude() } 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 *DistrictMutation) AddField(name string, value ent.Value) error { switch name { case district.FieldLevel: v, ok := value.(int32) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddLevel(v) return nil case district.FieldLatitude: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddLatitude(v) return nil case district.FieldLongitude: v, ok := value.(float64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddLongitude(v) return nil } return fmt.Errorf("unknown District numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DistrictMutation) ClearedFields() []string { var fields []string if m.FieldCleared(district.FieldShortName) { fields = append(fields, district.FieldShortName) } if m.FieldCleared(district.FieldCity) { fields = append(fields, district.FieldCity) } if m.FieldCleared(district.FieldArea) { fields = append(fields, district.FieldArea) } if m.FieldCleared(district.FieldStreet) { fields = append(fields, district.FieldStreet) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DistrictMutation) 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 *DistrictMutation) ClearField(name string) error { switch name { case district.FieldShortName: m.ClearShortName() return nil case district.FieldCity: m.ClearCity() return nil case district.FieldArea: m.ClearArea() return nil case district.FieldStreet: m.ClearStreet() return nil } return fmt.Errorf("unknown District 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 *DistrictMutation) ResetField(name string) error { switch name { case district.FieldCreatedAt: m.ResetCreatedAt() return nil case district.FieldUpdatedAt: m.ResetUpdatedAt() return nil case district.FieldName: m.ResetName() return nil case district.FieldShortName: m.ResetShortName() return nil case district.FieldCode: m.ResetCode() return nil case district.FieldProvince: m.ResetProvince() return nil case district.FieldCity: m.ResetCity() return nil case district.FieldArea: m.ResetArea() return nil case district.FieldStreet: m.ResetStreet() return nil case district.FieldLevel: m.ResetLevel() return nil case district.FieldLatitude: m.ResetLatitude() return nil case district.FieldLongitude: m.ResetLongitude() return nil } return fmt.Errorf("unknown District field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DistrictMutation) 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 *DistrictMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DistrictMutation) 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 *DistrictMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DistrictMutation) 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 *DistrictMutation) 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 *DistrictMutation) ClearEdge(name string) error { return fmt.Errorf("unknown District 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 *DistrictMutation) ResetEdge(name string) error { return fmt.Errorf("unknown District edge %s", name) } // LoginRecordMutation represents an operation that mutates the LoginRecord nodes in the graph. type LoginRecordMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time version *int64 addversion *int64 last_login_at *time.Time last_login_ipv4 *string last_login_device *string last_login_UA *string login_count *uint64 addlogin_count *int64 clearedFields map[string]struct{} user *int64 cleareduser bool done bool oldValue func(context.Context) (*LoginRecord, error) predicates []predicate.LoginRecord } var _ ent.Mutation = (*LoginRecordMutation)(nil) // loginrecordOption allows management of the mutation configuration using functional options. type loginrecordOption func(*LoginRecordMutation) // newLoginRecordMutation creates new mutation for the LoginRecord entity. func newLoginRecordMutation(c config, op Op, opts ...loginrecordOption) *LoginRecordMutation { m := &LoginRecordMutation{ config: c, op: op, typ: TypeLoginRecord, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withLoginRecordID sets the ID field of the mutation. func withLoginRecordID(id int64) loginrecordOption { return func(m *LoginRecordMutation) { var ( err error once sync.Once value *LoginRecord ) m.oldValue = func(ctx context.Context) (*LoginRecord, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().LoginRecord.Get(ctx, id) } }) return value, err } m.id = &id } } // withLoginRecord sets the old LoginRecord of the mutation. func withLoginRecord(node *LoginRecord) loginrecordOption { return func(m *LoginRecordMutation) { m.oldValue = func(context.Context) (*LoginRecord, 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 LoginRecordMutation) 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 LoginRecordMutation) 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 LoginRecord entities. func (m *LoginRecordMutation) 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 *LoginRecordMutation) 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 *LoginRecordMutation) 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().LoginRecord.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 *LoginRecordMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *LoginRecordMutation) 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 LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) 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 *LoginRecordMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *LoginRecordMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *LoginRecordMutation) 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 LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) 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 *LoginRecordMutation) ResetUpdatedAt() { m.updated_at = nil } // SetVersion sets the "version" field. func (m *LoginRecordMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *LoginRecordMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *LoginRecordMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *LoginRecordMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *LoginRecordMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetUserID sets the "user_id" field. func (m *LoginRecordMutation) SetUserID(i int64) { m.user = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *LoginRecordMutation) UserID() (r int64, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *LoginRecordMutation) ResetUserID() { m.user = nil } // SetLastLoginAt sets the "last_login_at" field. func (m *LoginRecordMutation) SetLastLoginAt(t time.Time) { m.last_login_at = &t } // LastLoginAt returns the value of the "last_login_at" field in the mutation. func (m *LoginRecordMutation) LastLoginAt() (r time.Time, exists bool) { v := m.last_login_at if v == nil { return } return *v, true } // OldLastLoginAt returns the old "last_login_at" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldLastLoginAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastLoginAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastLoginAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastLoginAt: %w", err) } return oldValue.LastLoginAt, nil } // ClearLastLoginAt clears the value of the "last_login_at" field. func (m *LoginRecordMutation) ClearLastLoginAt() { m.last_login_at = nil m.clearedFields[loginrecord.FieldLastLoginAt] = struct{}{} } // LastLoginAtCleared returns if the "last_login_at" field was cleared in this mutation. func (m *LoginRecordMutation) LastLoginAtCleared() bool { _, ok := m.clearedFields[loginrecord.FieldLastLoginAt] return ok } // ResetLastLoginAt resets all changes to the "last_login_at" field. func (m *LoginRecordMutation) ResetLastLoginAt() { m.last_login_at = nil delete(m.clearedFields, loginrecord.FieldLastLoginAt) } // SetLastLoginIpv4 sets the "last_login_ipv4" field. func (m *LoginRecordMutation) SetLastLoginIpv4(s string) { m.last_login_ipv4 = &s } // LastLoginIpv4 returns the value of the "last_login_ipv4" field in the mutation. func (m *LoginRecordMutation) LastLoginIpv4() (r string, exists bool) { v := m.last_login_ipv4 if v == nil { return } return *v, true } // OldLastLoginIpv4 returns the old "last_login_ipv4" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldLastLoginIpv4(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastLoginIpv4 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastLoginIpv4 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastLoginIpv4: %w", err) } return oldValue.LastLoginIpv4, nil } // ClearLastLoginIpv4 clears the value of the "last_login_ipv4" field. func (m *LoginRecordMutation) ClearLastLoginIpv4() { m.last_login_ipv4 = nil m.clearedFields[loginrecord.FieldLastLoginIpv4] = struct{}{} } // LastLoginIpv4Cleared returns if the "last_login_ipv4" field was cleared in this mutation. func (m *LoginRecordMutation) LastLoginIpv4Cleared() bool { _, ok := m.clearedFields[loginrecord.FieldLastLoginIpv4] return ok } // ResetLastLoginIpv4 resets all changes to the "last_login_ipv4" field. func (m *LoginRecordMutation) ResetLastLoginIpv4() { m.last_login_ipv4 = nil delete(m.clearedFields, loginrecord.FieldLastLoginIpv4) } // SetLastLoginDevice sets the "last_login_device" field. func (m *LoginRecordMutation) SetLastLoginDevice(s string) { m.last_login_device = &s } // LastLoginDevice returns the value of the "last_login_device" field in the mutation. func (m *LoginRecordMutation) LastLoginDevice() (r string, exists bool) { v := m.last_login_device if v == nil { return } return *v, true } // OldLastLoginDevice returns the old "last_login_device" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldLastLoginDevice(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastLoginDevice is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastLoginDevice requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastLoginDevice: %w", err) } return oldValue.LastLoginDevice, nil } // ClearLastLoginDevice clears the value of the "last_login_device" field. func (m *LoginRecordMutation) ClearLastLoginDevice() { m.last_login_device = nil m.clearedFields[loginrecord.FieldLastLoginDevice] = struct{}{} } // LastLoginDeviceCleared returns if the "last_login_device" field was cleared in this mutation. func (m *LoginRecordMutation) LastLoginDeviceCleared() bool { _, ok := m.clearedFields[loginrecord.FieldLastLoginDevice] return ok } // ResetLastLoginDevice resets all changes to the "last_login_device" field. func (m *LoginRecordMutation) ResetLastLoginDevice() { m.last_login_device = nil delete(m.clearedFields, loginrecord.FieldLastLoginDevice) } // SetLastLoginUA sets the "last_login_UA" field. func (m *LoginRecordMutation) SetLastLoginUA(s string) { m.last_login_UA = &s } // LastLoginUA returns the value of the "last_login_UA" field in the mutation. func (m *LoginRecordMutation) LastLoginUA() (r string, exists bool) { v := m.last_login_UA if v == nil { return } return *v, true } // OldLastLoginUA returns the old "last_login_UA" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldLastLoginUA(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastLoginUA is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastLoginUA requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastLoginUA: %w", err) } return oldValue.LastLoginUA, nil } // ClearLastLoginUA clears the value of the "last_login_UA" field. func (m *LoginRecordMutation) ClearLastLoginUA() { m.last_login_UA = nil m.clearedFields[loginrecord.FieldLastLoginUA] = struct{}{} } // LastLoginUACleared returns if the "last_login_UA" field was cleared in this mutation. func (m *LoginRecordMutation) LastLoginUACleared() bool { _, ok := m.clearedFields[loginrecord.FieldLastLoginUA] return ok } // ResetLastLoginUA resets all changes to the "last_login_UA" field. func (m *LoginRecordMutation) ResetLastLoginUA() { m.last_login_UA = nil delete(m.clearedFields, loginrecord.FieldLastLoginUA) } // SetLoginCount sets the "login_count" field. func (m *LoginRecordMutation) SetLoginCount(u uint64) { m.login_count = &u m.addlogin_count = nil } // LoginCount returns the value of the "login_count" field in the mutation. func (m *LoginRecordMutation) LoginCount() (r uint64, exists bool) { v := m.login_count if v == nil { return } return *v, true } // OldLoginCount returns the old "login_count" field's value of the LoginRecord entity. // If the LoginRecord 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 *LoginRecordMutation) OldLoginCount(ctx context.Context) (v uint64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLoginCount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLoginCount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLoginCount: %w", err) } return oldValue.LoginCount, nil } // AddLoginCount adds u to the "login_count" field. func (m *LoginRecordMutation) AddLoginCount(u int64) { if m.addlogin_count != nil { *m.addlogin_count += u } else { m.addlogin_count = &u } } // AddedLoginCount returns the value that was added to the "login_count" field in this mutation. func (m *LoginRecordMutation) AddedLoginCount() (r int64, exists bool) { v := m.addlogin_count if v == nil { return } return *v, true } // ResetLoginCount resets all changes to the "login_count" field. func (m *LoginRecordMutation) ResetLoginCount() { m.login_count = nil m.addlogin_count = nil } // ClearUser clears the "user" edge to the User entity. func (m *LoginRecordMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *LoginRecordMutation) UserCleared() bool { return m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *LoginRecordMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *LoginRecordMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the LoginRecordMutation builder. func (m *LoginRecordMutation) Where(ps ...predicate.LoginRecord) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the LoginRecordMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *LoginRecordMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.LoginRecord, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *LoginRecordMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *LoginRecordMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (LoginRecord). func (m *LoginRecordMutation) 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 *LoginRecordMutation) Fields() []string { fields := make([]string, 0, 9) if m.created_at != nil { fields = append(fields, loginrecord.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, loginrecord.FieldUpdatedAt) } if m.version != nil { fields = append(fields, loginrecord.FieldVersion) } if m.user != nil { fields = append(fields, loginrecord.FieldUserID) } if m.last_login_at != nil { fields = append(fields, loginrecord.FieldLastLoginAt) } if m.last_login_ipv4 != nil { fields = append(fields, loginrecord.FieldLastLoginIpv4) } if m.last_login_device != nil { fields = append(fields, loginrecord.FieldLastLoginDevice) } if m.last_login_UA != nil { fields = append(fields, loginrecord.FieldLastLoginUA) } if m.login_count != nil { fields = append(fields, loginrecord.FieldLoginCount) } 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 *LoginRecordMutation) Field(name string) (ent.Value, bool) { switch name { case loginrecord.FieldCreatedAt: return m.CreatedAt() case loginrecord.FieldUpdatedAt: return m.UpdatedAt() case loginrecord.FieldVersion: return m.Version() case loginrecord.FieldUserID: return m.UserID() case loginrecord.FieldLastLoginAt: return m.LastLoginAt() case loginrecord.FieldLastLoginIpv4: return m.LastLoginIpv4() case loginrecord.FieldLastLoginDevice: return m.LastLoginDevice() case loginrecord.FieldLastLoginUA: return m.LastLoginUA() case loginrecord.FieldLoginCount: return m.LoginCount() } 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 *LoginRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case loginrecord.FieldCreatedAt: return m.OldCreatedAt(ctx) case loginrecord.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case loginrecord.FieldVersion: return m.OldVersion(ctx) case loginrecord.FieldUserID: return m.OldUserID(ctx) case loginrecord.FieldLastLoginAt: return m.OldLastLoginAt(ctx) case loginrecord.FieldLastLoginIpv4: return m.OldLastLoginIpv4(ctx) case loginrecord.FieldLastLoginDevice: return m.OldLastLoginDevice(ctx) case loginrecord.FieldLastLoginUA: return m.OldLastLoginUA(ctx) case loginrecord.FieldLoginCount: return m.OldLoginCount(ctx) } return nil, fmt.Errorf("unknown LoginRecord 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 *LoginRecordMutation) SetField(name string, value ent.Value) error { switch name { case loginrecord.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 loginrecord.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 loginrecord.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case loginrecord.FieldUserID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case loginrecord.FieldLastLoginAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastLoginAt(v) return nil case loginrecord.FieldLastLoginIpv4: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastLoginIpv4(v) return nil case loginrecord.FieldLastLoginDevice: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastLoginDevice(v) return nil case loginrecord.FieldLastLoginUA: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastLoginUA(v) return nil case loginrecord.FieldLoginCount: v, ok := value.(uint64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLoginCount(v) return nil } return fmt.Errorf("unknown LoginRecord field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *LoginRecordMutation) AddedFields() []string { var fields []string if m.addversion != nil { fields = append(fields, loginrecord.FieldVersion) } if m.addlogin_count != nil { fields = append(fields, loginrecord.FieldLoginCount) } 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 *LoginRecordMutation) AddedField(name string) (ent.Value, bool) { switch name { case loginrecord.FieldVersion: return m.AddedVersion() case loginrecord.FieldLoginCount: return m.AddedLoginCount() } 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 *LoginRecordMutation) AddField(name string, value ent.Value) error { switch name { case loginrecord.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil case loginrecord.FieldLoginCount: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddLoginCount(v) return nil } return fmt.Errorf("unknown LoginRecord numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *LoginRecordMutation) ClearedFields() []string { var fields []string if m.FieldCleared(loginrecord.FieldLastLoginAt) { fields = append(fields, loginrecord.FieldLastLoginAt) } if m.FieldCleared(loginrecord.FieldLastLoginIpv4) { fields = append(fields, loginrecord.FieldLastLoginIpv4) } if m.FieldCleared(loginrecord.FieldLastLoginDevice) { fields = append(fields, loginrecord.FieldLastLoginDevice) } if m.FieldCleared(loginrecord.FieldLastLoginUA) { fields = append(fields, loginrecord.FieldLastLoginUA) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *LoginRecordMutation) 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 *LoginRecordMutation) ClearField(name string) error { switch name { case loginrecord.FieldLastLoginAt: m.ClearLastLoginAt() return nil case loginrecord.FieldLastLoginIpv4: m.ClearLastLoginIpv4() return nil case loginrecord.FieldLastLoginDevice: m.ClearLastLoginDevice() return nil case loginrecord.FieldLastLoginUA: m.ClearLastLoginUA() return nil } return fmt.Errorf("unknown LoginRecord 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 *LoginRecordMutation) ResetField(name string) error { switch name { case loginrecord.FieldCreatedAt: m.ResetCreatedAt() return nil case loginrecord.FieldUpdatedAt: m.ResetUpdatedAt() return nil case loginrecord.FieldVersion: m.ResetVersion() return nil case loginrecord.FieldUserID: m.ResetUserID() return nil case loginrecord.FieldLastLoginAt: m.ResetLastLoginAt() return nil case loginrecord.FieldLastLoginIpv4: m.ResetLastLoginIpv4() return nil case loginrecord.FieldLastLoginDevice: m.ResetLastLoginDevice() return nil case loginrecord.FieldLastLoginUA: m.ResetLastLoginUA() return nil case loginrecord.FieldLoginCount: m.ResetLoginCount() return nil } return fmt.Errorf("unknown LoginRecord field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *LoginRecordMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, loginrecord.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *LoginRecordMutation) AddedIDs(name string) []ent.Value { switch name { case loginrecord.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 *LoginRecordMutation) 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 *LoginRecordMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *LoginRecordMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, loginrecord.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *LoginRecordMutation) EdgeCleared(name string) bool { switch name { case loginrecord.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 *LoginRecordMutation) ClearEdge(name string) error { switch name { case loginrecord.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown LoginRecord 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 *LoginRecordMutation) ResetEdge(name string) error { switch name { case loginrecord.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown LoginRecord edge %s", name) } // OauthProviderMutation represents an operation that mutates the OauthProvider nodes in the graph. type OauthProviderMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time deleted_at *time.Time name *string client_id *string client_secret *string redirect_url *string scopes *string auth_url *string token_url *string info_url *string description *string system *bool init *bool clearedFields map[string]struct{} done bool oldValue func(context.Context) (*OauthProvider, error) predicates []predicate.OauthProvider } var _ ent.Mutation = (*OauthProviderMutation)(nil) // oauthproviderOption allows management of the mutation configuration using functional options. type oauthproviderOption func(*OauthProviderMutation) // newOauthProviderMutation creates new mutation for the OauthProvider entity. func newOauthProviderMutation(c config, op Op, opts ...oauthproviderOption) *OauthProviderMutation { m := &OauthProviderMutation{ config: c, op: op, typ: TypeOauthProvider, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withOauthProviderID sets the ID field of the mutation. func withOauthProviderID(id int64) oauthproviderOption { return func(m *OauthProviderMutation) { var ( err error once sync.Once value *OauthProvider ) m.oldValue = func(ctx context.Context) (*OauthProvider, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().OauthProvider.Get(ctx, id) } }) return value, err } m.id = &id } } // withOauthProvider sets the old OauthProvider of the mutation. func withOauthProvider(node *OauthProvider) oauthproviderOption { return func(m *OauthProviderMutation) { m.oldValue = func(context.Context) (*OauthProvider, 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 OauthProviderMutation) 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 OauthProviderMutation) 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 OauthProvider entities. func (m *OauthProviderMutation) 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 *OauthProviderMutation) 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 *OauthProviderMutation) 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().OauthProvider.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 *OauthProviderMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *OauthProviderMutation) 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 OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) 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 *OauthProviderMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *OauthProviderMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *OauthProviderMutation) 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 OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) 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 *OauthProviderMutation) ResetUpdatedAt() { m.updated_at = nil } // SetDeletedAt sets the "deleted_at" field. func (m *OauthProviderMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. func (m *OauthProviderMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return } return *v, true } // OldDeletedAt returns the old "deleted_at" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDeletedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } return oldValue.DeletedAt, nil } // ClearDeletedAt clears the value of the "deleted_at" field. func (m *OauthProviderMutation) ClearDeletedAt() { m.deleted_at = nil m.clearedFields[oauthprovider.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. func (m *OauthProviderMutation) DeletedAtCleared() bool { _, ok := m.clearedFields[oauthprovider.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. func (m *OauthProviderMutation) ResetDeletedAt() { m.deleted_at = nil delete(m.clearedFields, oauthprovider.FieldDeletedAt) } // SetName sets the "name" field. func (m *OauthProviderMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *OauthProviderMutation) 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 OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) 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 *OauthProviderMutation) ResetName() { m.name = nil } // SetClientID sets the "client_id" field. func (m *OauthProviderMutation) SetClientID(s string) { m.client_id = &s } // ClientID returns the value of the "client_id" field in the mutation. func (m *OauthProviderMutation) ClientID() (r string, exists bool) { v := m.client_id if v == nil { return } return *v, true } // OldClientID returns the old "client_id" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldClientID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldClientID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldClientID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldClientID: %w", err) } return oldValue.ClientID, nil } // ResetClientID resets all changes to the "client_id" field. func (m *OauthProviderMutation) ResetClientID() { m.client_id = nil } // SetClientSecret sets the "client_secret" field. func (m *OauthProviderMutation) SetClientSecret(s string) { m.client_secret = &s } // ClientSecret returns the value of the "client_secret" field in the mutation. func (m *OauthProviderMutation) ClientSecret() (r string, exists bool) { v := m.client_secret if v == nil { return } return *v, true } // OldClientSecret returns the old "client_secret" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldClientSecret(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldClientSecret is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldClientSecret requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldClientSecret: %w", err) } return oldValue.ClientSecret, nil } // ResetClientSecret resets all changes to the "client_secret" field. func (m *OauthProviderMutation) ResetClientSecret() { m.client_secret = nil } // SetRedirectURL sets the "redirect_url" field. func (m *OauthProviderMutation) SetRedirectURL(s string) { m.redirect_url = &s } // RedirectURL returns the value of the "redirect_url" field in the mutation. func (m *OauthProviderMutation) RedirectURL() (r string, exists bool) { v := m.redirect_url if v == nil { return } return *v, true } // OldRedirectURL returns the old "redirect_url" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldRedirectURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRedirectURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRedirectURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRedirectURL: %w", err) } return oldValue.RedirectURL, nil } // ResetRedirectURL resets all changes to the "redirect_url" field. func (m *OauthProviderMutation) ResetRedirectURL() { m.redirect_url = nil } // SetScopes sets the "scopes" field. func (m *OauthProviderMutation) SetScopes(s string) { m.scopes = &s } // Scopes returns the value of the "scopes" field in the mutation. func (m *OauthProviderMutation) Scopes() (r string, exists bool) { v := m.scopes if v == nil { return } return *v, true } // OldScopes returns the old "scopes" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldScopes(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldScopes is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldScopes requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldScopes: %w", err) } return oldValue.Scopes, nil } // ResetScopes resets all changes to the "scopes" field. func (m *OauthProviderMutation) ResetScopes() { m.scopes = nil } // SetAuthURL sets the "auth_url" field. func (m *OauthProviderMutation) SetAuthURL(s string) { m.auth_url = &s } // AuthURL returns the value of the "auth_url" field in the mutation. func (m *OauthProviderMutation) AuthURL() (r string, exists bool) { v := m.auth_url if v == nil { return } return *v, true } // OldAuthURL returns the old "auth_url" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldAuthURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAuthURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAuthURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAuthURL: %w", err) } return oldValue.AuthURL, nil } // ResetAuthURL resets all changes to the "auth_url" field. func (m *OauthProviderMutation) ResetAuthURL() { m.auth_url = nil } // SetTokenURL sets the "token_url" field. func (m *OauthProviderMutation) SetTokenURL(s string) { m.token_url = &s } // TokenURL returns the value of the "token_url" field in the mutation. func (m *OauthProviderMutation) TokenURL() (r string, exists bool) { v := m.token_url if v == nil { return } return *v, true } // OldTokenURL returns the old "token_url" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldTokenURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTokenURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTokenURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTokenURL: %w", err) } return oldValue.TokenURL, nil } // ResetTokenURL resets all changes to the "token_url" field. func (m *OauthProviderMutation) ResetTokenURL() { m.token_url = nil } // SetInfoURL sets the "info_url" field. func (m *OauthProviderMutation) SetInfoURL(s string) { m.info_url = &s } // InfoURL returns the value of the "info_url" field in the mutation. func (m *OauthProviderMutation) InfoURL() (r string, exists bool) { v := m.info_url if v == nil { return } return *v, true } // OldInfoURL returns the old "info_url" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldInfoURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldInfoURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldInfoURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldInfoURL: %w", err) } return oldValue.InfoURL, nil } // ResetInfoURL resets all changes to the "info_url" field. func (m *OauthProviderMutation) ResetInfoURL() { m.info_url = nil } // SetDescription sets the "description" field. func (m *OauthProviderMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *OauthProviderMutation) 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 OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) 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 *OauthProviderMutation) ResetDescription() { m.description = nil } // SetSystem sets the "system" field. func (m *OauthProviderMutation) SetSystem(b bool) { m.system = &b } // System returns the value of the "system" field in the mutation. func (m *OauthProviderMutation) System() (r bool, exists bool) { v := m.system if v == nil { return } return *v, true } // OldSystem returns the old "system" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldSystem(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSystem is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSystem requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSystem: %w", err) } return oldValue.System, nil } // ResetSystem resets all changes to the "system" field. func (m *OauthProviderMutation) ResetSystem() { m.system = nil } // SetInit sets the "init" field. func (m *OauthProviderMutation) SetInit(b bool) { m.init = &b } // Init returns the value of the "init" field in the mutation. func (m *OauthProviderMutation) Init() (r bool, exists bool) { v := m.init if v == nil { return } return *v, true } // OldInit returns the old "init" field's value of the OauthProvider entity. // If the OauthProvider 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 *OauthProviderMutation) OldInit(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldInit is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldInit requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldInit: %w", err) } return oldValue.Init, nil } // ResetInit resets all changes to the "init" field. func (m *OauthProviderMutation) ResetInit() { m.init = nil } // Where appends a list predicates to the OauthProviderMutation builder. func (m *OauthProviderMutation) Where(ps ...predicate.OauthProvider) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the OauthProviderMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *OauthProviderMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.OauthProvider, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *OauthProviderMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *OauthProviderMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (OauthProvider). func (m *OauthProviderMutation) 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 *OauthProviderMutation) Fields() []string { fields := make([]string, 0, 14) if m.created_at != nil { fields = append(fields, oauthprovider.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, oauthprovider.FieldUpdatedAt) } if m.deleted_at != nil { fields = append(fields, oauthprovider.FieldDeletedAt) } if m.name != nil { fields = append(fields, oauthprovider.FieldName) } if m.client_id != nil { fields = append(fields, oauthprovider.FieldClientID) } if m.client_secret != nil { fields = append(fields, oauthprovider.FieldClientSecret) } if m.redirect_url != nil { fields = append(fields, oauthprovider.FieldRedirectURL) } if m.scopes != nil { fields = append(fields, oauthprovider.FieldScopes) } if m.auth_url != nil { fields = append(fields, oauthprovider.FieldAuthURL) } if m.token_url != nil { fields = append(fields, oauthprovider.FieldTokenURL) } if m.info_url != nil { fields = append(fields, oauthprovider.FieldInfoURL) } if m.description != nil { fields = append(fields, oauthprovider.FieldDescription) } if m.system != nil { fields = append(fields, oauthprovider.FieldSystem) } if m.init != nil { fields = append(fields, oauthprovider.FieldInit) } 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 *OauthProviderMutation) Field(name string) (ent.Value, bool) { switch name { case oauthprovider.FieldCreatedAt: return m.CreatedAt() case oauthprovider.FieldUpdatedAt: return m.UpdatedAt() case oauthprovider.FieldDeletedAt: return m.DeletedAt() case oauthprovider.FieldName: return m.Name() case oauthprovider.FieldClientID: return m.ClientID() case oauthprovider.FieldClientSecret: return m.ClientSecret() case oauthprovider.FieldRedirectURL: return m.RedirectURL() case oauthprovider.FieldScopes: return m.Scopes() case oauthprovider.FieldAuthURL: return m.AuthURL() case oauthprovider.FieldTokenURL: return m.TokenURL() case oauthprovider.FieldInfoURL: return m.InfoURL() case oauthprovider.FieldDescription: return m.Description() case oauthprovider.FieldSystem: return m.System() case oauthprovider.FieldInit: return m.Init() } 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 *OauthProviderMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case oauthprovider.FieldCreatedAt: return m.OldCreatedAt(ctx) case oauthprovider.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case oauthprovider.FieldDeletedAt: return m.OldDeletedAt(ctx) case oauthprovider.FieldName: return m.OldName(ctx) case oauthprovider.FieldClientID: return m.OldClientID(ctx) case oauthprovider.FieldClientSecret: return m.OldClientSecret(ctx) case oauthprovider.FieldRedirectURL: return m.OldRedirectURL(ctx) case oauthprovider.FieldScopes: return m.OldScopes(ctx) case oauthprovider.FieldAuthURL: return m.OldAuthURL(ctx) case oauthprovider.FieldTokenURL: return m.OldTokenURL(ctx) case oauthprovider.FieldInfoURL: return m.OldInfoURL(ctx) case oauthprovider.FieldDescription: return m.OldDescription(ctx) case oauthprovider.FieldSystem: return m.OldSystem(ctx) case oauthprovider.FieldInit: return m.OldInit(ctx) } return nil, fmt.Errorf("unknown OauthProvider 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 *OauthProviderMutation) SetField(name string, value ent.Value) error { switch name { case oauthprovider.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 oauthprovider.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 oauthprovider.FieldDeletedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDeletedAt(v) return nil case oauthprovider.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case oauthprovider.FieldClientID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetClientID(v) return nil case oauthprovider.FieldClientSecret: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetClientSecret(v) return nil case oauthprovider.FieldRedirectURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRedirectURL(v) return nil case oauthprovider.FieldScopes: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetScopes(v) return nil case oauthprovider.FieldAuthURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAuthURL(v) return nil case oauthprovider.FieldTokenURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTokenURL(v) return nil case oauthprovider.FieldInfoURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetInfoURL(v) return nil case oauthprovider.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case oauthprovider.FieldSystem: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSystem(v) return nil case oauthprovider.FieldInit: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetInit(v) return nil } return fmt.Errorf("unknown OauthProvider field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *OauthProviderMutation) 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 *OauthProviderMutation) 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 *OauthProviderMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown OauthProvider numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *OauthProviderMutation) ClearedFields() []string { var fields []string if m.FieldCleared(oauthprovider.FieldDeletedAt) { fields = append(fields, oauthprovider.FieldDeletedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *OauthProviderMutation) 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 *OauthProviderMutation) ClearField(name string) error { switch name { case oauthprovider.FieldDeletedAt: m.ClearDeletedAt() return nil } return fmt.Errorf("unknown OauthProvider 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 *OauthProviderMutation) ResetField(name string) error { switch name { case oauthprovider.FieldCreatedAt: m.ResetCreatedAt() return nil case oauthprovider.FieldUpdatedAt: m.ResetUpdatedAt() return nil case oauthprovider.FieldDeletedAt: m.ResetDeletedAt() return nil case oauthprovider.FieldName: m.ResetName() return nil case oauthprovider.FieldClientID: m.ResetClientID() return nil case oauthprovider.FieldClientSecret: m.ResetClientSecret() return nil case oauthprovider.FieldRedirectURL: m.ResetRedirectURL() return nil case oauthprovider.FieldScopes: m.ResetScopes() return nil case oauthprovider.FieldAuthURL: m.ResetAuthURL() return nil case oauthprovider.FieldTokenURL: m.ResetTokenURL() return nil case oauthprovider.FieldInfoURL: m.ResetInfoURL() return nil case oauthprovider.FieldDescription: m.ResetDescription() return nil case oauthprovider.FieldSystem: m.ResetSystem() return nil case oauthprovider.FieldInit: m.ResetInit() return nil } return fmt.Errorf("unknown OauthProvider field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *OauthProviderMutation) 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 *OauthProviderMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *OauthProviderMutation) 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 *OauthProviderMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *OauthProviderMutation) 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 *OauthProviderMutation) 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 *OauthProviderMutation) ClearEdge(name string) error { return fmt.Errorf("unknown OauthProvider 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 *OauthProviderMutation) ResetEdge(name string) error { return fmt.Errorf("unknown OauthProvider 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 created_at *time.Time updated_at *time.Time version *int64 addversion *int64 status *types.Status deleted_at *time.Time code *string name *string description *string clearedFields map[string]struct{} users map[int64]struct{} removedusers map[int64]struct{} clearedusers bool 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) } } // SetCreatedAt sets the "created_at" field. func (m *RoleMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *RoleMutation) 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 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) 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 *RoleMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *RoleMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *RoleMutation) 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 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) 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 *RoleMutation) ResetUpdatedAt() { m.updated_at = nil } // SetVersion sets the "version" field. func (m *RoleMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *RoleMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" 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) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *RoleMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *RoleMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *RoleMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetStatus sets the "status" field. func (m *RoleMutation) SetStatus(t types.Status) { m.status = &t } // Status returns the value of the "status" field in the mutation. func (m *RoleMutation) Status() (r types.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" 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) OldStatus(ctx context.Context) (v types.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 *RoleMutation) ResetStatus() { m.status = nil } // SetDeletedAt sets the "deleted_at" field. func (m *RoleMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. func (m *RoleMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return } return *v, true } // OldDeletedAt returns the old "deleted_at" field's value of the 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) OldDeletedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDeletedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } return oldValue.DeletedAt, nil } // ClearDeletedAt clears the value of the "deleted_at" field. func (m *RoleMutation) ClearDeletedAt() { m.deleted_at = nil m.clearedFields[role.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. func (m *RoleMutation) DeletedAtCleared() bool { _, ok := m.clearedFields[role.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. func (m *RoleMutation) ResetDeletedAt() { m.deleted_at = nil delete(m.clearedFields, role.FieldDeletedAt) } // SetCode sets the "code" field. func (m *RoleMutation) SetCode(s string) { m.code = &s } // Code returns the value of the "code" field in the mutation. func (m *RoleMutation) Code() (r string, exists bool) { v := m.code if v == nil { return } return *v, true } // OldCode returns the old "code" field's value of the 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) OldCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCode: %w", err) } return oldValue.Code, nil } // ResetCode resets all changes to the "code" field. func (m *RoleMutation) ResetCode() { m.code = nil } // 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 } // SetDescription sets the "description" field. func (m *RoleMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *RoleMutation) 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 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) 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 *RoleMutation) ResetDescription() { m.description = nil } // AddUserIDs adds the "users" edge to the User entity by ids. func (m *RoleMutation) AddUserIDs(ids ...int64) { if m.users == nil { m.users = make(map[int64]struct{}) } for i := range ids { m.users[ids[i]] = struct{}{} } } // ClearUsers clears the "users" edge to the User entity. func (m *RoleMutation) ClearUsers() { m.clearedusers = true } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *RoleMutation) UsersCleared() bool { return m.clearedusers } // RemoveUserIDs removes the "users" edge to the User entity by IDs. func (m *RoleMutation) RemoveUserIDs(ids ...int64) { if m.removedusers == nil { m.removedusers = make(map[int64]struct{}) } for i := range ids { delete(m.users, ids[i]) m.removedusers[ids[i]] = struct{}{} } } // RemovedUsers returns the removed IDs of the "users" edge to the User entity. func (m *RoleMutation) RemovedUsersIDs() (ids []int64) { for id := range m.removedusers { ids = append(ids, id) } return } // UsersIDs returns the "users" edge IDs in the mutation. func (m *RoleMutation) UsersIDs() (ids []int64) { for id := range m.users { ids = append(ids, id) } return } // ResetUsers resets all changes to the "users" edge. func (m *RoleMutation) ResetUsers() { m.users = nil m.clearedusers = false m.removedusers = 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, 8) if m.created_at != nil { fields = append(fields, role.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, role.FieldUpdatedAt) } if m.version != nil { fields = append(fields, role.FieldVersion) } if m.status != nil { fields = append(fields, role.FieldStatus) } if m.deleted_at != nil { fields = append(fields, role.FieldDeletedAt) } if m.code != nil { fields = append(fields, role.FieldCode) } if m.name != nil { fields = append(fields, role.FieldName) } if m.description != nil { fields = append(fields, role.FieldDescription) } 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.FieldCreatedAt: return m.CreatedAt() case role.FieldUpdatedAt: return m.UpdatedAt() case role.FieldVersion: return m.Version() case role.FieldStatus: return m.Status() case role.FieldDeletedAt: return m.DeletedAt() case role.FieldCode: return m.Code() case role.FieldName: return m.Name() case role.FieldDescription: return m.Description() } 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.FieldCreatedAt: return m.OldCreatedAt(ctx) case role.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case role.FieldVersion: return m.OldVersion(ctx) case role.FieldStatus: return m.OldStatus(ctx) case role.FieldDeletedAt: return m.OldDeletedAt(ctx) case role.FieldCode: return m.OldCode(ctx) case role.FieldName: return m.OldName(ctx) case role.FieldDescription: return m.OldDescription(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.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 role.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 role.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case role.FieldStatus: v, ok := value.(types.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case role.FieldDeletedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDeletedAt(v) return nil case role.FieldCode: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCode(v) return nil 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 case role.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(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 { var fields []string if m.addversion != nil { fields = append(fields, role.FieldVersion) } 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 *RoleMutation) AddedField(name string) (ent.Value, bool) { switch name { case role.FieldVersion: return m.AddedVersion() } 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 { case role.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil } 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 { var fields []string if m.FieldCleared(role.FieldDeletedAt) { fields = append(fields, role.FieldDeletedAt) } return fields } // 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 { switch name { case role.FieldDeletedAt: m.ClearDeletedAt() return nil } 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.FieldCreatedAt: m.ResetCreatedAt() return nil case role.FieldUpdatedAt: m.ResetUpdatedAt() return nil case role.FieldVersion: m.ResetVersion() return nil case role.FieldStatus: m.ResetStatus() return nil case role.FieldDeletedAt: m.ResetDeletedAt() return nil case role.FieldCode: m.ResetCode() return nil case role.FieldName: m.ResetName() return nil case role.FieldDescription: m.ResetDescription() 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, 1) if m.users != nil { edges = append(edges, role.EdgeUsers) } 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 { switch name { case role.EdgeUsers: ids := make([]ent.Value, 0, len(m.users)) for id := range m.users { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *RoleMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedusers != nil { edges = append(edges, role.EdgeUsers) } 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 { switch name { case role.EdgeUsers: ids := make([]ent.Value, 0, len(m.removedusers)) for id := range m.removedusers { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RoleMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedusers { edges = append(edges, role.EdgeUsers) } 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 { switch name { case role.EdgeUsers: return m.clearedusers } 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 { switch name { } 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 { switch name { case role.EdgeUsers: m.ResetUsers() return nil } return fmt.Errorf("unknown Role edge %s", name) } // TokenMutation represents an operation that mutates the Token nodes in the graph. type TokenMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time status *types.Status version *int64 addversion *int64 token_type *string access_token *string refresh_token *string source *string expired_at *time.Time clearedFields map[string]struct{} user *int64 cleareduser bool done bool oldValue func(context.Context) (*Token, error) predicates []predicate.Token } var _ ent.Mutation = (*TokenMutation)(nil) // tokenOption allows management of the mutation configuration using functional options. type tokenOption func(*TokenMutation) // newTokenMutation creates new mutation for the Token entity. func newTokenMutation(c config, op Op, opts ...tokenOption) *TokenMutation { m := &TokenMutation{ config: c, op: op, typ: TypeToken, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withTokenID sets the ID field of the mutation. func withTokenID(id int64) tokenOption { return func(m *TokenMutation) { var ( err error once sync.Once value *Token ) m.oldValue = func(ctx context.Context) (*Token, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Token.Get(ctx, id) } }) return value, err } m.id = &id } } // withToken sets the old Token of the mutation. func withToken(node *Token) tokenOption { return func(m *TokenMutation) { m.oldValue = func(context.Context) (*Token, 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 TokenMutation) 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 TokenMutation) 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 Token entities. func (m *TokenMutation) 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 *TokenMutation) 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 *TokenMutation) 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().Token.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 *TokenMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *TokenMutation) 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 Token entity. // If the Token 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 *TokenMutation) 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 *TokenMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *TokenMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *TokenMutation) 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 Token entity. // If the Token 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 *TokenMutation) 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 *TokenMutation) ResetUpdatedAt() { m.updated_at = nil } // SetStatus sets the "status" field. func (m *TokenMutation) SetStatus(t types.Status) { m.status = &t } // Status returns the value of the "status" field in the mutation. func (m *TokenMutation) Status() (r types.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Token entity. // If the Token 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 *TokenMutation) OldStatus(ctx context.Context) (v types.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 *TokenMutation) ResetStatus() { m.status = nil } // SetVersion sets the "version" field. func (m *TokenMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *TokenMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" field's value of the Token entity. // If the Token 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 *TokenMutation) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *TokenMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *TokenMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *TokenMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetUserID sets the "user_id" field. func (m *TokenMutation) SetUserID(i int64) { m.user = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *TokenMutation) UserID() (r int64, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the Token entity. // If the Token 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 *TokenMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *TokenMutation) ResetUserID() { m.user = nil } // SetTokenType sets the "token_type" field. func (m *TokenMutation) SetTokenType(s string) { m.token_type = &s } // TokenType returns the value of the "token_type" field in the mutation. func (m *TokenMutation) TokenType() (r string, exists bool) { v := m.token_type if v == nil { return } return *v, true } // OldTokenType returns the old "token_type" field's value of the Token entity. // If the Token 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 *TokenMutation) OldTokenType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTokenType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTokenType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTokenType: %w", err) } return oldValue.TokenType, nil } // ResetTokenType resets all changes to the "token_type" field. func (m *TokenMutation) ResetTokenType() { m.token_type = nil } // SetAccessToken sets the "access_token" field. func (m *TokenMutation) SetAccessToken(s string) { m.access_token = &s } // AccessToken returns the value of the "access_token" field in the mutation. func (m *TokenMutation) AccessToken() (r string, exists bool) { v := m.access_token if v == nil { return } return *v, true } // OldAccessToken returns the old "access_token" field's value of the Token entity. // If the Token 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 *TokenMutation) OldAccessToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAccessToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAccessToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAccessToken: %w", err) } return oldValue.AccessToken, nil } // ResetAccessToken resets all changes to the "access_token" field. func (m *TokenMutation) ResetAccessToken() { m.access_token = nil } // SetRefreshToken sets the "refresh_token" field. func (m *TokenMutation) SetRefreshToken(s string) { m.refresh_token = &s } // RefreshToken returns the value of the "refresh_token" field in the mutation. func (m *TokenMutation) RefreshToken() (r string, exists bool) { v := m.refresh_token if v == nil { return } return *v, true } // OldRefreshToken returns the old "refresh_token" field's value of the Token entity. // If the Token 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 *TokenMutation) OldRefreshToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRefreshToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRefreshToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRefreshToken: %w", err) } return oldValue.RefreshToken, nil } // ResetRefreshToken resets all changes to the "refresh_token" field. func (m *TokenMutation) ResetRefreshToken() { m.refresh_token = nil } // SetSource sets the "source" field. func (m *TokenMutation) SetSource(s string) { m.source = &s } // Source returns the value of the "source" field in the mutation. func (m *TokenMutation) Source() (r string, exists bool) { v := m.source if v == nil { return } return *v, true } // OldSource returns the old "source" field's value of the Token entity. // If the Token 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 *TokenMutation) OldSource(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSource is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSource requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSource: %w", err) } return oldValue.Source, nil } // ResetSource resets all changes to the "source" field. func (m *TokenMutation) ResetSource() { m.source = nil } // SetExpiredAt sets the "expired_at" field. func (m *TokenMutation) SetExpiredAt(t time.Time) { m.expired_at = &t } // ExpiredAt returns the value of the "expired_at" field in the mutation. func (m *TokenMutation) ExpiredAt() (r time.Time, exists bool) { v := m.expired_at if v == nil { return } return *v, true } // OldExpiredAt returns the old "expired_at" field's value of the Token entity. // If the Token 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 *TokenMutation) OldExpiredAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldExpiredAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldExpiredAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldExpiredAt: %w", err) } return oldValue.ExpiredAt, nil } // ResetExpiredAt resets all changes to the "expired_at" field. func (m *TokenMutation) ResetExpiredAt() { m.expired_at = nil } // ClearUser clears the "user" edge to the User entity. func (m *TokenMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *TokenMutation) UserCleared() bool { return m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *TokenMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *TokenMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the TokenMutation builder. func (m *TokenMutation) Where(ps ...predicate.Token) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the TokenMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *TokenMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Token, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *TokenMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *TokenMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Token). func (m *TokenMutation) 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 *TokenMutation) Fields() []string { fields := make([]string, 0, 10) if m.created_at != nil { fields = append(fields, token.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, token.FieldUpdatedAt) } if m.status != nil { fields = append(fields, token.FieldStatus) } if m.version != nil { fields = append(fields, token.FieldVersion) } if m.user != nil { fields = append(fields, token.FieldUserID) } if m.token_type != nil { fields = append(fields, token.FieldTokenType) } if m.access_token != nil { fields = append(fields, token.FieldAccessToken) } if m.refresh_token != nil { fields = append(fields, token.FieldRefreshToken) } if m.source != nil { fields = append(fields, token.FieldSource) } if m.expired_at != nil { fields = append(fields, token.FieldExpiredAt) } 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 *TokenMutation) Field(name string) (ent.Value, bool) { switch name { case token.FieldCreatedAt: return m.CreatedAt() case token.FieldUpdatedAt: return m.UpdatedAt() case token.FieldStatus: return m.Status() case token.FieldVersion: return m.Version() case token.FieldUserID: return m.UserID() case token.FieldTokenType: return m.TokenType() case token.FieldAccessToken: return m.AccessToken() case token.FieldRefreshToken: return m.RefreshToken() case token.FieldSource: return m.Source() case token.FieldExpiredAt: return m.ExpiredAt() } 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 *TokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case token.FieldCreatedAt: return m.OldCreatedAt(ctx) case token.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case token.FieldStatus: return m.OldStatus(ctx) case token.FieldVersion: return m.OldVersion(ctx) case token.FieldUserID: return m.OldUserID(ctx) case token.FieldTokenType: return m.OldTokenType(ctx) case token.FieldAccessToken: return m.OldAccessToken(ctx) case token.FieldRefreshToken: return m.OldRefreshToken(ctx) case token.FieldSource: return m.OldSource(ctx) case token.FieldExpiredAt: return m.OldExpiredAt(ctx) } return nil, fmt.Errorf("unknown Token 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 *TokenMutation) SetField(name string, value ent.Value) error { switch name { case token.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 token.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 token.FieldStatus: v, ok := value.(types.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case token.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case token.FieldUserID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case token.FieldTokenType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTokenType(v) return nil case token.FieldAccessToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAccessToken(v) return nil case token.FieldRefreshToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRefreshToken(v) return nil case token.FieldSource: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSource(v) return nil case token.FieldExpiredAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetExpiredAt(v) return nil } return fmt.Errorf("unknown Token field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *TokenMutation) AddedFields() []string { var fields []string if m.addversion != nil { fields = append(fields, token.FieldVersion) } 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 *TokenMutation) AddedField(name string) (ent.Value, bool) { switch name { case token.FieldVersion: return m.AddedVersion() } 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 *TokenMutation) AddField(name string, value ent.Value) error { switch name { case token.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil } return fmt.Errorf("unknown Token numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TokenMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *TokenMutation) 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 *TokenMutation) ClearField(name string) error { return fmt.Errorf("unknown Token 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 *TokenMutation) ResetField(name string) error { switch name { case token.FieldCreatedAt: m.ResetCreatedAt() return nil case token.FieldUpdatedAt: m.ResetUpdatedAt() return nil case token.FieldStatus: m.ResetStatus() return nil case token.FieldVersion: m.ResetVersion() return nil case token.FieldUserID: m.ResetUserID() return nil case token.FieldTokenType: m.ResetTokenType() return nil case token.FieldAccessToken: m.ResetAccessToken() return nil case token.FieldRefreshToken: m.ResetRefreshToken() return nil case token.FieldSource: m.ResetSource() return nil case token.FieldExpiredAt: m.ResetExpiredAt() return nil } return fmt.Errorf("unknown Token field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *TokenMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, token.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *TokenMutation) AddedIDs(name string) []ent.Value { switch name { case token.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 *TokenMutation) 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 *TokenMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TokenMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, token.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *TokenMutation) EdgeCleared(name string) bool { switch name { case token.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 *TokenMutation) ClearEdge(name string) error { switch name { case token.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown Token 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 *TokenMutation) ResetEdge(name string) error { switch name { case token.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown Token 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 status *types.Status created_at *time.Time updated_at *time.Time version *int64 addversion *int64 username *string phone_number *string email *string password *string nickname *string clearedFields map[string]struct{} metas map[int64]struct{} removedmetas map[int64]struct{} clearedmetas bool roles map[int64]struct{} removedroles map[int64]struct{} clearedroles bool socials map[int64]struct{} removedsocials map[int64]struct{} clearedsocials bool departments map[int64]struct{} removeddepartments map[int64]struct{} cleareddepartments bool token map[int64]struct{} removedtoken map[int64]struct{} clearedtoken bool loginRecord *int64 clearedloginRecord 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) } } // SetStatus sets the "status" field. func (m *UserMutation) SetStatus(t types.Status) { m.status = &t } // Status returns the value of the "status" field in the mutation. func (m *UserMutation) Status() (r types.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 types.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 } // 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 } // SetVersion sets the "version" field. func (m *UserMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *UserMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" 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) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *UserMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *UserMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *UserMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetUsername sets the "username" field. func (m *UserMutation) SetUsername(s string) { m.username = &s } // Username returns the value of the "username" field in the mutation. func (m *UserMutation) Username() (r string, exists bool) { v := m.username if v == nil { return } return *v, true } // OldUsername returns the old "username" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUsername: %w", err) } return oldValue.Username, nil } // ResetUsername resets all changes to the "username" field. func (m *UserMutation) ResetUsername() { m.username = nil } // SetPhoneNumber sets the "phone_number" field. func (m *UserMutation) SetPhoneNumber(s string) { m.phone_number = &s } // PhoneNumber returns the value of the "phone_number" field in the mutation. func (m *UserMutation) PhoneNumber() (r string, exists bool) { v := m.phone_number if v == nil { return } return *v, true } // OldPhoneNumber returns the old "phone_number" 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) OldPhoneNumber(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPhoneNumber is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPhoneNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPhoneNumber: %w", err) } return oldValue.PhoneNumber, nil } // ClearPhoneNumber clears the value of the "phone_number" field. func (m *UserMutation) ClearPhoneNumber() { m.phone_number = nil m.clearedFields[user.FieldPhoneNumber] = struct{}{} } // PhoneNumberCleared returns if the "phone_number" field was cleared in this mutation. func (m *UserMutation) PhoneNumberCleared() bool { _, ok := m.clearedFields[user.FieldPhoneNumber] return ok } // ResetPhoneNumber resets all changes to the "phone_number" field. func (m *UserMutation) ResetPhoneNumber() { m.phone_number = nil delete(m.clearedFields, user.FieldPhoneNumber) } // 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 } // ClearEmail clears the value of the "email" field. func (m *UserMutation) ClearEmail() { m.email = nil m.clearedFields[user.FieldEmail] = struct{}{} } // EmailCleared returns if the "email" field was cleared in this mutation. func (m *UserMutation) EmailCleared() bool { _, ok := m.clearedFields[user.FieldEmail] return ok } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil delete(m.clearedFields, user.FieldEmail) } // SetPassword sets the "password" field. func (m *UserMutation) SetPassword(s string) { m.password = &s } // Password returns the value of the "password" field in the mutation. func (m *UserMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old "password" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPassword requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPassword: %w", err) } return oldValue.Password, nil } // ResetPassword resets all changes to the "password" field. func (m *UserMutation) ResetPassword() { m.password = nil } // SetNickname sets the "nickname" field. func (m *UserMutation) SetNickname(s string) { m.nickname = &s } // Nickname returns the value of the "nickname" field in the mutation. func (m *UserMutation) Nickname() (r string, exists bool) { v := m.nickname if v == nil { return } return *v, true } // OldNickname returns the old "nickname" 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) OldNickname(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldNickname is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldNickname requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldNickname: %w", err) } return oldValue.Nickname, nil } // ClearNickname clears the value of the "nickname" field. func (m *UserMutation) ClearNickname() { m.nickname = nil m.clearedFields[user.FieldNickname] = struct{}{} } // NicknameCleared returns if the "nickname" field was cleared in this mutation. func (m *UserMutation) NicknameCleared() bool { _, ok := m.clearedFields[user.FieldNickname] return ok } // ResetNickname resets all changes to the "nickname" field. func (m *UserMutation) ResetNickname() { m.nickname = nil delete(m.clearedFields, user.FieldNickname) } // AddMetaIDs adds the "metas" edge to the UserMeta entity by ids. func (m *UserMutation) AddMetaIDs(ids ...int64) { if m.metas == nil { m.metas = make(map[int64]struct{}) } for i := range ids { m.metas[ids[i]] = struct{}{} } } // ClearMetas clears the "metas" edge to the UserMeta entity. func (m *UserMutation) ClearMetas() { m.clearedmetas = true } // MetasCleared reports if the "metas" edge to the UserMeta entity was cleared. func (m *UserMutation) MetasCleared() bool { return m.clearedmetas } // RemoveMetaIDs removes the "metas" edge to the UserMeta entity by IDs. func (m *UserMutation) RemoveMetaIDs(ids ...int64) { if m.removedmetas == nil { m.removedmetas = make(map[int64]struct{}) } for i := range ids { delete(m.metas, ids[i]) m.removedmetas[ids[i]] = struct{}{} } } // RemovedMetas returns the removed IDs of the "metas" edge to the UserMeta entity. func (m *UserMutation) RemovedMetasIDs() (ids []int64) { for id := range m.removedmetas { ids = append(ids, id) } return } // MetasIDs returns the "metas" edge IDs in the mutation. func (m *UserMutation) MetasIDs() (ids []int64) { for id := range m.metas { ids = append(ids, id) } return } // ResetMetas resets all changes to the "metas" edge. func (m *UserMutation) ResetMetas() { m.metas = nil m.clearedmetas = false m.removedmetas = nil } // AddRoleIDs adds the "roles" edge to the Role entity by ids. func (m *UserMutation) AddRoleIDs(ids ...int64) { if m.roles == nil { m.roles = make(map[int64]struct{}) } for i := range ids { m.roles[ids[i]] = struct{}{} } } // ClearRoles clears the "roles" edge to the Role entity. func (m *UserMutation) ClearRoles() { m.clearedroles = true } // RolesCleared reports if the "roles" edge to the Role entity was cleared. func (m *UserMutation) RolesCleared() bool { return m.clearedroles } // RemoveRoleIDs removes the "roles" edge to the Role entity by IDs. func (m *UserMutation) RemoveRoleIDs(ids ...int64) { if m.removedroles == nil { m.removedroles = make(map[int64]struct{}) } for i := range ids { delete(m.roles, ids[i]) m.removedroles[ids[i]] = struct{}{} } } // RemovedRoles returns the removed IDs of the "roles" edge to the Role entity. func (m *UserMutation) RemovedRolesIDs() (ids []int64) { for id := range m.removedroles { ids = append(ids, id) } return } // RolesIDs returns the "roles" edge IDs in the mutation. func (m *UserMutation) RolesIDs() (ids []int64) { for id := range m.roles { ids = append(ids, id) } return } // ResetRoles resets all changes to the "roles" edge. func (m *UserMutation) ResetRoles() { m.roles = nil m.clearedroles = false m.removedroles = nil } // AddSocialIDs adds the "socials" edge to the UserSocial entity by ids. func (m *UserMutation) AddSocialIDs(ids ...int64) { if m.socials == nil { m.socials = make(map[int64]struct{}) } for i := range ids { m.socials[ids[i]] = struct{}{} } } // ClearSocials clears the "socials" edge to the UserSocial entity. func (m *UserMutation) ClearSocials() { m.clearedsocials = true } // SocialsCleared reports if the "socials" edge to the UserSocial entity was cleared. func (m *UserMutation) SocialsCleared() bool { return m.clearedsocials } // RemoveSocialIDs removes the "socials" edge to the UserSocial entity by IDs. func (m *UserMutation) RemoveSocialIDs(ids ...int64) { if m.removedsocials == nil { m.removedsocials = make(map[int64]struct{}) } for i := range ids { delete(m.socials, ids[i]) m.removedsocials[ids[i]] = struct{}{} } } // RemovedSocials returns the removed IDs of the "socials" edge to the UserSocial entity. func (m *UserMutation) RemovedSocialsIDs() (ids []int64) { for id := range m.removedsocials { ids = append(ids, id) } return } // SocialsIDs returns the "socials" edge IDs in the mutation. func (m *UserMutation) SocialsIDs() (ids []int64) { for id := range m.socials { ids = append(ids, id) } return } // ResetSocials resets all changes to the "socials" edge. func (m *UserMutation) ResetSocials() { m.socials = nil m.clearedsocials = false m.removedsocials = nil } // AddDepartmentIDs adds the "departments" edge to the Department entity by ids. func (m *UserMutation) AddDepartmentIDs(ids ...int64) { if m.departments == nil { m.departments = make(map[int64]struct{}) } for i := range ids { m.departments[ids[i]] = struct{}{} } } // ClearDepartments clears the "departments" edge to the Department entity. func (m *UserMutation) ClearDepartments() { m.cleareddepartments = true } // DepartmentsCleared reports if the "departments" edge to the Department entity was cleared. func (m *UserMutation) DepartmentsCleared() bool { return m.cleareddepartments } // RemoveDepartmentIDs removes the "departments" edge to the Department entity by IDs. func (m *UserMutation) RemoveDepartmentIDs(ids ...int64) { if m.removeddepartments == nil { m.removeddepartments = make(map[int64]struct{}) } for i := range ids { delete(m.departments, ids[i]) m.removeddepartments[ids[i]] = struct{}{} } } // RemovedDepartments returns the removed IDs of the "departments" edge to the Department entity. func (m *UserMutation) RemovedDepartmentsIDs() (ids []int64) { for id := range m.removeddepartments { ids = append(ids, id) } return } // DepartmentsIDs returns the "departments" edge IDs in the mutation. func (m *UserMutation) DepartmentsIDs() (ids []int64) { for id := range m.departments { ids = append(ids, id) } return } // ResetDepartments resets all changes to the "departments" edge. func (m *UserMutation) ResetDepartments() { m.departments = nil m.cleareddepartments = false m.removeddepartments = nil } // AddTokenIDs adds the "token" edge to the Token entity by ids. func (m *UserMutation) AddTokenIDs(ids ...int64) { if m.token == nil { m.token = make(map[int64]struct{}) } for i := range ids { m.token[ids[i]] = struct{}{} } } // ClearToken clears the "token" edge to the Token entity. func (m *UserMutation) ClearToken() { m.clearedtoken = true } // TokenCleared reports if the "token" edge to the Token entity was cleared. func (m *UserMutation) TokenCleared() bool { return m.clearedtoken } // RemoveTokenIDs removes the "token" edge to the Token entity by IDs. func (m *UserMutation) RemoveTokenIDs(ids ...int64) { if m.removedtoken == nil { m.removedtoken = make(map[int64]struct{}) } for i := range ids { delete(m.token, ids[i]) m.removedtoken[ids[i]] = struct{}{} } } // RemovedToken returns the removed IDs of the "token" edge to the Token entity. func (m *UserMutation) RemovedTokenIDs() (ids []int64) { for id := range m.removedtoken { ids = append(ids, id) } return } // TokenIDs returns the "token" edge IDs in the mutation. func (m *UserMutation) TokenIDs() (ids []int64) { for id := range m.token { ids = append(ids, id) } return } // ResetToken resets all changes to the "token" edge. func (m *UserMutation) ResetToken() { m.token = nil m.clearedtoken = false m.removedtoken = nil } // SetLoginRecordID sets the "loginRecord" edge to the LoginRecord entity by id. func (m *UserMutation) SetLoginRecordID(id int64) { m.loginRecord = &id } // ClearLoginRecord clears the "loginRecord" edge to the LoginRecord entity. func (m *UserMutation) ClearLoginRecord() { m.clearedloginRecord = true } // LoginRecordCleared reports if the "loginRecord" edge to the LoginRecord entity was cleared. func (m *UserMutation) LoginRecordCleared() bool { return m.clearedloginRecord } // LoginRecordID returns the "loginRecord" edge ID in the mutation. func (m *UserMutation) LoginRecordID() (id int64, exists bool) { if m.loginRecord != nil { return *m.loginRecord, true } return } // LoginRecordIDs returns the "loginRecord" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // LoginRecordID instead. It exists only for internal usage by the builders. func (m *UserMutation) LoginRecordIDs() (ids []int64) { if id := m.loginRecord; id != nil { ids = append(ids, *id) } return } // ResetLoginRecord resets all changes to the "loginRecord" edge. func (m *UserMutation) ResetLoginRecord() { m.loginRecord = nil m.clearedloginRecord = false } // 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, 9) if m.status != nil { fields = append(fields, user.FieldStatus) } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } if m.version != nil { fields = append(fields, user.FieldVersion) } if m.username != nil { fields = append(fields, user.FieldUsername) } if m.phone_number != nil { fields = append(fields, user.FieldPhoneNumber) } if m.email != nil { fields = append(fields, user.FieldEmail) } if m.password != nil { fields = append(fields, user.FieldPassword) } if m.nickname != nil { fields = append(fields, user.FieldNickname) } 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.FieldStatus: return m.Status() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() case user.FieldVersion: return m.Version() case user.FieldUsername: return m.Username() case user.FieldPhoneNumber: return m.PhoneNumber() case user.FieldEmail: return m.Email() case user.FieldPassword: return m.Password() case user.FieldNickname: return m.Nickname() } 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.FieldStatus: return m.OldStatus(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case user.FieldVersion: return m.OldVersion(ctx) case user.FieldUsername: return m.OldUsername(ctx) case user.FieldPhoneNumber: return m.OldPhoneNumber(ctx) case user.FieldEmail: return m.OldEmail(ctx) case user.FieldPassword: return m.OldPassword(ctx) case user.FieldNickname: return m.OldNickname(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.FieldStatus: v, ok := value.(types.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case user.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case user.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case user.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case user.FieldUsername: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsername(v) return nil case user.FieldPhoneNumber: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhoneNumber(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.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(v) return nil case user.FieldNickname: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNickname(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.addversion != nil { fields = append(fields, user.FieldVersion) } 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.FieldVersion: return m.AddedVersion() } 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.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(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.FieldPhoneNumber) { fields = append(fields, user.FieldPhoneNumber) } if m.FieldCleared(user.FieldEmail) { fields = append(fields, user.FieldEmail) } if m.FieldCleared(user.FieldNickname) { fields = append(fields, user.FieldNickname) } 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.FieldPhoneNumber: m.ClearPhoneNumber() return nil case user.FieldEmail: m.ClearEmail() return nil case user.FieldNickname: m.ClearNickname() 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.FieldStatus: m.ResetStatus() return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() return nil case user.FieldVersion: m.ResetVersion() return nil case user.FieldUsername: m.ResetUsername() return nil case user.FieldPhoneNumber: m.ResetPhoneNumber() return nil case user.FieldEmail: m.ResetEmail() return nil case user.FieldPassword: m.ResetPassword() return nil case user.FieldNickname: m.ResetNickname() 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, 6) if m.metas != nil { edges = append(edges, user.EdgeMetas) } if m.roles != nil { edges = append(edges, user.EdgeRoles) } if m.socials != nil { edges = append(edges, user.EdgeSocials) } if m.departments != nil { edges = append(edges, user.EdgeDepartments) } if m.token != nil { edges = append(edges, user.EdgeToken) } if m.loginRecord != nil { edges = append(edges, user.EdgeLoginRecord) } 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.EdgeMetas: ids := make([]ent.Value, 0, len(m.metas)) for id := range m.metas { ids = append(ids, id) } return ids case user.EdgeRoles: ids := make([]ent.Value, 0, len(m.roles)) for id := range m.roles { ids = append(ids, id) } return ids case user.EdgeSocials: ids := make([]ent.Value, 0, len(m.socials)) for id := range m.socials { ids = append(ids, id) } return ids case user.EdgeDepartments: ids := make([]ent.Value, 0, len(m.departments)) for id := range m.departments { ids = append(ids, id) } return ids case user.EdgeToken: ids := make([]ent.Value, 0, len(m.token)) for id := range m.token { ids = append(ids, id) } return ids case user.EdgeLoginRecord: if id := m.loginRecord; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { edges := make([]string, 0, 6) if m.removedmetas != nil { edges = append(edges, user.EdgeMetas) } if m.removedroles != nil { edges = append(edges, user.EdgeRoles) } if m.removedsocials != nil { edges = append(edges, user.EdgeSocials) } if m.removeddepartments != nil { edges = append(edges, user.EdgeDepartments) } if m.removedtoken != nil { edges = append(edges, user.EdgeToken) } 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.EdgeMetas: ids := make([]ent.Value, 0, len(m.removedmetas)) for id := range m.removedmetas { ids = append(ids, id) } return ids case user.EdgeRoles: ids := make([]ent.Value, 0, len(m.removedroles)) for id := range m.removedroles { ids = append(ids, id) } return ids case user.EdgeSocials: ids := make([]ent.Value, 0, len(m.removedsocials)) for id := range m.removedsocials { ids = append(ids, id) } return ids case user.EdgeDepartments: ids := make([]ent.Value, 0, len(m.removeddepartments)) for id := range m.removeddepartments { ids = append(ids, id) } return ids case user.EdgeToken: ids := make([]ent.Value, 0, len(m.removedtoken)) for id := range m.removedtoken { 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, 6) if m.clearedmetas { edges = append(edges, user.EdgeMetas) } if m.clearedroles { edges = append(edges, user.EdgeRoles) } if m.clearedsocials { edges = append(edges, user.EdgeSocials) } if m.cleareddepartments { edges = append(edges, user.EdgeDepartments) } if m.clearedtoken { edges = append(edges, user.EdgeToken) } if m.clearedloginRecord { edges = append(edges, user.EdgeLoginRecord) } 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.EdgeMetas: return m.clearedmetas case user.EdgeRoles: return m.clearedroles case user.EdgeSocials: return m.clearedsocials case user.EdgeDepartments: return m.cleareddepartments case user.EdgeToken: return m.clearedtoken case user.EdgeLoginRecord: return m.clearedloginRecord } 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 { case user.EdgeLoginRecord: m.ClearLoginRecord() return nil } 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.EdgeMetas: m.ResetMetas() return nil case user.EdgeRoles: m.ResetRoles() return nil case user.EdgeSocials: m.ResetSocials() return nil case user.EdgeDepartments: m.ResetDepartments() return nil case user.EdgeToken: m.ResetToken() return nil case user.EdgeLoginRecord: m.ResetLoginRecord() return nil } return fmt.Errorf("unknown User edge %s", name) } // UserMetaMutation represents an operation that mutates the UserMeta nodes in the graph. type UserMetaMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time version *int64 addversion *int64 key *string value *string clearedFields map[string]struct{} user *int64 cleareduser bool done bool oldValue func(context.Context) (*UserMeta, error) predicates []predicate.UserMeta } var _ ent.Mutation = (*UserMetaMutation)(nil) // usermetaOption allows management of the mutation configuration using functional options. type usermetaOption func(*UserMetaMutation) // newUserMetaMutation creates new mutation for the UserMeta entity. func newUserMetaMutation(c config, op Op, opts ...usermetaOption) *UserMetaMutation { m := &UserMetaMutation{ config: c, op: op, typ: TypeUserMeta, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserMetaID sets the ID field of the mutation. func withUserMetaID(id int64) usermetaOption { return func(m *UserMetaMutation) { var ( err error once sync.Once value *UserMeta ) m.oldValue = func(ctx context.Context) (*UserMeta, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserMeta.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserMeta sets the old UserMeta of the mutation. func withUserMeta(node *UserMeta) usermetaOption { return func(m *UserMetaMutation) { m.oldValue = func(context.Context) (*UserMeta, 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 UserMetaMutation) 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 UserMetaMutation) 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 UserMeta entities. func (m *UserMetaMutation) 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 *UserMetaMutation) 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 *UserMetaMutation) 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().UserMeta.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 *UserMetaMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserMetaMutation) 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 UserMeta entity. // If the UserMeta 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 *UserMetaMutation) 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 *UserMetaMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *UserMetaMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *UserMetaMutation) 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 UserMeta entity. // If the UserMeta 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 *UserMetaMutation) 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 *UserMetaMutation) ResetUpdatedAt() { m.updated_at = nil } // SetVersion sets the "version" field. func (m *UserMetaMutation) SetVersion(i int64) { m.version = &i m.addversion = nil } // Version returns the value of the "version" field in the mutation. func (m *UserMetaMutation) Version() (r int64, exists bool) { v := m.version if v == nil { return } return *v, true } // OldVersion returns the old "version" field's value of the UserMeta entity. // If the UserMeta 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 *UserMetaMutation) OldVersion(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVersion: %w", err) } return oldValue.Version, nil } // AddVersion adds i to the "version" field. func (m *UserMetaMutation) AddVersion(i int64) { if m.addversion != nil { *m.addversion += i } else { m.addversion = &i } } // AddedVersion returns the value that was added to the "version" field in this mutation. func (m *UserMetaMutation) AddedVersion() (r int64, exists bool) { v := m.addversion if v == nil { return } return *v, true } // ResetVersion resets all changes to the "version" field. func (m *UserMetaMutation) ResetVersion() { m.version = nil m.addversion = nil } // SetUserID sets the "user_id" field. func (m *UserMetaMutation) SetUserID(i int64) { m.user = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *UserMetaMutation) UserID() (r int64, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the UserMeta entity. // If the UserMeta 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 *UserMetaMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *UserMetaMutation) ResetUserID() { m.user = nil } // SetKey sets the "key" field. func (m *UserMetaMutation) SetKey(s string) { m.key = &s } // Key returns the value of the "key" field in the mutation. func (m *UserMetaMutation) Key() (r string, exists bool) { v := m.key if v == nil { return } return *v, true } // OldKey returns the old "key" field's value of the UserMeta entity. // If the UserMeta 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 *UserMetaMutation) OldKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldKey requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldKey: %w", err) } return oldValue.Key, nil } // ClearKey clears the value of the "key" field. func (m *UserMetaMutation) ClearKey() { m.key = nil m.clearedFields[usermeta.FieldKey] = struct{}{} } // KeyCleared returns if the "key" field was cleared in this mutation. func (m *UserMetaMutation) KeyCleared() bool { _, ok := m.clearedFields[usermeta.FieldKey] return ok } // ResetKey resets all changes to the "key" field. func (m *UserMetaMutation) ResetKey() { m.key = nil delete(m.clearedFields, usermeta.FieldKey) } // SetValue sets the "value" field. func (m *UserMetaMutation) SetValue(s string) { m.value = &s } // Value returns the value of the "value" field in the mutation. func (m *UserMetaMutation) Value() (r string, exists bool) { v := m.value if v == nil { return } return *v, true } // OldValue returns the old "value" field's value of the UserMeta entity. // If the UserMeta 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 *UserMetaMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldValue requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldValue: %w", err) } return oldValue.Value, nil } // ClearValue clears the value of the "value" field. func (m *UserMetaMutation) ClearValue() { m.value = nil m.clearedFields[usermeta.FieldValue] = struct{}{} } // ValueCleared returns if the "value" field was cleared in this mutation. func (m *UserMetaMutation) ValueCleared() bool { _, ok := m.clearedFields[usermeta.FieldValue] return ok } // ResetValue resets all changes to the "value" field. func (m *UserMetaMutation) ResetValue() { m.value = nil delete(m.clearedFields, usermeta.FieldValue) } // ClearUser clears the "user" edge to the User entity. func (m *UserMetaMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *UserMetaMutation) UserCleared() bool { return m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *UserMetaMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *UserMetaMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the UserMetaMutation builder. func (m *UserMetaMutation) Where(ps ...predicate.UserMeta) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserMetaMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserMetaMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserMeta, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserMetaMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserMetaMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserMeta). func (m *UserMetaMutation) 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 *UserMetaMutation) Fields() []string { fields := make([]string, 0, 6) if m.created_at != nil { fields = append(fields, usermeta.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, usermeta.FieldUpdatedAt) } if m.version != nil { fields = append(fields, usermeta.FieldVersion) } if m.user != nil { fields = append(fields, usermeta.FieldUserID) } if m.key != nil { fields = append(fields, usermeta.FieldKey) } if m.value != nil { fields = append(fields, usermeta.FieldValue) } 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 *UserMetaMutation) Field(name string) (ent.Value, bool) { switch name { case usermeta.FieldCreatedAt: return m.CreatedAt() case usermeta.FieldUpdatedAt: return m.UpdatedAt() case usermeta.FieldVersion: return m.Version() case usermeta.FieldUserID: return m.UserID() case usermeta.FieldKey: return m.Key() case usermeta.FieldValue: return m.Value() } 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 *UserMetaMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case usermeta.FieldCreatedAt: return m.OldCreatedAt(ctx) case usermeta.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case usermeta.FieldVersion: return m.OldVersion(ctx) case usermeta.FieldUserID: return m.OldUserID(ctx) case usermeta.FieldKey: return m.OldKey(ctx) case usermeta.FieldValue: return m.OldValue(ctx) } return nil, fmt.Errorf("unknown UserMeta 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 *UserMetaMutation) SetField(name string, value ent.Value) error { switch name { case usermeta.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 usermeta.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 usermeta.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVersion(v) return nil case usermeta.FieldUserID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case usermeta.FieldKey: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetKey(v) return nil case usermeta.FieldValue: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetValue(v) return nil } return fmt.Errorf("unknown UserMeta field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserMetaMutation) AddedFields() []string { var fields []string if m.addversion != nil { fields = append(fields, usermeta.FieldVersion) } 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 *UserMetaMutation) AddedField(name string) (ent.Value, bool) { switch name { case usermeta.FieldVersion: return m.AddedVersion() } 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 *UserMetaMutation) AddField(name string, value ent.Value) error { switch name { case usermeta.FieldVersion: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVersion(v) return nil } return fmt.Errorf("unknown UserMeta numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMetaMutation) ClearedFields() []string { var fields []string if m.FieldCleared(usermeta.FieldKey) { fields = append(fields, usermeta.FieldKey) } if m.FieldCleared(usermeta.FieldValue) { fields = append(fields, usermeta.FieldValue) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMetaMutation) 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 *UserMetaMutation) ClearField(name string) error { switch name { case usermeta.FieldKey: m.ClearKey() return nil case usermeta.FieldValue: m.ClearValue() return nil } return fmt.Errorf("unknown UserMeta 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 *UserMetaMutation) ResetField(name string) error { switch name { case usermeta.FieldCreatedAt: m.ResetCreatedAt() return nil case usermeta.FieldUpdatedAt: m.ResetUpdatedAt() return nil case usermeta.FieldVersion: m.ResetVersion() return nil case usermeta.FieldUserID: m.ResetUserID() return nil case usermeta.FieldKey: m.ResetKey() return nil case usermeta.FieldValue: m.ResetValue() return nil } return fmt.Errorf("unknown UserMeta field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMetaMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, usermeta.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserMetaMutation) AddedIDs(name string) []ent.Value { switch name { case usermeta.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 *UserMetaMutation) 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 *UserMetaMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMetaMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, usermeta.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserMetaMutation) EdgeCleared(name string) bool { switch name { case usermeta.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 *UserMetaMutation) ClearEdge(name string) error { switch name { case usermeta.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown UserMeta 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 *UserMetaMutation) ResetEdge(name string) error { switch name { case usermeta.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown UserMeta edge %s", name) } // UserSocialMutation represents an operation that mutates the UserSocial nodes in the graph. type UserSocialMutation struct { config op Op typ string id *int64 created_at *time.Time updated_at *time.Time provider *string access_token *string refresh_token *string uid *string open_id *string union_id *string key *string expires_in *uint64 addexpires_in *int64 user_profile *string clearedFields map[string]struct{} user *int64 cleareduser bool done bool oldValue func(context.Context) (*UserSocial, error) predicates []predicate.UserSocial } var _ ent.Mutation = (*UserSocialMutation)(nil) // usersocialOption allows management of the mutation configuration using functional options. type usersocialOption func(*UserSocialMutation) // newUserSocialMutation creates new mutation for the UserSocial entity. func newUserSocialMutation(c config, op Op, opts ...usersocialOption) *UserSocialMutation { m := &UserSocialMutation{ config: c, op: op, typ: TypeUserSocial, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserSocialID sets the ID field of the mutation. func withUserSocialID(id int64) usersocialOption { return func(m *UserSocialMutation) { var ( err error once sync.Once value *UserSocial ) m.oldValue = func(ctx context.Context) (*UserSocial, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserSocial.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserSocial sets the old UserSocial of the mutation. func withUserSocial(node *UserSocial) usersocialOption { return func(m *UserSocialMutation) { m.oldValue = func(context.Context) (*UserSocial, 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 UserSocialMutation) 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 UserSocialMutation) 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 UserSocial entities. func (m *UserSocialMutation) 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 *UserSocialMutation) 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 *UserSocialMutation) 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().UserSocial.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 *UserSocialMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserSocialMutation) 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 UserSocial entity. // If the UserSocial 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 *UserSocialMutation) 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 *UserSocialMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *UserSocialMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *UserSocialMutation) 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 UserSocial entity. // If the UserSocial 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 *UserSocialMutation) 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 *UserSocialMutation) ResetUpdatedAt() { m.updated_at = nil } // SetUserID sets the "user_id" field. func (m *UserSocialMutation) SetUserID(i int64) { m.user = &i } // UserID returns the value of the "user_id" field in the mutation. func (m *UserSocialMutation) UserID() (r int64, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *UserSocialMutation) ResetUserID() { m.user = nil } // SetProvider sets the "provider" field. func (m *UserSocialMutation) SetProvider(s string) { m.provider = &s } // Provider returns the value of the "provider" field in the mutation. func (m *UserSocialMutation) Provider() (r string, exists bool) { v := m.provider if v == nil { return } return *v, true } // OldProvider returns the old "provider" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldProvider(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProvider is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProvider requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProvider: %w", err) } return oldValue.Provider, nil } // ResetProvider resets all changes to the "provider" field. func (m *UserSocialMutation) ResetProvider() { m.provider = nil } // SetAccessToken sets the "access_token" field. func (m *UserSocialMutation) SetAccessToken(s string) { m.access_token = &s } // AccessToken returns the value of the "access_token" field in the mutation. func (m *UserSocialMutation) AccessToken() (r string, exists bool) { v := m.access_token if v == nil { return } return *v, true } // OldAccessToken returns the old "access_token" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldAccessToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAccessToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAccessToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAccessToken: %w", err) } return oldValue.AccessToken, nil } // ResetAccessToken resets all changes to the "access_token" field. func (m *UserSocialMutation) ResetAccessToken() { m.access_token = nil } // SetRefreshToken sets the "refresh_token" field. func (m *UserSocialMutation) SetRefreshToken(s string) { m.refresh_token = &s } // RefreshToken returns the value of the "refresh_token" field in the mutation. func (m *UserSocialMutation) RefreshToken() (r string, exists bool) { v := m.refresh_token if v == nil { return } return *v, true } // OldRefreshToken returns the old "refresh_token" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldRefreshToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRefreshToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRefreshToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRefreshToken: %w", err) } return oldValue.RefreshToken, nil } // ResetRefreshToken resets all changes to the "refresh_token" field. func (m *UserSocialMutation) ResetRefreshToken() { m.refresh_token = nil } // SetUID sets the "uid" field. func (m *UserSocialMutation) SetUID(s string) { m.uid = &s } // UID returns the value of the "uid" field in the mutation. func (m *UserSocialMutation) UID() (r string, exists bool) { v := m.uid if v == nil { return } return *v, true } // OldUID returns the old "uid" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldUID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUID: %w", err) } return oldValue.UID, nil } // ResetUID resets all changes to the "uid" field. func (m *UserSocialMutation) ResetUID() { m.uid = nil } // SetOpenID sets the "open_id" field. func (m *UserSocialMutation) SetOpenID(s string) { m.open_id = &s } // OpenID returns the value of the "open_id" field in the mutation. func (m *UserSocialMutation) OpenID() (r string, exists bool) { v := m.open_id if v == nil { return } return *v, true } // OldOpenID returns the old "open_id" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldOpenID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOpenID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOpenID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOpenID: %w", err) } return oldValue.OpenID, nil } // ResetOpenID resets all changes to the "open_id" field. func (m *UserSocialMutation) ResetOpenID() { m.open_id = nil } // SetUnionID sets the "union_id" field. func (m *UserSocialMutation) SetUnionID(s string) { m.union_id = &s } // UnionID returns the value of the "union_id" field in the mutation. func (m *UserSocialMutation) UnionID() (r string, exists bool) { v := m.union_id if v == nil { return } return *v, true } // OldUnionID returns the old "union_id" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldUnionID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUnionID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUnionID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUnionID: %w", err) } return oldValue.UnionID, nil } // ResetUnionID resets all changes to the "union_id" field. func (m *UserSocialMutation) ResetUnionID() { m.union_id = nil } // SetKey sets the "key" field. func (m *UserSocialMutation) SetKey(s string) { m.key = &s } // Key returns the value of the "key" field in the mutation. func (m *UserSocialMutation) Key() (r string, exists bool) { v := m.key if v == nil { return } return *v, true } // OldKey returns the old "key" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldKey requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldKey: %w", err) } return oldValue.Key, nil } // ResetKey resets all changes to the "key" field. func (m *UserSocialMutation) ResetKey() { m.key = nil } // SetExpiresIn sets the "expires_in" field. func (m *UserSocialMutation) SetExpiresIn(u uint64) { m.expires_in = &u m.addexpires_in = nil } // ExpiresIn returns the value of the "expires_in" field in the mutation. func (m *UserSocialMutation) ExpiresIn() (r uint64, exists bool) { v := m.expires_in if v == nil { return } return *v, true } // OldExpiresIn returns the old "expires_in" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldExpiresIn(ctx context.Context) (v uint64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldExpiresIn is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldExpiresIn requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldExpiresIn: %w", err) } return oldValue.ExpiresIn, nil } // AddExpiresIn adds u to the "expires_in" field. func (m *UserSocialMutation) AddExpiresIn(u int64) { if m.addexpires_in != nil { *m.addexpires_in += u } else { m.addexpires_in = &u } } // AddedExpiresIn returns the value that was added to the "expires_in" field in this mutation. func (m *UserSocialMutation) AddedExpiresIn() (r int64, exists bool) { v := m.addexpires_in if v == nil { return } return *v, true } // ResetExpiresIn resets all changes to the "expires_in" field. func (m *UserSocialMutation) ResetExpiresIn() { m.expires_in = nil m.addexpires_in = nil } // SetUserProfile sets the "user_profile" field. func (m *UserSocialMutation) SetUserProfile(s string) { m.user_profile = &s } // UserProfile returns the value of the "user_profile" field in the mutation. func (m *UserSocialMutation) UserProfile() (r string, exists bool) { v := m.user_profile if v == nil { return } return *v, true } // OldUserProfile returns the old "user_profile" field's value of the UserSocial entity. // If the UserSocial 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 *UserSocialMutation) OldUserProfile(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserProfile is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserProfile requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserProfile: %w", err) } return oldValue.UserProfile, nil } // ResetUserProfile resets all changes to the "user_profile" field. func (m *UserSocialMutation) ResetUserProfile() { m.user_profile = nil } // ClearUser clears the "user" edge to the User entity. func (m *UserSocialMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *UserSocialMutation) UserCleared() bool { return m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *UserSocialMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *UserSocialMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the UserSocialMutation builder. func (m *UserSocialMutation) Where(ps ...predicate.UserSocial) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserSocialMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserSocialMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserSocial, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserSocialMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserSocialMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserSocial). func (m *UserSocialMutation) 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 *UserSocialMutation) Fields() []string { fields := make([]string, 0, 12) if m.created_at != nil { fields = append(fields, usersocial.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, usersocial.FieldUpdatedAt) } if m.user != nil { fields = append(fields, usersocial.FieldUserID) } if m.provider != nil { fields = append(fields, usersocial.FieldProvider) } if m.access_token != nil { fields = append(fields, usersocial.FieldAccessToken) } if m.refresh_token != nil { fields = append(fields, usersocial.FieldRefreshToken) } if m.uid != nil { fields = append(fields, usersocial.FieldUID) } if m.open_id != nil { fields = append(fields, usersocial.FieldOpenID) } if m.union_id != nil { fields = append(fields, usersocial.FieldUnionID) } if m.key != nil { fields = append(fields, usersocial.FieldKey) } if m.expires_in != nil { fields = append(fields, usersocial.FieldExpiresIn) } if m.user_profile != nil { fields = append(fields, usersocial.FieldUserProfile) } 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 *UserSocialMutation) Field(name string) (ent.Value, bool) { switch name { case usersocial.FieldCreatedAt: return m.CreatedAt() case usersocial.FieldUpdatedAt: return m.UpdatedAt() case usersocial.FieldUserID: return m.UserID() case usersocial.FieldProvider: return m.Provider() case usersocial.FieldAccessToken: return m.AccessToken() case usersocial.FieldRefreshToken: return m.RefreshToken() case usersocial.FieldUID: return m.UID() case usersocial.FieldOpenID: return m.OpenID() case usersocial.FieldUnionID: return m.UnionID() case usersocial.FieldKey: return m.Key() case usersocial.FieldExpiresIn: return m.ExpiresIn() case usersocial.FieldUserProfile: return m.UserProfile() } 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 *UserSocialMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case usersocial.FieldCreatedAt: return m.OldCreatedAt(ctx) case usersocial.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case usersocial.FieldUserID: return m.OldUserID(ctx) case usersocial.FieldProvider: return m.OldProvider(ctx) case usersocial.FieldAccessToken: return m.OldAccessToken(ctx) case usersocial.FieldRefreshToken: return m.OldRefreshToken(ctx) case usersocial.FieldUID: return m.OldUID(ctx) case usersocial.FieldOpenID: return m.OldOpenID(ctx) case usersocial.FieldUnionID: return m.OldUnionID(ctx) case usersocial.FieldKey: return m.OldKey(ctx) case usersocial.FieldExpiresIn: return m.OldExpiresIn(ctx) case usersocial.FieldUserProfile: return m.OldUserProfile(ctx) } return nil, fmt.Errorf("unknown UserSocial 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 *UserSocialMutation) SetField(name string, value ent.Value) error { switch name { case usersocial.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 usersocial.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 usersocial.FieldUserID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case usersocial.FieldProvider: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProvider(v) return nil case usersocial.FieldAccessToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAccessToken(v) return nil case usersocial.FieldRefreshToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRefreshToken(v) return nil case usersocial.FieldUID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUID(v) return nil case usersocial.FieldOpenID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOpenID(v) return nil case usersocial.FieldUnionID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUnionID(v) return nil case usersocial.FieldKey: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetKey(v) return nil case usersocial.FieldExpiresIn: v, ok := value.(uint64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetExpiresIn(v) return nil case usersocial.FieldUserProfile: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserProfile(v) return nil } return fmt.Errorf("unknown UserSocial field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserSocialMutation) AddedFields() []string { var fields []string if m.addexpires_in != nil { fields = append(fields, usersocial.FieldExpiresIn) } 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 *UserSocialMutation) AddedField(name string) (ent.Value, bool) { switch name { case usersocial.FieldExpiresIn: return m.AddedExpiresIn() } 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 *UserSocialMutation) AddField(name string, value ent.Value) error { switch name { case usersocial.FieldExpiresIn: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddExpiresIn(v) return nil } return fmt.Errorf("unknown UserSocial numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserSocialMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserSocialMutation) 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 *UserSocialMutation) ClearField(name string) error { return fmt.Errorf("unknown UserSocial 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 *UserSocialMutation) ResetField(name string) error { switch name { case usersocial.FieldCreatedAt: m.ResetCreatedAt() return nil case usersocial.FieldUpdatedAt: m.ResetUpdatedAt() return nil case usersocial.FieldUserID: m.ResetUserID() return nil case usersocial.FieldProvider: m.ResetProvider() return nil case usersocial.FieldAccessToken: m.ResetAccessToken() return nil case usersocial.FieldRefreshToken: m.ResetRefreshToken() return nil case usersocial.FieldUID: m.ResetUID() return nil case usersocial.FieldOpenID: m.ResetOpenID() return nil case usersocial.FieldUnionID: m.ResetUnionID() return nil case usersocial.FieldKey: m.ResetKey() return nil case usersocial.FieldExpiresIn: m.ResetExpiresIn() return nil case usersocial.FieldUserProfile: m.ResetUserProfile() return nil } return fmt.Errorf("unknown UserSocial field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserSocialMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, usersocial.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserSocialMutation) AddedIDs(name string) []ent.Value { switch name { case usersocial.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 *UserSocialMutation) 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 *UserSocialMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserSocialMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, usersocial.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserSocialMutation) EdgeCleared(name string) bool { switch name { case usersocial.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 *UserSocialMutation) ClearEdge(name string) error { switch name { case usersocial.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown UserSocial 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 *UserSocialMutation) ResetEdge(name string) error { switch name { case usersocial.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown UserSocial edge %s", name) }