// Copyright 2019-present Facebook Inc. All rights reserved. // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. // Code generated by ent, DO NOT EDIT. package user import ( "context" "fmt" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/entc/integration/migrate/entv2/predicate" ) // Mutation represents an operation that mutates the User nodes in the graph. type Mutation struct { op ent.Op typ string mixed_string *string mixed_enum *MixedEnum active *bool age *int addage *int name *string description *string nickname *string phone *string buffer *[]byte title *string new_name *string new_token *string blob *[]byte state *State status *Status workplace *string roles *[]string appendroles []string default_expr *string default_exprs *string created_at *time.Time drop_optional *string clearedFields map[string]struct{} car map[int]struct{} removedcar map[int]struct{} clearedcar bool pets *int clearedpets bool friends map[int]struct{} removedfriends map[int]struct{} clearedfriends bool predicates []predicate.User } // NewMutation creates a new Mutation for the User entity. func NewMutation(op ent.Op) *Mutation { return &Mutation{ op: op, typ: "User", clearedFields: make(map[string]struct{}), } } // Predicates returns the list of predicates set on the mutation. func (m *Mutation) Predicates() []predicate.User { return m.predicates } // SetMixedString sets the "mixed_string" field. func (m *Mutation) SetMixedString(s string) { m.mixed_string = &s } // MixedString returns the value of the "mixed_string" field in the mutation. func (m *Mutation) MixedString() (r string, exists bool) { v := m.mixed_string if v == nil { return } return *v, true } // ResetMixedString resets all changes to the "mixed_string" field. func (m *Mutation) ResetMixedString() { m.mixed_string = nil } // SetMixedEnum sets the "mixed_enum" field. func (m *Mutation) SetMixedEnum(ue MixedEnum) { m.mixed_enum = &ue } // MixedEnum returns the value of the "mixed_enum" field in the mutation. func (m *Mutation) MixedEnum() (r MixedEnum, exists bool) { v := m.mixed_enum if v == nil { return } return *v, true } // ResetMixedEnum resets all changes to the "mixed_enum" field. func (m *Mutation) ResetMixedEnum() { m.mixed_enum = nil } // SetActive sets the "active" field. func (m *Mutation) SetActive(b bool) { m.active = &b } // Active returns the value of the "active" field in the mutation. func (m *Mutation) Active() (r bool, exists bool) { v := m.active if v == nil { return } return *v, true } // ResetActive resets all changes to the "active" field. func (m *Mutation) ResetActive() { m.active = nil } // SetAge sets the "age" field. func (m *Mutation) SetAge(i int) { m.age = &i m.addage = nil } // Age returns the value of the "age" field in the mutation. func (m *Mutation) Age() (r int, exists bool) { v := m.age if v == nil { return } return *v, true } // AddAge adds i to the "age" field. func (m *Mutation) AddAge(i int) { if m.addage != nil { *m.addage += i } else { m.addage = &i } } // AddedAge returns the value that was added to the "age" field in this mutation. func (m *Mutation) AddedAge() (r int, exists bool) { v := m.addage if v == nil { return } return *v, true } // ResetAge resets all changes to the "age" field. func (m *Mutation) ResetAge() { m.age = nil m.addage = nil } // SetName sets the "name" field. func (m *Mutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *Mutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // ResetName resets all changes to the "name" field. func (m *Mutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *Mutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *Mutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // ClearDescription clears the value of the "description" field. func (m *Mutation) ClearDescription() { m.description = nil m.clearedFields[FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *Mutation) DescriptionCleared() bool { _, ok := m.clearedFields[FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *Mutation) ResetDescription() { m.description = nil delete(m.clearedFields, FieldDescription) } // SetNickname sets the "nickname" field. func (m *Mutation) SetNickname(s string) { m.nickname = &s } // Nickname returns the value of the "nickname" field in the mutation. func (m *Mutation) Nickname() (r string, exists bool) { v := m.nickname if v == nil { return } return *v, true } // ResetNickname resets all changes to the "nickname" field. func (m *Mutation) ResetNickname() { m.nickname = nil } // SetPhone sets the "phone" field. func (m *Mutation) SetPhone(s string) { m.phone = &s } // Phone returns the value of the "phone" field in the mutation. func (m *Mutation) Phone() (r string, exists bool) { v := m.phone if v == nil { return } return *v, true } // ResetPhone resets all changes to the "phone" field. func (m *Mutation) ResetPhone() { m.phone = nil } // SetBuffer sets the "buffer" field. func (m *Mutation) SetBuffer(b []byte) { m.buffer = &b } // Buffer returns the value of the "buffer" field in the mutation. func (m *Mutation) Buffer() (r []byte, exists bool) { v := m.buffer if v == nil { return } return *v, true } // ClearBuffer clears the value of the "buffer" field. func (m *Mutation) ClearBuffer() { m.buffer = nil m.clearedFields[FieldBuffer] = struct{}{} } // BufferCleared returns if the "buffer" field was cleared in this mutation. func (m *Mutation) BufferCleared() bool { _, ok := m.clearedFields[FieldBuffer] return ok } // ResetBuffer resets all changes to the "buffer" field. func (m *Mutation) ResetBuffer() { m.buffer = nil delete(m.clearedFields, FieldBuffer) } // SetTitle sets the "title" field. func (m *Mutation) SetTitle(s string) { m.title = &s } // Title returns the value of the "title" field in the mutation. func (m *Mutation) Title() (r string, exists bool) { v := m.title if v == nil { return } return *v, true } // ResetTitle resets all changes to the "title" field. func (m *Mutation) ResetTitle() { m.title = nil } // SetNewName sets the "new_name" field. func (m *Mutation) SetNewName(s string) { m.new_name = &s } // NewName returns the value of the "new_name" field in the mutation. func (m *Mutation) NewName() (r string, exists bool) { v := m.new_name if v == nil { return } return *v, true } // ClearNewName clears the value of the "new_name" field. func (m *Mutation) ClearNewName() { m.new_name = nil m.clearedFields[FieldNewName] = struct{}{} } // NewNameCleared returns if the "new_name" field was cleared in this mutation. func (m *Mutation) NewNameCleared() bool { _, ok := m.clearedFields[FieldNewName] return ok } // ResetNewName resets all changes to the "new_name" field. func (m *Mutation) ResetNewName() { m.new_name = nil delete(m.clearedFields, FieldNewName) } // SetNewToken sets the "new_token" field. func (m *Mutation) SetNewToken(s string) { m.new_token = &s } // NewToken returns the value of the "new_token" field in the mutation. func (m *Mutation) NewToken() (r string, exists bool) { v := m.new_token if v == nil { return } return *v, true } // ResetNewToken resets all changes to the "new_token" field. func (m *Mutation) ResetNewToken() { m.new_token = nil } // SetBlob sets the "blob" field. func (m *Mutation) SetBlob(b []byte) { m.blob = &b } // Blob returns the value of the "blob" field in the mutation. func (m *Mutation) Blob() (r []byte, exists bool) { v := m.blob if v == nil { return } return *v, true } // ClearBlob clears the value of the "blob" field. func (m *Mutation) ClearBlob() { m.blob = nil m.clearedFields[FieldBlob] = struct{}{} } // BlobCleared returns if the "blob" field was cleared in this mutation. func (m *Mutation) BlobCleared() bool { _, ok := m.clearedFields[FieldBlob] return ok } // ResetBlob resets all changes to the "blob" field. func (m *Mutation) ResetBlob() { m.blob = nil delete(m.clearedFields, FieldBlob) } // SetState sets the "state" field. func (m *Mutation) SetState(u State) { m.state = &u } // State returns the value of the "state" field in the mutation. func (m *Mutation) State() (r State, exists bool) { v := m.state if v == nil { return } return *v, true } // ClearState clears the value of the "state" field. func (m *Mutation) ClearState() { m.state = nil m.clearedFields[FieldState] = struct{}{} } // StateCleared returns if the "state" field was cleared in this mutation. func (m *Mutation) StateCleared() bool { _, ok := m.clearedFields[FieldState] return ok } // ResetState resets all changes to the "state" field. func (m *Mutation) ResetState() { m.state = nil delete(m.clearedFields, FieldState) } // SetStatus sets the "status" field. func (m *Mutation) SetStatus(u Status) { m.status = &u } // Status returns the value of the "status" field in the mutation. func (m *Mutation) Status() (r Status, exists bool) { v := m.status if v == nil { return } return *v, true } // ClearStatus clears the value of the "status" field. func (m *Mutation) ClearStatus() { m.status = nil m.clearedFields[FieldStatus] = struct{}{} } // StatusCleared returns if the "status" field was cleared in this mutation. func (m *Mutation) StatusCleared() bool { _, ok := m.clearedFields[FieldStatus] return ok } // ResetStatus resets all changes to the "status" field. func (m *Mutation) ResetStatus() { m.status = nil delete(m.clearedFields, FieldStatus) } // SetWorkplace sets the "workplace" field. func (m *Mutation) SetWorkplace(s string) { m.workplace = &s } // Workplace returns the value of the "workplace" field in the mutation. func (m *Mutation) Workplace() (r string, exists bool) { v := m.workplace if v == nil { return } return *v, true } // ClearWorkplace clears the value of the "workplace" field. func (m *Mutation) ClearWorkplace() { m.workplace = nil m.clearedFields[FieldWorkplace] = struct{}{} } // WorkplaceCleared returns if the "workplace" field was cleared in this mutation. func (m *Mutation) WorkplaceCleared() bool { _, ok := m.clearedFields[FieldWorkplace] return ok } // ResetWorkplace resets all changes to the "workplace" field. func (m *Mutation) ResetWorkplace() { m.workplace = nil delete(m.clearedFields, FieldWorkplace) } // SetRoles sets the "roles" field. func (m *Mutation) SetRoles(s []string) { m.roles = &s m.appendroles = nil } // Roles returns the value of the "roles" field in the mutation. func (m *Mutation) Roles() (r []string, exists bool) { v := m.roles if v == nil { return } return *v, true } // AppendRoles adds s to the "roles" field. func (m *Mutation) AppendRoles(s []string) { m.appendroles = append(m.appendroles, s...) } // AppendedRoles returns the list of values that were appended to the "roles" field in this mutation. func (m *Mutation) AppendedRoles() ([]string, bool) { if len(m.appendroles) == 0 { return nil, false } return m.appendroles, true } // ClearRoles clears the value of the "roles" field. func (m *Mutation) ClearRoles() { m.roles = nil m.appendroles = nil m.clearedFields[FieldRoles] = struct{}{} } // RolesCleared returns if the "roles" field was cleared in this mutation. func (m *Mutation) RolesCleared() bool { _, ok := m.clearedFields[FieldRoles] return ok } // ResetRoles resets all changes to the "roles" field. func (m *Mutation) ResetRoles() { m.roles = nil m.appendroles = nil delete(m.clearedFields, FieldRoles) } // SetDefaultExpr sets the "default_expr" field. func (m *Mutation) SetDefaultExpr(s string) { m.default_expr = &s } // DefaultExpr returns the value of the "default_expr" field in the mutation. func (m *Mutation) DefaultExpr() (r string, exists bool) { v := m.default_expr if v == nil { return } return *v, true } // ClearDefaultExpr clears the value of the "default_expr" field. func (m *Mutation) ClearDefaultExpr() { m.default_expr = nil m.clearedFields[FieldDefaultExpr] = struct{}{} } // DefaultExprCleared returns if the "default_expr" field was cleared in this mutation. func (m *Mutation) DefaultExprCleared() bool { _, ok := m.clearedFields[FieldDefaultExpr] return ok } // ResetDefaultExpr resets all changes to the "default_expr" field. func (m *Mutation) ResetDefaultExpr() { m.default_expr = nil delete(m.clearedFields, FieldDefaultExpr) } // SetDefaultExprs sets the "default_exprs" field. func (m *Mutation) SetDefaultExprs(s string) { m.default_exprs = &s } // DefaultExprs returns the value of the "default_exprs" field in the mutation. func (m *Mutation) DefaultExprs() (r string, exists bool) { v := m.default_exprs if v == nil { return } return *v, true } // ClearDefaultExprs clears the value of the "default_exprs" field. func (m *Mutation) ClearDefaultExprs() { m.default_exprs = nil m.clearedFields[FieldDefaultExprs] = struct{}{} } // DefaultExprsCleared returns if the "default_exprs" field was cleared in this mutation. func (m *Mutation) DefaultExprsCleared() bool { _, ok := m.clearedFields[FieldDefaultExprs] return ok } // ResetDefaultExprs resets all changes to the "default_exprs" field. func (m *Mutation) ResetDefaultExprs() { m.default_exprs = nil delete(m.clearedFields, FieldDefaultExprs) } // SetCreatedAt sets the "created_at" field. func (m *Mutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *Mutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // ResetCreatedAt resets all changes to the "created_at" field. func (m *Mutation) ResetCreatedAt() { m.created_at = nil } // SetDropOptional sets the "drop_optional" field. func (m *Mutation) SetDropOptional(s string) { m.drop_optional = &s } // DropOptional returns the value of the "drop_optional" field in the mutation. func (m *Mutation) DropOptional() (r string, exists bool) { v := m.drop_optional if v == nil { return } return *v, true } // ResetDropOptional resets all changes to the "drop_optional" field. func (m *Mutation) ResetDropOptional() { m.drop_optional = nil } // AddCarIDs adds the "car" edge to the Car entity by ids. func (m *Mutation) AddCarIDs(ids ...int) { if m.car == nil { m.car = make(map[int]struct{}) } for i := range ids { m.car[ids[i]] = struct{}{} } } // ClearCar clears the "car" edge to the Car entity. func (m *Mutation) ClearCar() { m.clearedcar = true } // CarCleared reports if the "car" edge to the Car entity was cleared. func (m *Mutation) CarCleared() bool { return m.clearedcar } // RemoveCarIDs removes the "car" edge to the Car entity by IDs. func (m *Mutation) RemoveCarIDs(ids ...int) { if m.removedcar == nil { m.removedcar = make(map[int]struct{}) } for i := range ids { delete(m.car, ids[i]) m.removedcar[ids[i]] = struct{}{} } } // RemovedCar returns the removed IDs of the "car" edge to the Car entity. func (m *Mutation) RemovedCarIDs() (ids []int) { for id := range m.removedcar { ids = append(ids, id) } return } // CarIDs returns the "car" edge IDs in the mutation. func (m *Mutation) CarIDs() (ids []int) { for id := range m.car { ids = append(ids, id) } return } // ResetCar resets all changes to the "car" edge. func (m *Mutation) ResetCar() { m.car = nil m.clearedcar = false m.removedcar = nil } // SetPetsID sets the "pets" edge to the Pet entity by id. func (m *Mutation) SetPetsID(id int) { m.pets = &id } // ClearPets clears the "pets" edge to the Pet entity. func (m *Mutation) ClearPets() { m.clearedpets = true } // PetsCleared reports if the "pets" edge to the Pet entity was cleared. func (m *Mutation) PetsCleared() bool { return m.clearedpets } // PetsID returns the "pets" edge ID in the mutation. func (m *Mutation) PetsID() (id int, exists bool) { if m.pets != nil { return *m.pets, true } return } // PetsIDs returns the "pets" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // PetsID instead. It exists only for internal usage by the builders. func (m *Mutation) PetsIDs() (ids []int) { if id := m.pets; id != nil { ids = append(ids, *id) } return } // ResetPets resets all changes to the "pets" edge. func (m *Mutation) ResetPets() { m.pets = nil m.clearedpets = false } // AddFriendIDs adds the "friends" edge to the User entity by ids. func (m *Mutation) AddFriendIDs(ids ...int) { if m.friends == nil { m.friends = make(map[int]struct{}) } for i := range ids { m.friends[ids[i]] = struct{}{} } } // ClearFriends clears the "friends" edge to the User entity. func (m *Mutation) ClearFriends() { m.clearedfriends = true } // FriendsCleared reports if the "friends" edge to the User entity was cleared. func (m *Mutation) FriendsCleared() bool { return m.clearedfriends } // RemoveFriendIDs removes the "friends" edge to the User entity by IDs. func (m *Mutation) RemoveFriendIDs(ids ...int) { if m.removedfriends == nil { m.removedfriends = make(map[int]struct{}) } for i := range ids { delete(m.friends, ids[i]) m.removedfriends[ids[i]] = struct{}{} } } // RemovedFriends returns the removed IDs of the "friends" edge to the User entity. func (m *Mutation) RemovedFriendsIDs() (ids []int) { for id := range m.removedfriends { ids = append(ids, id) } return } // FriendsIDs returns the "friends" edge IDs in the mutation. func (m *Mutation) FriendsIDs() (ids []int) { for id := range m.friends { ids = append(ids, id) } return } // ResetFriends resets all changes to the "friends" edge. func (m *Mutation) ResetFriends() { m.friends = nil m.clearedfriends = false m.removedfriends = nil } // Where appends a list predicates to the Mutation builder. func (m *Mutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the Mutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *Mutation) 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 *Mutation) Op() ent.Op { return m.op } // SetOp allows setting the mutation operation. func (m *Mutation) SetOp(op ent.Op) { m.op = op } // Type returns the node type of this mutation (User). func (m *Mutation) 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 *Mutation) Fields() []string { fields := make([]string, 0, 21) if m.mixed_string != nil { fields = append(fields, FieldMixedString) } if m.mixed_enum != nil { fields = append(fields, FieldMixedEnum) } if m.active != nil { fields = append(fields, FieldActive) } if m.age != nil { fields = append(fields, FieldAge) } if m.name != nil { fields = append(fields, FieldName) } if m.description != nil { fields = append(fields, FieldDescription) } if m.nickname != nil { fields = append(fields, FieldNickname) } if m.phone != nil { fields = append(fields, FieldPhone) } if m.buffer != nil { fields = append(fields, FieldBuffer) } if m.title != nil { fields = append(fields, FieldTitle) } if m.new_name != nil { fields = append(fields, FieldNewName) } if m.new_token != nil { fields = append(fields, FieldNewToken) } if m.blob != nil { fields = append(fields, FieldBlob) } if m.state != nil { fields = append(fields, FieldState) } if m.status != nil { fields = append(fields, FieldStatus) } if m.workplace != nil { fields = append(fields, FieldWorkplace) } if m.roles != nil { fields = append(fields, FieldRoles) } if m.default_expr != nil { fields = append(fields, FieldDefaultExpr) } if m.default_exprs != nil { fields = append(fields, FieldDefaultExprs) } if m.created_at != nil { fields = append(fields, FieldCreatedAt) } if m.drop_optional != nil { fields = append(fields, FieldDropOptional) } 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 *Mutation) Field(name string) (ent.Value, bool) { switch name { case FieldMixedString: return m.MixedString() case FieldMixedEnum: return m.MixedEnum() case FieldActive: return m.Active() case FieldAge: return m.Age() case FieldName: return m.Name() case FieldDescription: return m.Description() case FieldNickname: return m.Nickname() case FieldPhone: return m.Phone() case FieldBuffer: return m.Buffer() case FieldTitle: return m.Title() case FieldNewName: return m.NewName() case FieldNewToken: return m.NewToken() case FieldBlob: return m.Blob() case FieldState: return m.State() case FieldStatus: return m.Status() case FieldWorkplace: return m.Workplace() case FieldRoles: return m.Roles() case FieldDefaultExpr: return m.DefaultExpr() case FieldDefaultExprs: return m.DefaultExprs() case FieldCreatedAt: return m.CreatedAt() case FieldDropOptional: return m.DropOptional() } 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 *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) { 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 *Mutation) SetField(name string, value ent.Value) error { switch name { case FieldMixedString: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMixedString(v) return nil case FieldMixedEnum: v, ok := value.(MixedEnum) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMixedEnum(v) return nil case FieldActive: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetActive(v) return nil case FieldAge: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAge(v) return nil case FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case FieldNickname: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNickname(v) return nil case FieldPhone: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhone(v) return nil case FieldBuffer: v, ok := value.([]byte) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBuffer(v) return nil case FieldTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTitle(v) return nil case FieldNewName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNewName(v) return nil case FieldNewToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNewToken(v) return nil case FieldBlob: v, ok := value.([]byte) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBlob(v) return nil case FieldState: v, ok := value.(State) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetState(v) return nil case FieldStatus: v, ok := value.(Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case FieldWorkplace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetWorkplace(v) return nil case FieldRoles: v, ok := value.([]string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRoles(v) return nil case FieldDefaultExpr: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDefaultExpr(v) return nil case FieldDefaultExprs: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDefaultExprs(v) return nil case FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case FieldDropOptional: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDropOptional(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 *Mutation) AddedFields() []string { var fields []string if m.addage != nil { fields = append(fields, FieldAge) } 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 *Mutation) AddedField(name string) (ent.Value, bool) { switch name { case FieldAge: return m.AddedAge() } 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 *Mutation) AddField(name string, value ent.Value) error { switch name { case FieldAge: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddAge(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 *Mutation) ClearedFields() []string { var fields []string if m.FieldCleared(FieldDescription) { fields = append(fields, FieldDescription) } if m.FieldCleared(FieldBuffer) { fields = append(fields, FieldBuffer) } if m.FieldCleared(FieldNewName) { fields = append(fields, FieldNewName) } if m.FieldCleared(FieldBlob) { fields = append(fields, FieldBlob) } if m.FieldCleared(FieldState) { fields = append(fields, FieldState) } if m.FieldCleared(FieldStatus) { fields = append(fields, FieldStatus) } if m.FieldCleared(FieldWorkplace) { fields = append(fields, FieldWorkplace) } if m.FieldCleared(FieldRoles) { fields = append(fields, FieldRoles) } if m.FieldCleared(FieldDefaultExpr) { fields = append(fields, FieldDefaultExpr) } if m.FieldCleared(FieldDefaultExprs) { fields = append(fields, FieldDefaultExprs) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *Mutation) 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 *Mutation) ClearField(name string) error { switch name { case FieldDescription: m.ClearDescription() return nil case FieldBuffer: m.ClearBuffer() return nil case FieldNewName: m.ClearNewName() return nil case FieldBlob: m.ClearBlob() return nil case FieldState: m.ClearState() return nil case FieldStatus: m.ClearStatus() return nil case FieldWorkplace: m.ClearWorkplace() return nil case FieldRoles: m.ClearRoles() return nil case FieldDefaultExpr: m.ClearDefaultExpr() return nil case FieldDefaultExprs: m.ClearDefaultExprs() return nil } return fmt.Errorf("unknown User nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *Mutation) ResetField(name string) error { switch name { case FieldMixedString: m.ResetMixedString() return nil case FieldMixedEnum: m.ResetMixedEnum() return nil case FieldActive: m.ResetActive() return nil case FieldAge: m.ResetAge() return nil case FieldName: m.ResetName() return nil case FieldDescription: m.ResetDescription() return nil case FieldNickname: m.ResetNickname() return nil case FieldPhone: m.ResetPhone() return nil case FieldBuffer: m.ResetBuffer() return nil case FieldTitle: m.ResetTitle() return nil case FieldNewName: m.ResetNewName() return nil case FieldNewToken: m.ResetNewToken() return nil case FieldBlob: m.ResetBlob() return nil case FieldState: m.ResetState() return nil case FieldStatus: m.ResetStatus() return nil case FieldWorkplace: m.ResetWorkplace() return nil case FieldRoles: m.ResetRoles() return nil case FieldDefaultExpr: m.ResetDefaultExpr() return nil case FieldDefaultExprs: m.ResetDefaultExprs() return nil case FieldCreatedAt: m.ResetCreatedAt() return nil case FieldDropOptional: m.ResetDropOptional() return nil } return fmt.Errorf("unknown User field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *Mutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.car != nil { edges = append(edges, EdgeCar) } if m.pets != nil { edges = append(edges, EdgePets) } if m.friends != nil { edges = append(edges, EdgeFriends) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *Mutation) AddedIDs(name string) []ent.Value { switch name { case EdgeCar: ids := make([]ent.Value, 0, len(m.car)) for id := range m.car { ids = append(ids, id) } return ids case EdgePets: if id := m.pets; id != nil { return []ent.Value{*id} } case EdgeFriends: ids := make([]ent.Value, 0, len(m.friends)) for id := range m.friends { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *Mutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedcar != nil { edges = append(edges, EdgeCar) } if m.removedfriends != nil { edges = append(edges, EdgeFriends) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *Mutation) RemovedIDs(name string) []ent.Value { switch name { case EdgeCar: ids := make([]ent.Value, 0, len(m.removedcar)) for id := range m.removedcar { ids = append(ids, id) } return ids case EdgeFriends: ids := make([]ent.Value, 0, len(m.removedfriends)) for id := range m.removedfriends { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *Mutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedcar { edges = append(edges, EdgeCar) } if m.clearedpets { edges = append(edges, EdgePets) } if m.clearedfriends { edges = append(edges, EdgeFriends) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *Mutation) EdgeCleared(name string) bool { switch name { case EdgeCar: return m.clearedcar case EdgePets: return m.clearedpets case EdgeFriends: return m.clearedfriends } 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 *Mutation) ClearEdge(name string) error { switch name { case EdgePets: m.ClearPets() 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 *Mutation) ResetEdge(name string) error { switch name { case EdgeCar: m.ResetCar() return nil case EdgePets: m.ResetPets() return nil case EdgeFriends: m.ResetFriends() return nil } return fmt.Errorf("unknown User edge %s", name) }