// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/xmdhs/authlib-skin/db/ent/predicate" "github.com/xmdhs/authlib-skin/db/ent/skin" "github.com/xmdhs/authlib-skin/db/ent/user" "github.com/xmdhs/authlib-skin/db/ent/userprofile" "github.com/xmdhs/authlib-skin/db/ent/usertoken" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeSkin = "Skin" TypeUser = "User" TypeUserProfile = "UserProfile" TypeUserToken = "UserToken" ) // SkinMutation represents an operation that mutates the Skin nodes in the graph. type SkinMutation struct { config op Op typ string id *int skin_hash *string _type *uint8 add_type *int8 variant *string clearedFields map[string]struct{} created_user *int clearedcreated_user bool done bool oldValue func(context.Context) (*Skin, error) predicates []predicate.Skin } var _ ent.Mutation = (*SkinMutation)(nil) // skinOption allows management of the mutation configuration using functional options. type skinOption func(*SkinMutation) // newSkinMutation creates new mutation for the Skin entity. func newSkinMutation(c config, op Op, opts ...skinOption) *SkinMutation { m := &SkinMutation{ config: c, op: op, typ: TypeSkin, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSkinID sets the ID field of the mutation. func withSkinID(id int) skinOption { return func(m *SkinMutation) { var ( err error once sync.Once value *Skin ) m.oldValue = func(ctx context.Context) (*Skin, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Skin.Get(ctx, id) } }) return value, err } m.id = &id } } // withSkin sets the old Skin of the mutation. func withSkin(node *Skin) skinOption { return func(m *SkinMutation) { m.oldValue = func(context.Context) (*Skin, 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 SkinMutation) 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 SkinMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *SkinMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *SkinMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Skin.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetSkinHash sets the "skin_hash" field. func (m *SkinMutation) SetSkinHash(s string) { m.skin_hash = &s } // SkinHash returns the value of the "skin_hash" field in the mutation. func (m *SkinMutation) SkinHash() (r string, exists bool) { v := m.skin_hash if v == nil { return } return *v, true } // OldSkinHash returns the old "skin_hash" field's value of the Skin entity. // If the Skin 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 *SkinMutation) OldSkinHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSkinHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSkinHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSkinHash: %w", err) } return oldValue.SkinHash, nil } // ResetSkinHash resets all changes to the "skin_hash" field. func (m *SkinMutation) ResetSkinHash() { m.skin_hash = nil } // SetType sets the "type" field. func (m *SkinMutation) SetType(u uint8) { m._type = &u m.add_type = nil } // GetType returns the value of the "type" field in the mutation. func (m *SkinMutation) GetType() (r uint8, exists bool) { v := m._type if v == nil { return } return *v, true } // OldType returns the old "type" field's value of the Skin entity. // If the Skin 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 *SkinMutation) OldType(ctx context.Context) (v uint8, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldType: %w", err) } return oldValue.Type, nil } // AddType adds u to the "type" field. func (m *SkinMutation) AddType(u int8) { if m.add_type != nil { *m.add_type += u } else { m.add_type = &u } } // AddedType returns the value that was added to the "type" field in this mutation. func (m *SkinMutation) AddedType() (r int8, exists bool) { v := m.add_type if v == nil { return } return *v, true } // ResetType resets all changes to the "type" field. func (m *SkinMutation) ResetType() { m._type = nil m.add_type = nil } // SetVariant sets the "variant" field. func (m *SkinMutation) SetVariant(s string) { m.variant = &s } // Variant returns the value of the "variant" field in the mutation. func (m *SkinMutation) Variant() (r string, exists bool) { v := m.variant if v == nil { return } return *v, true } // OldVariant returns the old "variant" field's value of the Skin entity. // If the Skin 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 *SkinMutation) OldVariant(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVariant is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVariant requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVariant: %w", err) } return oldValue.Variant, nil } // ResetVariant resets all changes to the "variant" field. func (m *SkinMutation) ResetVariant() { m.variant = nil } // SetCreatedUserID sets the "created_user" edge to the User entity by id. func (m *SkinMutation) SetCreatedUserID(id int) { m.created_user = &id } // ClearCreatedUser clears the "created_user" edge to the User entity. func (m *SkinMutation) ClearCreatedUser() { m.clearedcreated_user = true } // CreatedUserCleared reports if the "created_user" edge to the User entity was cleared. func (m *SkinMutation) CreatedUserCleared() bool { return m.clearedcreated_user } // CreatedUserID returns the "created_user" edge ID in the mutation. func (m *SkinMutation) CreatedUserID() (id int, exists bool) { if m.created_user != nil { return *m.created_user, true } return } // CreatedUserIDs returns the "created_user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // CreatedUserID instead. It exists only for internal usage by the builders. func (m *SkinMutation) CreatedUserIDs() (ids []int) { if id := m.created_user; id != nil { ids = append(ids, *id) } return } // ResetCreatedUser resets all changes to the "created_user" edge. func (m *SkinMutation) ResetCreatedUser() { m.created_user = nil m.clearedcreated_user = false } // Where appends a list predicates to the SkinMutation builder. func (m *SkinMutation) Where(ps ...predicate.Skin) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SkinMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SkinMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Skin, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SkinMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SkinMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Skin). func (m *SkinMutation) 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 *SkinMutation) Fields() []string { fields := make([]string, 0, 3) if m.skin_hash != nil { fields = append(fields, skin.FieldSkinHash) } if m._type != nil { fields = append(fields, skin.FieldType) } if m.variant != nil { fields = append(fields, skin.FieldVariant) } 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 *SkinMutation) Field(name string) (ent.Value, bool) { switch name { case skin.FieldSkinHash: return m.SkinHash() case skin.FieldType: return m.GetType() case skin.FieldVariant: return m.Variant() } 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 *SkinMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case skin.FieldSkinHash: return m.OldSkinHash(ctx) case skin.FieldType: return m.OldType(ctx) case skin.FieldVariant: return m.OldVariant(ctx) } return nil, fmt.Errorf("unknown Skin 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 *SkinMutation) SetField(name string, value ent.Value) error { switch name { case skin.FieldSkinHash: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSkinHash(v) return nil case skin.FieldType: v, ok := value.(uint8) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetType(v) return nil case skin.FieldVariant: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVariant(v) return nil } return fmt.Errorf("unknown Skin field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SkinMutation) AddedFields() []string { var fields []string if m.add_type != nil { fields = append(fields, skin.FieldType) } 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 *SkinMutation) AddedField(name string) (ent.Value, bool) { switch name { case skin.FieldType: return m.AddedType() } 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 *SkinMutation) AddField(name string, value ent.Value) error { switch name { case skin.FieldType: v, ok := value.(int8) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddType(v) return nil } return fmt.Errorf("unknown Skin numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SkinMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SkinMutation) 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 *SkinMutation) ClearField(name string) error { return fmt.Errorf("unknown Skin 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 *SkinMutation) ResetField(name string) error { switch name { case skin.FieldSkinHash: m.ResetSkinHash() return nil case skin.FieldType: m.ResetType() return nil case skin.FieldVariant: m.ResetVariant() return nil } return fmt.Errorf("unknown Skin field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SkinMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.created_user != nil { edges = append(edges, skin.EdgeCreatedUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *SkinMutation) AddedIDs(name string) []ent.Value { switch name { case skin.EdgeCreatedUser: if id := m.created_user; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SkinMutation) 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 *SkinMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SkinMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedcreated_user { edges = append(edges, skin.EdgeCreatedUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *SkinMutation) EdgeCleared(name string) bool { switch name { case skin.EdgeCreatedUser: return m.clearedcreated_user } 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 *SkinMutation) ClearEdge(name string) error { switch name { case skin.EdgeCreatedUser: m.ClearCreatedUser() return nil } return fmt.Errorf("unknown Skin 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 *SkinMutation) ResetEdge(name string) error { switch name { case skin.EdgeCreatedUser: m.ResetCreatedUser() return nil } return fmt.Errorf("unknown Skin edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config op Op typ string id *int email *string password *string salt *string reg_ip *string state *int addstate *int reg_time *int64 addreg_time *int64 clearedFields map[string]struct{} created_skin map[int]struct{} removedcreated_skin map[int]struct{} clearedcreated_skin bool profile *int clearedprofile bool token *int clearedtoken bool skin *int clearedskin 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 int) 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 } // 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 int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *UserMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().User.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetEmail sets the "email" field. func (m *UserMutation) SetEmail(s string) { m.email = &s } // Email returns the value of the "email" field in the mutation. func (m *UserMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old "email" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmail: %w", err) } return oldValue.Email, nil } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil } // 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 } // SetSalt sets the "salt" field. func (m *UserMutation) SetSalt(s string) { m.salt = &s } // Salt returns the value of the "salt" field in the mutation. func (m *UserMutation) Salt() (r string, exists bool) { v := m.salt if v == nil { return } return *v, true } // OldSalt returns the old "salt" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldSalt(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSalt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSalt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSalt: %w", err) } return oldValue.Salt, nil } // ResetSalt resets all changes to the "salt" field. func (m *UserMutation) ResetSalt() { m.salt = nil } // SetRegIP sets the "reg_ip" field. func (m *UserMutation) SetRegIP(s string) { m.reg_ip = &s } // RegIP returns the value of the "reg_ip" field in the mutation. func (m *UserMutation) RegIP() (r string, exists bool) { v := m.reg_ip if v == nil { return } return *v, true } // OldRegIP returns the old "reg_ip" 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) OldRegIP(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRegIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRegIP requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRegIP: %w", err) } return oldValue.RegIP, nil } // ResetRegIP resets all changes to the "reg_ip" field. func (m *UserMutation) ResetRegIP() { m.reg_ip = nil } // SetState sets the "state" field. func (m *UserMutation) SetState(i int) { m.state = &i m.addstate = nil } // State returns the value of the "state" field in the mutation. func (m *UserMutation) State() (r int, exists bool) { v := m.state if v == nil { return } return *v, true } // OldState returns the old "state" 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) OldState(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldState is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldState requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldState: %w", err) } return oldValue.State, nil } // AddState adds i to the "state" field. func (m *UserMutation) AddState(i int) { if m.addstate != nil { *m.addstate += i } else { m.addstate = &i } } // AddedState returns the value that was added to the "state" field in this mutation. func (m *UserMutation) AddedState() (r int, exists bool) { v := m.addstate if v == nil { return } return *v, true } // ResetState resets all changes to the "state" field. func (m *UserMutation) ResetState() { m.state = nil m.addstate = nil } // SetRegTime sets the "reg_time" field. func (m *UserMutation) SetRegTime(i int64) { m.reg_time = &i m.addreg_time = nil } // RegTime returns the value of the "reg_time" field in the mutation. func (m *UserMutation) RegTime() (r int64, exists bool) { v := m.reg_time if v == nil { return } return *v, true } // OldRegTime returns the old "reg_time" 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) OldRegTime(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRegTime is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRegTime requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRegTime: %w", err) } return oldValue.RegTime, nil } // AddRegTime adds i to the "reg_time" field. func (m *UserMutation) AddRegTime(i int64) { if m.addreg_time != nil { *m.addreg_time += i } else { m.addreg_time = &i } } // AddedRegTime returns the value that was added to the "reg_time" field in this mutation. func (m *UserMutation) AddedRegTime() (r int64, exists bool) { v := m.addreg_time if v == nil { return } return *v, true } // ResetRegTime resets all changes to the "reg_time" field. func (m *UserMutation) ResetRegTime() { m.reg_time = nil m.addreg_time = nil } // AddCreatedSkinIDs adds the "created_skin" edge to the Skin entity by ids. func (m *UserMutation) AddCreatedSkinIDs(ids ...int) { if m.created_skin == nil { m.created_skin = make(map[int]struct{}) } for i := range ids { m.created_skin[ids[i]] = struct{}{} } } // ClearCreatedSkin clears the "created_skin" edge to the Skin entity. func (m *UserMutation) ClearCreatedSkin() { m.clearedcreated_skin = true } // CreatedSkinCleared reports if the "created_skin" edge to the Skin entity was cleared. func (m *UserMutation) CreatedSkinCleared() bool { return m.clearedcreated_skin } // RemoveCreatedSkinIDs removes the "created_skin" edge to the Skin entity by IDs. func (m *UserMutation) RemoveCreatedSkinIDs(ids ...int) { if m.removedcreated_skin == nil { m.removedcreated_skin = make(map[int]struct{}) } for i := range ids { delete(m.created_skin, ids[i]) m.removedcreated_skin[ids[i]] = struct{}{} } } // RemovedCreatedSkin returns the removed IDs of the "created_skin" edge to the Skin entity. func (m *UserMutation) RemovedCreatedSkinIDs() (ids []int) { for id := range m.removedcreated_skin { ids = append(ids, id) } return } // CreatedSkinIDs returns the "created_skin" edge IDs in the mutation. func (m *UserMutation) CreatedSkinIDs() (ids []int) { for id := range m.created_skin { ids = append(ids, id) } return } // ResetCreatedSkin resets all changes to the "created_skin" edge. func (m *UserMutation) ResetCreatedSkin() { m.created_skin = nil m.clearedcreated_skin = false m.removedcreated_skin = nil } // SetProfileID sets the "profile" edge to the UserProfile entity by id. func (m *UserMutation) SetProfileID(id int) { m.profile = &id } // ClearProfile clears the "profile" edge to the UserProfile entity. func (m *UserMutation) ClearProfile() { m.clearedprofile = true } // ProfileCleared reports if the "profile" edge to the UserProfile entity was cleared. func (m *UserMutation) ProfileCleared() bool { return m.clearedprofile } // ProfileID returns the "profile" edge ID in the mutation. func (m *UserMutation) ProfileID() (id int, exists bool) { if m.profile != nil { return *m.profile, true } return } // ProfileIDs returns the "profile" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ProfileID instead. It exists only for internal usage by the builders. func (m *UserMutation) ProfileIDs() (ids []int) { if id := m.profile; id != nil { ids = append(ids, *id) } return } // ResetProfile resets all changes to the "profile" edge. func (m *UserMutation) ResetProfile() { m.profile = nil m.clearedprofile = false } // SetTokenID sets the "token" edge to the UserToken entity by id. func (m *UserMutation) SetTokenID(id int) { m.token = &id } // ClearToken clears the "token" edge to the UserToken entity. func (m *UserMutation) ClearToken() { m.clearedtoken = true } // TokenCleared reports if the "token" edge to the UserToken entity was cleared. func (m *UserMutation) TokenCleared() bool { return m.clearedtoken } // TokenID returns the "token" edge ID in the mutation. func (m *UserMutation) TokenID() (id int, exists bool) { if m.token != nil { return *m.token, true } return } // TokenIDs returns the "token" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // TokenID instead. It exists only for internal usage by the builders. func (m *UserMutation) TokenIDs() (ids []int) { if id := m.token; id != nil { ids = append(ids, *id) } return } // ResetToken resets all changes to the "token" edge. func (m *UserMutation) ResetToken() { m.token = nil m.clearedtoken = false } // SetSkinID sets the "skin" edge to the Skin entity by id. func (m *UserMutation) SetSkinID(id int) { m.skin = &id } // ClearSkin clears the "skin" edge to the Skin entity. func (m *UserMutation) ClearSkin() { m.clearedskin = true } // SkinCleared reports if the "skin" edge to the Skin entity was cleared. func (m *UserMutation) SkinCleared() bool { return m.clearedskin } // SkinID returns the "skin" edge ID in the mutation. func (m *UserMutation) SkinID() (id int, exists bool) { if m.skin != nil { return *m.skin, true } return } // SkinIDs returns the "skin" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SkinID instead. It exists only for internal usage by the builders. func (m *UserMutation) SkinIDs() (ids []int) { if id := m.skin; id != nil { ids = append(ids, *id) } return } // ResetSkin resets all changes to the "skin" edge. func (m *UserMutation) ResetSkin() { m.skin = nil m.clearedskin = 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, 6) if m.email != nil { fields = append(fields, user.FieldEmail) } if m.password != nil { fields = append(fields, user.FieldPassword) } if m.salt != nil { fields = append(fields, user.FieldSalt) } if m.reg_ip != nil { fields = append(fields, user.FieldRegIP) } if m.state != nil { fields = append(fields, user.FieldState) } if m.reg_time != nil { fields = append(fields, user.FieldRegTime) } 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.FieldEmail: return m.Email() case user.FieldPassword: return m.Password() case user.FieldSalt: return m.Salt() case user.FieldRegIP: return m.RegIP() case user.FieldState: return m.State() case user.FieldRegTime: return m.RegTime() } 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.FieldEmail: return m.OldEmail(ctx) case user.FieldPassword: return m.OldPassword(ctx) case user.FieldSalt: return m.OldSalt(ctx) case user.FieldRegIP: return m.OldRegIP(ctx) case user.FieldState: return m.OldState(ctx) case user.FieldRegTime: return m.OldRegTime(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.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.FieldSalt: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSalt(v) return nil case user.FieldRegIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRegIP(v) return nil case user.FieldState: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetState(v) return nil case user.FieldRegTime: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRegTime(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.addstate != nil { fields = append(fields, user.FieldState) } if m.addreg_time != nil { fields = append(fields, user.FieldRegTime) } 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.FieldState: return m.AddedState() case user.FieldRegTime: return m.AddedRegTime() } 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.FieldState: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddState(v) return nil case user.FieldRegTime: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddRegTime(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 { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { return fmt.Errorf("unknown User nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *UserMutation) ResetField(name string) error { switch name { case user.FieldEmail: m.ResetEmail() return nil case user.FieldPassword: m.ResetPassword() return nil case user.FieldSalt: m.ResetSalt() return nil case user.FieldRegIP: m.ResetRegIP() return nil case user.FieldState: m.ResetState() return nil case user.FieldRegTime: m.ResetRegTime() 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, 4) if m.created_skin != nil { edges = append(edges, user.EdgeCreatedSkin) } if m.profile != nil { edges = append(edges, user.EdgeProfile) } if m.token != nil { edges = append(edges, user.EdgeToken) } if m.skin != nil { edges = append(edges, user.EdgeSkin) } 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.EdgeCreatedSkin: ids := make([]ent.Value, 0, len(m.created_skin)) for id := range m.created_skin { ids = append(ids, id) } return ids case user.EdgeProfile: if id := m.profile; id != nil { return []ent.Value{*id} } case user.EdgeToken: if id := m.token; id != nil { return []ent.Value{*id} } case user.EdgeSkin: if id := m.skin; 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, 4) if m.removedcreated_skin != nil { edges = append(edges, user.EdgeCreatedSkin) } 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.EdgeCreatedSkin: ids := make([]ent.Value, 0, len(m.removedcreated_skin)) for id := range m.removedcreated_skin { 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, 4) if m.clearedcreated_skin { edges = append(edges, user.EdgeCreatedSkin) } if m.clearedprofile { edges = append(edges, user.EdgeProfile) } if m.clearedtoken { edges = append(edges, user.EdgeToken) } if m.clearedskin { edges = append(edges, user.EdgeSkin) } 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.EdgeCreatedSkin: return m.clearedcreated_skin case user.EdgeProfile: return m.clearedprofile case user.EdgeToken: return m.clearedtoken case user.EdgeSkin: return m.clearedskin } 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.EdgeProfile: m.ClearProfile() return nil case user.EdgeToken: m.ClearToken() return nil case user.EdgeSkin: m.ClearSkin() 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.EdgeCreatedSkin: m.ResetCreatedSkin() return nil case user.EdgeProfile: m.ResetProfile() return nil case user.EdgeToken: m.ResetToken() return nil case user.EdgeSkin: m.ResetSkin() return nil } return fmt.Errorf("unknown User edge %s", name) } // UserProfileMutation represents an operation that mutates the UserProfile nodes in the graph. type UserProfileMutation struct { config op Op typ string id *int name *string uuid *string clearedFields map[string]struct{} user *int cleareduser bool done bool oldValue func(context.Context) (*UserProfile, error) predicates []predicate.UserProfile } var _ ent.Mutation = (*UserProfileMutation)(nil) // userprofileOption allows management of the mutation configuration using functional options. type userprofileOption func(*UserProfileMutation) // newUserProfileMutation creates new mutation for the UserProfile entity. func newUserProfileMutation(c config, op Op, opts ...userprofileOption) *UserProfileMutation { m := &UserProfileMutation{ config: c, op: op, typ: TypeUserProfile, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserProfileID sets the ID field of the mutation. func withUserProfileID(id int) userprofileOption { return func(m *UserProfileMutation) { var ( err error once sync.Once value *UserProfile ) m.oldValue = func(ctx context.Context) (*UserProfile, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserProfile.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserProfile sets the old UserProfile of the mutation. func withUserProfile(node *UserProfile) userprofileOption { return func(m *UserProfileMutation) { m.oldValue = func(context.Context) (*UserProfile, 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 UserProfileMutation) 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 UserProfileMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *UserProfileMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *UserProfileMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().UserProfile.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *UserProfileMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *UserProfileMutation) 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 UserProfile entity. // If the UserProfile 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 *UserProfileMutation) 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 *UserProfileMutation) ResetName() { m.name = nil } // SetUUID sets the "uuid" field. func (m *UserProfileMutation) SetUUID(s string) { m.uuid = &s } // UUID returns the value of the "uuid" field in the mutation. func (m *UserProfileMutation) UUID() (r string, exists bool) { v := m.uuid if v == nil { return } return *v, true } // OldUUID returns the old "uuid" field's value of the UserProfile entity. // If the UserProfile 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 *UserProfileMutation) OldUUID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUUID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUUID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUUID: %w", err) } return oldValue.UUID, nil } // ResetUUID resets all changes to the "uuid" field. func (m *UserProfileMutation) ResetUUID() { m.uuid = nil } // SetUserID sets the "user" edge to the User entity by id. func (m *UserProfileMutation) SetUserID(id int) { m.user = &id } // ClearUser clears the "user" edge to the User entity. func (m *UserProfileMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *UserProfileMutation) UserCleared() bool { return m.cleareduser } // UserID returns the "user" edge ID in the mutation. func (m *UserProfileMutation) UserID() (id int, exists bool) { if m.user != nil { return *m.user, true } return } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *UserProfileMutation) UserIDs() (ids []int) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *UserProfileMutation) ResetUser() { m.user = nil m.cleareduser = false } // Where appends a list predicates to the UserProfileMutation builder. func (m *UserProfileMutation) Where(ps ...predicate.UserProfile) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserProfileMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserProfileMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserProfile, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserProfileMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserProfileMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserProfile). func (m *UserProfileMutation) 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 *UserProfileMutation) Fields() []string { fields := make([]string, 0, 2) if m.name != nil { fields = append(fields, userprofile.FieldName) } if m.uuid != nil { fields = append(fields, userprofile.FieldUUID) } 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 *UserProfileMutation) Field(name string) (ent.Value, bool) { switch name { case userprofile.FieldName: return m.Name() case userprofile.FieldUUID: return m.UUID() } 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 *UserProfileMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case userprofile.FieldName: return m.OldName(ctx) case userprofile.FieldUUID: return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown UserProfile 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 *UserProfileMutation) SetField(name string, value ent.Value) error { switch name { case userprofile.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case userprofile.FieldUUID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUUID(v) return nil } return fmt.Errorf("unknown UserProfile field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserProfileMutation) 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 *UserProfileMutation) 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 *UserProfileMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown UserProfile numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserProfileMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserProfileMutation) 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 *UserProfileMutation) ClearField(name string) error { return fmt.Errorf("unknown UserProfile 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 *UserProfileMutation) ResetField(name string) error { switch name { case userprofile.FieldName: m.ResetName() return nil case userprofile.FieldUUID: m.ResetUUID() return nil } return fmt.Errorf("unknown UserProfile field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserProfileMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.user != nil { edges = append(edges, userprofile.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserProfileMutation) AddedIDs(name string) []ent.Value { switch name { case userprofile.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 *UserProfileMutation) 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 *UserProfileMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserProfileMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareduser { edges = append(edges, userprofile.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserProfileMutation) EdgeCleared(name string) bool { switch name { case userprofile.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 *UserProfileMutation) ClearEdge(name string) error { switch name { case userprofile.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown UserProfile 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 *UserProfileMutation) ResetEdge(name string) error { switch name { case userprofile.EdgeUser: m.ResetUser() return nil } return fmt.Errorf("unknown UserProfile edge %s", name) } // UserTokenMutation represents an operation that mutates the UserToken nodes in the graph. type UserTokenMutation struct { config op Op typ string id *int token_id *uint64 addtoken_id *int64 uuid *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*UserToken, error) predicates []predicate.UserToken } var _ ent.Mutation = (*UserTokenMutation)(nil) // usertokenOption allows management of the mutation configuration using functional options. type usertokenOption func(*UserTokenMutation) // newUserTokenMutation creates new mutation for the UserToken entity. func newUserTokenMutation(c config, op Op, opts ...usertokenOption) *UserTokenMutation { m := &UserTokenMutation{ config: c, op: op, typ: TypeUserToken, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserTokenID sets the ID field of the mutation. func withUserTokenID(id int) usertokenOption { return func(m *UserTokenMutation) { var ( err error once sync.Once value *UserToken ) m.oldValue = func(ctx context.Context) (*UserToken, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserToken.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserToken sets the old UserToken of the mutation. func withUserToken(node *UserToken) usertokenOption { return func(m *UserTokenMutation) { m.oldValue = func(context.Context) (*UserToken, 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 UserTokenMutation) 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 UserTokenMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *UserTokenMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *UserTokenMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().UserToken.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetTokenID sets the "token_id" field. func (m *UserTokenMutation) SetTokenID(u uint64) { m.token_id = &u m.addtoken_id = nil } // TokenID returns the value of the "token_id" field in the mutation. func (m *UserTokenMutation) TokenID() (r uint64, exists bool) { v := m.token_id if v == nil { return } return *v, true } // OldTokenID returns the old "token_id" field's value of the UserToken entity. // If the UserToken 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 *UserTokenMutation) OldTokenID(ctx context.Context) (v uint64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTokenID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTokenID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTokenID: %w", err) } return oldValue.TokenID, nil } // AddTokenID adds u to the "token_id" field. func (m *UserTokenMutation) AddTokenID(u int64) { if m.addtoken_id != nil { *m.addtoken_id += u } else { m.addtoken_id = &u } } // AddedTokenID returns the value that was added to the "token_id" field in this mutation. func (m *UserTokenMutation) AddedTokenID() (r int64, exists bool) { v := m.addtoken_id if v == nil { return } return *v, true } // ResetTokenID resets all changes to the "token_id" field. func (m *UserTokenMutation) ResetTokenID() { m.token_id = nil m.addtoken_id = nil } // SetUUID sets the "uuid" field. func (m *UserTokenMutation) SetUUID(s string) { m.uuid = &s } // UUID returns the value of the "uuid" field in the mutation. func (m *UserTokenMutation) UUID() (r string, exists bool) { v := m.uuid if v == nil { return } return *v, true } // OldUUID returns the old "uuid" field's value of the UserToken entity. // If the UserToken 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 *UserTokenMutation) OldUUID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUUID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUUID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUUID: %w", err) } return oldValue.UUID, nil } // ResetUUID resets all changes to the "uuid" field. func (m *UserTokenMutation) ResetUUID() { m.uuid = nil } // Where appends a list predicates to the UserTokenMutation builder. func (m *UserTokenMutation) Where(ps ...predicate.UserToken) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserTokenMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserTokenMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserToken, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserTokenMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserTokenMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserToken). func (m *UserTokenMutation) 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 *UserTokenMutation) Fields() []string { fields := make([]string, 0, 2) if m.token_id != nil { fields = append(fields, usertoken.FieldTokenID) } if m.uuid != nil { fields = append(fields, usertoken.FieldUUID) } 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 *UserTokenMutation) Field(name string) (ent.Value, bool) { switch name { case usertoken.FieldTokenID: return m.TokenID() case usertoken.FieldUUID: return m.UUID() } 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 *UserTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case usertoken.FieldTokenID: return m.OldTokenID(ctx) case usertoken.FieldUUID: return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown UserToken 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 *UserTokenMutation) SetField(name string, value ent.Value) error { switch name { case usertoken.FieldTokenID: v, ok := value.(uint64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTokenID(v) return nil case usertoken.FieldUUID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUUID(v) return nil } return fmt.Errorf("unknown UserToken field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserTokenMutation) AddedFields() []string { var fields []string if m.addtoken_id != nil { fields = append(fields, usertoken.FieldTokenID) } 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 *UserTokenMutation) AddedField(name string) (ent.Value, bool) { switch name { case usertoken.FieldTokenID: return m.AddedTokenID() } 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 *UserTokenMutation) AddField(name string, value ent.Value) error { switch name { case usertoken.FieldTokenID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddTokenID(v) return nil } return fmt.Errorf("unknown UserToken numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserTokenMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserTokenMutation) 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 *UserTokenMutation) ClearField(name string) error { return fmt.Errorf("unknown UserToken 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 *UserTokenMutation) ResetField(name string) error { switch name { case usertoken.FieldTokenID: m.ResetTokenID() return nil case usertoken.FieldUUID: m.ResetUUID() return nil } return fmt.Errorf("unknown UserToken field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserTokenMutation) 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 *UserTokenMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserTokenMutation) 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 *UserTokenMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserTokenMutation) 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 *UserTokenMutation) 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 *UserTokenMutation) ClearEdge(name string) error { return fmt.Errorf("unknown UserToken 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 *UserTokenMutation) ResetEdge(name string) error { return fmt.Errorf("unknown UserToken edge %s", name) }