// Code generated by entc, DO NOT EDIT. package ent import ( "context" "fmt" "sync" "github.com/kallydev/privacy/ent/jdmodel" "github.com/kallydev/privacy/ent/predicate" "github.com/kallydev/privacy/ent/qqmodel" "github.com/kallydev/privacy/ent/sfmodel" "github.com/facebook/ent" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeJDModel = "JDModel" TypeQQModel = "QQModel" TypeSFModel = "SFModel" ) // JDModelMutation represents an operation that mutate the JDModels // nodes in the graph. type JDModelMutation struct { config op Op typ string id *int name *string nickname *string password *string email *string id_number *string phone_number *int64 addphone_number *int64 clearedFields map[string]struct{} done bool oldValue func(context.Context) (*JDModel, error) predicates []predicate.JDModel } var _ ent.Mutation = (*JDModelMutation)(nil) // jdmodelOption allows to manage the mutation configuration using functional options. type jdmodelOption func(*JDModelMutation) // newJDModelMutation creates new mutation for $n.Name. func newJDModelMutation(c config, op Op, opts ...jdmodelOption) *JDModelMutation { m := &JDModelMutation{ config: c, op: op, typ: TypeJDModel, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withJDModelID sets the id field of the mutation. func withJDModelID(id int) jdmodelOption { return func(m *JDModelMutation) { var ( err error once sync.Once value *JDModel ) m.oldValue = func(ctx context.Context) (*JDModel, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { value, err = m.Client().JDModel.Get(ctx, id) } }) return value, err } m.id = &id } } // withJDModel sets the old JDModel of the mutation. func withJDModel(node *JDModel) jdmodelOption { return func(m *JDModelMutation) { m.oldValue = func(context.Context) (*JDModel, 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 JDModelMutation) 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 JDModelMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("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 available only if it was provided to the builder. func (m *JDModelMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // SetName sets the name field. func (m *JDModelMutation) SetName(s string) { m.name = &s } // Name returns the name value in the mutation. func (m *JDModelMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old name value of the JDModel. // If the JDModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *JDModelMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldName is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 reset all changes of the "name" field. func (m *JDModelMutation) ResetName() { m.name = nil } // SetNickname sets the nickname field. func (m *JDModelMutation) SetNickname(s string) { m.nickname = &s } // Nickname returns the nickname value in the mutation. func (m *JDModelMutation) Nickname() (r string, exists bool) { v := m.nickname if v == nil { return } return *v, true } // OldNickname returns the old nickname value of the JDModel. // If the JDModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *JDModelMutation) OldNickname(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldNickname is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 } // ResetNickname reset all changes of the "nickname" field. func (m *JDModelMutation) ResetNickname() { m.nickname = nil } // SetPassword sets the password field. func (m *JDModelMutation) SetPassword(s string) { m.password = &s } // Password returns the password value in the mutation. func (m *JDModelMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old password value of the JDModel. // If the JDModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *JDModelMutation) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldPassword is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 reset all changes of the "password" field. func (m *JDModelMutation) ResetPassword() { m.password = nil } // SetEmail sets the email field. func (m *JDModelMutation) SetEmail(s string) { m.email = &s } // Email returns the email value in the mutation. func (m *JDModelMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old email value of the JDModel. // If the JDModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *JDModelMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldEmail is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 reset all changes of the "email" field. func (m *JDModelMutation) ResetEmail() { m.email = nil } // SetIDNumber sets the id_number field. func (m *JDModelMutation) SetIDNumber(s string) { m.id_number = &s } // IDNumber returns the id_number value in the mutation. func (m *JDModelMutation) IDNumber() (r string, exists bool) { v := m.id_number if v == nil { return } return *v, true } // OldIDNumber returns the old id_number value of the JDModel. // If the JDModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *JDModelMutation) OldIDNumber(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldIDNumber is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldIDNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIDNumber: %w", err) } return oldValue.IDNumber, nil } // ResetIDNumber reset all changes of the "id_number" field. func (m *JDModelMutation) ResetIDNumber() { m.id_number = nil } // SetPhoneNumber sets the phone_number field. func (m *JDModelMutation) SetPhoneNumber(i int64) { m.phone_number = &i m.addphone_number = nil } // PhoneNumber returns the phone_number value in the mutation. func (m *JDModelMutation) PhoneNumber() (r int64, exists bool) { v := m.phone_number if v == nil { return } return *v, true } // OldPhoneNumber returns the old phone_number value of the JDModel. // If the JDModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *JDModelMutation) OldPhoneNumber(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldPhoneNumber is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 } // AddPhoneNumber adds i to phone_number. func (m *JDModelMutation) AddPhoneNumber(i int64) { if m.addphone_number != nil { *m.addphone_number += i } else { m.addphone_number = &i } } // AddedPhoneNumber returns the value that was added to the phone_number field in this mutation. func (m *JDModelMutation) AddedPhoneNumber() (r int64, exists bool) { v := m.addphone_number if v == nil { return } return *v, true } // ResetPhoneNumber reset all changes of the "phone_number" field. func (m *JDModelMutation) ResetPhoneNumber() { m.phone_number = nil m.addphone_number = nil } // Op returns the operation name. func (m *JDModelMutation) Op() Op { return m.op } // Type returns the node type of this mutation (JDModel). func (m *JDModelMutation) 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 in/decremented, call AddedFields(). func (m *JDModelMutation) Fields() []string { fields := make([]string, 0, 6) if m.name != nil { fields = append(fields, jdmodel.FieldName) } if m.nickname != nil { fields = append(fields, jdmodel.FieldNickname) } if m.password != nil { fields = append(fields, jdmodel.FieldPassword) } if m.email != nil { fields = append(fields, jdmodel.FieldEmail) } if m.id_number != nil { fields = append(fields, jdmodel.FieldIDNumber) } if m.phone_number != nil { fields = append(fields, jdmodel.FieldPhoneNumber) } return fields } // Field returns the value of a field with the given name. // The second boolean value indicates that this field was // not set, or was not define in the schema. func (m *JDModelMutation) Field(name string) (ent.Value, bool) { switch name { case jdmodel.FieldName: return m.Name() case jdmodel.FieldNickname: return m.Nickname() case jdmodel.FieldPassword: return m.Password() case jdmodel.FieldEmail: return m.Email() case jdmodel.FieldIDNumber: return m.IDNumber() case jdmodel.FieldPhoneNumber: return m.PhoneNumber() } 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 was failed. func (m *JDModelMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case jdmodel.FieldName: return m.OldName(ctx) case jdmodel.FieldNickname: return m.OldNickname(ctx) case jdmodel.FieldPassword: return m.OldPassword(ctx) case jdmodel.FieldEmail: return m.OldEmail(ctx) case jdmodel.FieldIDNumber: return m.OldIDNumber(ctx) case jdmodel.FieldPhoneNumber: return m.OldPhoneNumber(ctx) } return nil, fmt.Errorf("unknown JDModel field %s", name) } // SetField sets the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. func (m *JDModelMutation) SetField(name string, value ent.Value) error { switch name { case jdmodel.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case jdmodel.FieldNickname: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNickname(v) return nil case jdmodel.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(v) return nil case jdmodel.FieldEmail: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmail(v) return nil case jdmodel.FieldIDNumber: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIDNumber(v) return nil case jdmodel.FieldPhoneNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhoneNumber(v) return nil } return fmt.Errorf("unknown JDModel field %s", name) } // AddedFields returns all numeric fields that were incremented // or decremented during this mutation. func (m *JDModelMutation) AddedFields() []string { var fields []string if m.addphone_number != nil { fields = append(fields, jdmodel.FieldPhoneNumber) } return fields } // AddedField returns the numeric value that was in/decremented // from a field with the given name. The second value indicates // that this field was not set, or was not define in the schema. func (m *JDModelMutation) AddedField(name string) (ent.Value, bool) { switch name { case jdmodel.FieldPhoneNumber: return m.AddedPhoneNumber() } return nil, false } // AddField adds the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. func (m *JDModelMutation) AddField(name string, value ent.Value) error { switch name { case jdmodel.FieldPhoneNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddPhoneNumber(v) return nil } return fmt.Errorf("unknown JDModel numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared // during this mutation. func (m *JDModelMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicates if this field was // cleared in this mutation. func (m *JDModelMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value for the given name. It returns an // error if the field is not defined in the schema. func (m *JDModelMutation) ClearField(name string) error { return fmt.Errorf("unknown JDModel nullable field %s", name) } // ResetField resets all changes in the mutation regarding the // given field name. It returns an error if the field is not // defined in the schema. func (m *JDModelMutation) ResetField(name string) error { switch name { case jdmodel.FieldName: m.ResetName() return nil case jdmodel.FieldNickname: m.ResetNickname() return nil case jdmodel.FieldPassword: m.ResetPassword() return nil case jdmodel.FieldEmail: m.ResetEmail() return nil case jdmodel.FieldIDNumber: m.ResetIDNumber() return nil case jdmodel.FieldPhoneNumber: m.ResetPhoneNumber() return nil } return fmt.Errorf("unknown JDModel field %s", name) } // AddedEdges returns all edge names that were set/added in this // mutation. func (m *JDModelMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all ids (to other nodes) that were added for // the given edge name. func (m *JDModelMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this // mutation. func (m *JDModelMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all ids (to other nodes) that were removed for // the given edge name. func (m *JDModelMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this // mutation. func (m *JDModelMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean indicates if this edge was // cleared in this mutation. func (m *JDModelMutation) EdgeCleared(name string) bool { return false } // ClearEdge clears the value for the given name. It returns an // error if the edge name is not defined in the schema. func (m *JDModelMutation) ClearEdge(name string) error { return fmt.Errorf("unknown JDModel unique edge %s", name) } // ResetEdge resets all changes in the mutation regarding the // given edge name. It returns an error if the edge is not // defined in the schema. func (m *JDModelMutation) ResetEdge(name string) error { return fmt.Errorf("unknown JDModel edge %s", name) } // QQModelMutation represents an operation that mutate the QQModels // nodes in the graph. type QQModelMutation struct { config op Op typ string id *int qq_number *int64 addqq_number *int64 phone_number *int64 addphone_number *int64 clearedFields map[string]struct{} done bool oldValue func(context.Context) (*QQModel, error) predicates []predicate.QQModel } var _ ent.Mutation = (*QQModelMutation)(nil) // qqmodelOption allows to manage the mutation configuration using functional options. type qqmodelOption func(*QQModelMutation) // newQQModelMutation creates new mutation for $n.Name. func newQQModelMutation(c config, op Op, opts ...qqmodelOption) *QQModelMutation { m := &QQModelMutation{ config: c, op: op, typ: TypeQQModel, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withQQModelID sets the id field of the mutation. func withQQModelID(id int) qqmodelOption { return func(m *QQModelMutation) { var ( err error once sync.Once value *QQModel ) m.oldValue = func(ctx context.Context) (*QQModel, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { value, err = m.Client().QQModel.Get(ctx, id) } }) return value, err } m.id = &id } } // withQQModel sets the old QQModel of the mutation. func withQQModel(node *QQModel) qqmodelOption { return func(m *QQModelMutation) { m.oldValue = func(context.Context) (*QQModel, 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 QQModelMutation) 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 QQModelMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("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 available only if it was provided to the builder. func (m *QQModelMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // SetQqNumber sets the qq_number field. func (m *QQModelMutation) SetQqNumber(i int64) { m.qq_number = &i m.addqq_number = nil } // QqNumber returns the qq_number value in the mutation. func (m *QQModelMutation) QqNumber() (r int64, exists bool) { v := m.qq_number if v == nil { return } return *v, true } // OldQqNumber returns the old qq_number value of the QQModel. // If the QQModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *QQModelMutation) OldQqNumber(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldQqNumber is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldQqNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldQqNumber: %w", err) } return oldValue.QqNumber, nil } // AddQqNumber adds i to qq_number. func (m *QQModelMutation) AddQqNumber(i int64) { if m.addqq_number != nil { *m.addqq_number += i } else { m.addqq_number = &i } } // AddedQqNumber returns the value that was added to the qq_number field in this mutation. func (m *QQModelMutation) AddedQqNumber() (r int64, exists bool) { v := m.addqq_number if v == nil { return } return *v, true } // ResetQqNumber reset all changes of the "qq_number" field. func (m *QQModelMutation) ResetQqNumber() { m.qq_number = nil m.addqq_number = nil } // SetPhoneNumber sets the phone_number field. func (m *QQModelMutation) SetPhoneNumber(i int64) { m.phone_number = &i m.addphone_number = nil } // PhoneNumber returns the phone_number value in the mutation. func (m *QQModelMutation) PhoneNumber() (r int64, exists bool) { v := m.phone_number if v == nil { return } return *v, true } // OldPhoneNumber returns the old phone_number value of the QQModel. // If the QQModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *QQModelMutation) OldPhoneNumber(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldPhoneNumber is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 } // AddPhoneNumber adds i to phone_number. func (m *QQModelMutation) AddPhoneNumber(i int64) { if m.addphone_number != nil { *m.addphone_number += i } else { m.addphone_number = &i } } // AddedPhoneNumber returns the value that was added to the phone_number field in this mutation. func (m *QQModelMutation) AddedPhoneNumber() (r int64, exists bool) { v := m.addphone_number if v == nil { return } return *v, true } // ResetPhoneNumber reset all changes of the "phone_number" field. func (m *QQModelMutation) ResetPhoneNumber() { m.phone_number = nil m.addphone_number = nil } // Op returns the operation name. func (m *QQModelMutation) Op() Op { return m.op } // Type returns the node type of this mutation (QQModel). func (m *QQModelMutation) 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 in/decremented, call AddedFields(). func (m *QQModelMutation) Fields() []string { fields := make([]string, 0, 2) if m.qq_number != nil { fields = append(fields, qqmodel.FieldQqNumber) } if m.phone_number != nil { fields = append(fields, qqmodel.FieldPhoneNumber) } return fields } // Field returns the value of a field with the given name. // The second boolean value indicates that this field was // not set, or was not define in the schema. func (m *QQModelMutation) Field(name string) (ent.Value, bool) { switch name { case qqmodel.FieldQqNumber: return m.QqNumber() case qqmodel.FieldPhoneNumber: return m.PhoneNumber() } 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 was failed. func (m *QQModelMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case qqmodel.FieldQqNumber: return m.OldQqNumber(ctx) case qqmodel.FieldPhoneNumber: return m.OldPhoneNumber(ctx) } return nil, fmt.Errorf("unknown QQModel field %s", name) } // SetField sets the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. func (m *QQModelMutation) SetField(name string, value ent.Value) error { switch name { case qqmodel.FieldQqNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetQqNumber(v) return nil case qqmodel.FieldPhoneNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhoneNumber(v) return nil } return fmt.Errorf("unknown QQModel field %s", name) } // AddedFields returns all numeric fields that were incremented // or decremented during this mutation. func (m *QQModelMutation) AddedFields() []string { var fields []string if m.addqq_number != nil { fields = append(fields, qqmodel.FieldQqNumber) } if m.addphone_number != nil { fields = append(fields, qqmodel.FieldPhoneNumber) } return fields } // AddedField returns the numeric value that was in/decremented // from a field with the given name. The second value indicates // that this field was not set, or was not define in the schema. func (m *QQModelMutation) AddedField(name string) (ent.Value, bool) { switch name { case qqmodel.FieldQqNumber: return m.AddedQqNumber() case qqmodel.FieldPhoneNumber: return m.AddedPhoneNumber() } return nil, false } // AddField adds the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. func (m *QQModelMutation) AddField(name string, value ent.Value) error { switch name { case qqmodel.FieldQqNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddQqNumber(v) return nil case qqmodel.FieldPhoneNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddPhoneNumber(v) return nil } return fmt.Errorf("unknown QQModel numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared // during this mutation. func (m *QQModelMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicates if this field was // cleared in this mutation. func (m *QQModelMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value for the given name. It returns an // error if the field is not defined in the schema. func (m *QQModelMutation) ClearField(name string) error { return fmt.Errorf("unknown QQModel nullable field %s", name) } // ResetField resets all changes in the mutation regarding the // given field name. It returns an error if the field is not // defined in the schema. func (m *QQModelMutation) ResetField(name string) error { switch name { case qqmodel.FieldQqNumber: m.ResetQqNumber() return nil case qqmodel.FieldPhoneNumber: m.ResetPhoneNumber() return nil } return fmt.Errorf("unknown QQModel field %s", name) } // AddedEdges returns all edge names that were set/added in this // mutation. func (m *QQModelMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all ids (to other nodes) that were added for // the given edge name. func (m *QQModelMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this // mutation. func (m *QQModelMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all ids (to other nodes) that were removed for // the given edge name. func (m *QQModelMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this // mutation. func (m *QQModelMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean indicates if this edge was // cleared in this mutation. func (m *QQModelMutation) EdgeCleared(name string) bool { return false } // ClearEdge clears the value for the given name. It returns an // error if the edge name is not defined in the schema. func (m *QQModelMutation) ClearEdge(name string) error { return fmt.Errorf("unknown QQModel unique edge %s", name) } // ResetEdge resets all changes in the mutation regarding the // given edge name. It returns an error if the edge is not // defined in the schema. func (m *QQModelMutation) ResetEdge(name string) error { return fmt.Errorf("unknown QQModel edge %s", name) } // SFModelMutation represents an operation that mutate the SFModels // nodes in the graph. type SFModelMutation struct { config op Op typ string id *int name *string phone_number *int64 addphone_number *int64 address *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*SFModel, error) predicates []predicate.SFModel } var _ ent.Mutation = (*SFModelMutation)(nil) // sfmodelOption allows to manage the mutation configuration using functional options. type sfmodelOption func(*SFModelMutation) // newSFModelMutation creates new mutation for $n.Name. func newSFModelMutation(c config, op Op, opts ...sfmodelOption) *SFModelMutation { m := &SFModelMutation{ config: c, op: op, typ: TypeSFModel, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSFModelID sets the id field of the mutation. func withSFModelID(id int) sfmodelOption { return func(m *SFModelMutation) { var ( err error once sync.Once value *SFModel ) m.oldValue = func(ctx context.Context) (*SFModel, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { value, err = m.Client().SFModel.Get(ctx, id) } }) return value, err } m.id = &id } } // withSFModel sets the old SFModel of the mutation. func withSFModel(node *SFModel) sfmodelOption { return func(m *SFModelMutation) { m.oldValue = func(context.Context) (*SFModel, 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 SFModelMutation) 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 SFModelMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("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 available only if it was provided to the builder. func (m *SFModelMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } // SetName sets the name field. func (m *SFModelMutation) SetName(s string) { m.name = &s } // Name returns the name value in the mutation. func (m *SFModelMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old name value of the SFModel. // If the SFModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *SFModelMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldName is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 reset all changes of the "name" field. func (m *SFModelMutation) ResetName() { m.name = nil } // SetPhoneNumber sets the phone_number field. func (m *SFModelMutation) SetPhoneNumber(i int64) { m.phone_number = &i m.addphone_number = nil } // PhoneNumber returns the phone_number value in the mutation. func (m *SFModelMutation) PhoneNumber() (r int64, exists bool) { v := m.phone_number if v == nil { return } return *v, true } // OldPhoneNumber returns the old phone_number value of the SFModel. // If the SFModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *SFModelMutation) OldPhoneNumber(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldPhoneNumber is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("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 } // AddPhoneNumber adds i to phone_number. func (m *SFModelMutation) AddPhoneNumber(i int64) { if m.addphone_number != nil { *m.addphone_number += i } else { m.addphone_number = &i } } // AddedPhoneNumber returns the value that was added to the phone_number field in this mutation. func (m *SFModelMutation) AddedPhoneNumber() (r int64, exists bool) { v := m.addphone_number if v == nil { return } return *v, true } // ResetPhoneNumber reset all changes of the "phone_number" field. func (m *SFModelMutation) ResetPhoneNumber() { m.phone_number = nil m.addphone_number = nil } // SetAddress sets the address field. func (m *SFModelMutation) SetAddress(s string) { m.address = &s } // Address returns the address value in the mutation. func (m *SFModelMutation) Address() (r string, exists bool) { v := m.address if v == nil { return } return *v, true } // OldAddress returns the old address value of the SFModel. // If the SFModel object wasn't provided to the builder, the object is fetched // from the database. // An error is returned if the mutation operation is not UpdateOne, or database query fails. func (m *SFModelMutation) OldAddress(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldAddress is allowed only on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldAddress requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAddress: %w", err) } return oldValue.Address, nil } // ResetAddress reset all changes of the "address" field. func (m *SFModelMutation) ResetAddress() { m.address = nil } // Op returns the operation name. func (m *SFModelMutation) Op() Op { return m.op } // Type returns the node type of this mutation (SFModel). func (m *SFModelMutation) 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 in/decremented, call AddedFields(). func (m *SFModelMutation) Fields() []string { fields := make([]string, 0, 3) if m.name != nil { fields = append(fields, sfmodel.FieldName) } if m.phone_number != nil { fields = append(fields, sfmodel.FieldPhoneNumber) } if m.address != nil { fields = append(fields, sfmodel.FieldAddress) } return fields } // Field returns the value of a field with the given name. // The second boolean value indicates that this field was // not set, or was not define in the schema. func (m *SFModelMutation) Field(name string) (ent.Value, bool) { switch name { case sfmodel.FieldName: return m.Name() case sfmodel.FieldPhoneNumber: return m.PhoneNumber() case sfmodel.FieldAddress: return m.Address() } 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 was failed. func (m *SFModelMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case sfmodel.FieldName: return m.OldName(ctx) case sfmodel.FieldPhoneNumber: return m.OldPhoneNumber(ctx) case sfmodel.FieldAddress: return m.OldAddress(ctx) } return nil, fmt.Errorf("unknown SFModel field %s", name) } // SetField sets the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. func (m *SFModelMutation) SetField(name string, value ent.Value) error { switch name { case sfmodel.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case sfmodel.FieldPhoneNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhoneNumber(v) return nil case sfmodel.FieldAddress: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAddress(v) return nil } return fmt.Errorf("unknown SFModel field %s", name) } // AddedFields returns all numeric fields that were incremented // or decremented during this mutation. func (m *SFModelMutation) AddedFields() []string { var fields []string if m.addphone_number != nil { fields = append(fields, sfmodel.FieldPhoneNumber) } return fields } // AddedField returns the numeric value that was in/decremented // from a field with the given name. The second value indicates // that this field was not set, or was not define in the schema. func (m *SFModelMutation) AddedField(name string) (ent.Value, bool) { switch name { case sfmodel.FieldPhoneNumber: return m.AddedPhoneNumber() } return nil, false } // AddField adds the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. func (m *SFModelMutation) AddField(name string, value ent.Value) error { switch name { case sfmodel.FieldPhoneNumber: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddPhoneNumber(v) return nil } return fmt.Errorf("unknown SFModel numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared // during this mutation. func (m *SFModelMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicates if this field was // cleared in this mutation. func (m *SFModelMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value for the given name. It returns an // error if the field is not defined in the schema. func (m *SFModelMutation) ClearField(name string) error { return fmt.Errorf("unknown SFModel nullable field %s", name) } // ResetField resets all changes in the mutation regarding the // given field name. It returns an error if the field is not // defined in the schema. func (m *SFModelMutation) ResetField(name string) error { switch name { case sfmodel.FieldName: m.ResetName() return nil case sfmodel.FieldPhoneNumber: m.ResetPhoneNumber() return nil case sfmodel.FieldAddress: m.ResetAddress() return nil } return fmt.Errorf("unknown SFModel field %s", name) } // AddedEdges returns all edge names that were set/added in this // mutation. func (m *SFModelMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all ids (to other nodes) that were added for // the given edge name. func (m *SFModelMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this // mutation. func (m *SFModelMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all ids (to other nodes) that were removed for // the given edge name. func (m *SFModelMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this // mutation. func (m *SFModelMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean indicates if this edge was // cleared in this mutation. func (m *SFModelMutation) EdgeCleared(name string) bool { return false } // ClearEdge clears the value for the given name. It returns an // error if the edge name is not defined in the schema. func (m *SFModelMutation) ClearEdge(name string) error { return fmt.Errorf("unknown SFModel unique edge %s", name) } // ResetEdge resets all changes in the mutation regarding the // given edge name. It returns an error if the edge is not // defined in the schema. func (m *SFModelMutation) ResetEdge(name string) error { return fmt.Errorf("unknown SFModel edge %s", name) }