// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "t/ent/card" "t/ent/group" "t/ent/predicate" "t/ent/user" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeCard = "Card" TypeGroup = "Group" TypeUser = "User" ) // CardMutation represents an operation that mutates the Card nodes in the graph. type CardMutation struct { config op Op typ string id *int card *int addcard *int status *string cp *int addcp *int url *string created_at *time.Time clearedFields map[string]struct{} owner *int clearedowner bool done bool oldValue func(context.Context) (*Card, error) predicates []predicate.Card } var _ ent.Mutation = (*CardMutation)(nil) // cardOption allows management of the mutation configuration using functional options. type cardOption func(*CardMutation) // newCardMutation creates new mutation for the Card entity. func newCardMutation(c config, op Op, opts ...cardOption) *CardMutation { m := &CardMutation{ config: c, op: op, typ: TypeCard, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withCardID sets the ID field of the mutation. func withCardID(id int) cardOption { return func(m *CardMutation) { var ( err error once sync.Once value *Card ) m.oldValue = func(ctx context.Context) (*Card, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Card.Get(ctx, id) } }) return value, err } m.id = &id } } // withCard sets the old Card of the mutation. func withCard(node *Card) cardOption { return func(m *CardMutation) { m.oldValue = func(context.Context) (*Card, 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 CardMutation) 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 CardMutation) 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 *CardMutation) 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 *CardMutation) 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().Card.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCard sets the "card" field. func (m *CardMutation) SetCard(i int) { m.card = &i m.addcard = nil } // Card returns the value of the "card" field in the mutation. func (m *CardMutation) Card() (r int, exists bool) { v := m.card if v == nil { return } return *v, true } // OldCard returns the old "card" field's value of the Card entity. // If the Card 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 *CardMutation) OldCard(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCard is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCard requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCard: %w", err) } return oldValue.Card, nil } // AddCard adds i to the "card" field. func (m *CardMutation) AddCard(i int) { if m.addcard != nil { *m.addcard += i } else { m.addcard = &i } } // AddedCard returns the value that was added to the "card" field in this mutation. func (m *CardMutation) AddedCard() (r int, exists bool) { v := m.addcard if v == nil { return } return *v, true } // ClearCard clears the value of the "card" field. func (m *CardMutation) ClearCard() { m.card = nil m.addcard = nil m.clearedFields[card.FieldCard] = struct{}{} } // CardCleared returns if the "card" field was cleared in this mutation. func (m *CardMutation) CardCleared() bool { _, ok := m.clearedFields[card.FieldCard] return ok } // ResetCard resets all changes to the "card" field. func (m *CardMutation) ResetCard() { m.card = nil m.addcard = nil delete(m.clearedFields, card.FieldCard) } // SetStatus sets the "status" field. func (m *CardMutation) SetStatus(s string) { m.status = &s } // Status returns the value of the "status" field in the mutation. func (m *CardMutation) Status() (r string, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the Card entity. // If the Card 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 *CardMutation) OldStatus(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ClearStatus clears the value of the "status" field. func (m *CardMutation) ClearStatus() { m.status = nil m.clearedFields[card.FieldStatus] = struct{}{} } // StatusCleared returns if the "status" field was cleared in this mutation. func (m *CardMutation) StatusCleared() bool { _, ok := m.clearedFields[card.FieldStatus] return ok } // ResetStatus resets all changes to the "status" field. func (m *CardMutation) ResetStatus() { m.status = nil delete(m.clearedFields, card.FieldStatus) } // SetCp sets the "cp" field. func (m *CardMutation) SetCp(i int) { m.cp = &i m.addcp = nil } // Cp returns the value of the "cp" field in the mutation. func (m *CardMutation) Cp() (r int, exists bool) { v := m.cp if v == nil { return } return *v, true } // OldCp returns the old "cp" field's value of the Card entity. // If the Card 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 *CardMutation) OldCp(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCp requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCp: %w", err) } return oldValue.Cp, nil } // AddCp adds i to the "cp" field. func (m *CardMutation) AddCp(i int) { if m.addcp != nil { *m.addcp += i } else { m.addcp = &i } } // AddedCp returns the value that was added to the "cp" field in this mutation. func (m *CardMutation) AddedCp() (r int, exists bool) { v := m.addcp if v == nil { return } return *v, true } // ClearCp clears the value of the "cp" field. func (m *CardMutation) ClearCp() { m.cp = nil m.addcp = nil m.clearedFields[card.FieldCp] = struct{}{} } // CpCleared returns if the "cp" field was cleared in this mutation. func (m *CardMutation) CpCleared() bool { _, ok := m.clearedFields[card.FieldCp] return ok } // ResetCp resets all changes to the "cp" field. func (m *CardMutation) ResetCp() { m.cp = nil m.addcp = nil delete(m.clearedFields, card.FieldCp) } // SetURL sets the "url" field. func (m *CardMutation) SetURL(s string) { m.url = &s } // URL returns the value of the "url" field in the mutation. func (m *CardMutation) URL() (r string, exists bool) { v := m.url if v == nil { return } return *v, true } // OldURL returns the old "url" field's value of the Card entity. // If the Card 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 *CardMutation) OldURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldURL: %w", err) } return oldValue.URL, nil } // ClearURL clears the value of the "url" field. func (m *CardMutation) ClearURL() { m.url = nil m.clearedFields[card.FieldURL] = struct{}{} } // URLCleared returns if the "url" field was cleared in this mutation. func (m *CardMutation) URLCleared() bool { _, ok := m.clearedFields[card.FieldURL] return ok } // ResetURL resets all changes to the "url" field. func (m *CardMutation) ResetURL() { m.url = nil delete(m.clearedFields, card.FieldURL) } // SetCreatedAt sets the "created_at" field. func (m *CardMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *CardMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Card entity. // If the Card 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 *CardMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ClearCreatedAt clears the value of the "created_at" field. func (m *CardMutation) ClearCreatedAt() { m.created_at = nil m.clearedFields[card.FieldCreatedAt] = struct{}{} } // CreatedAtCleared returns if the "created_at" field was cleared in this mutation. func (m *CardMutation) CreatedAtCleared() bool { _, ok := m.clearedFields[card.FieldCreatedAt] return ok } // ResetCreatedAt resets all changes to the "created_at" field. func (m *CardMutation) ResetCreatedAt() { m.created_at = nil delete(m.clearedFields, card.FieldCreatedAt) } // SetOwnerID sets the "owner" edge to the User entity by id. func (m *CardMutation) SetOwnerID(id int) { m.owner = &id } // ClearOwner clears the "owner" edge to the User entity. func (m *CardMutation) ClearOwner() { m.clearedowner = true } // OwnerCleared reports if the "owner" edge to the User entity was cleared. func (m *CardMutation) OwnerCleared() bool { return m.clearedowner } // OwnerID returns the "owner" edge ID in the mutation. func (m *CardMutation) OwnerID() (id int, exists bool) { if m.owner != nil { return *m.owner, true } return } // OwnerIDs returns the "owner" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *CardMutation) OwnerIDs() (ids []int) { if id := m.owner; id != nil { ids = append(ids, *id) } return } // ResetOwner resets all changes to the "owner" edge. func (m *CardMutation) ResetOwner() { m.owner = nil m.clearedowner = false } // Where appends a list predicates to the CardMutation builder. func (m *CardMutation) Where(ps ...predicate.Card) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the CardMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *CardMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Card, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *CardMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *CardMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Card). func (m *CardMutation) 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 *CardMutation) Fields() []string { fields := make([]string, 0, 5) if m.card != nil { fields = append(fields, card.FieldCard) } if m.status != nil { fields = append(fields, card.FieldStatus) } if m.cp != nil { fields = append(fields, card.FieldCp) } if m.url != nil { fields = append(fields, card.FieldURL) } if m.created_at != nil { fields = append(fields, card.FieldCreatedAt) } 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 *CardMutation) Field(name string) (ent.Value, bool) { switch name { case card.FieldCard: return m.Card() case card.FieldStatus: return m.Status() case card.FieldCp: return m.Cp() case card.FieldURL: return m.URL() case card.FieldCreatedAt: return m.CreatedAt() } 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 *CardMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case card.FieldCard: return m.OldCard(ctx) case card.FieldStatus: return m.OldStatus(ctx) case card.FieldCp: return m.OldCp(ctx) case card.FieldURL: return m.OldURL(ctx) case card.FieldCreatedAt: return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown Card 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 *CardMutation) SetField(name string, value ent.Value) error { switch name { case card.FieldCard: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCard(v) return nil case card.FieldStatus: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case card.FieldCp: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCp(v) return nil case card.FieldURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetURL(v) return nil case card.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil } return fmt.Errorf("unknown Card field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *CardMutation) AddedFields() []string { var fields []string if m.addcard != nil { fields = append(fields, card.FieldCard) } if m.addcp != nil { fields = append(fields, card.FieldCp) } 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 *CardMutation) AddedField(name string) (ent.Value, bool) { switch name { case card.FieldCard: return m.AddedCard() case card.FieldCp: return m.AddedCp() } 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 *CardMutation) AddField(name string, value ent.Value) error { switch name { case card.FieldCard: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddCard(v) return nil case card.FieldCp: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddCp(v) return nil } return fmt.Errorf("unknown Card numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *CardMutation) ClearedFields() []string { var fields []string if m.FieldCleared(card.FieldCard) { fields = append(fields, card.FieldCard) } if m.FieldCleared(card.FieldStatus) { fields = append(fields, card.FieldStatus) } if m.FieldCleared(card.FieldCp) { fields = append(fields, card.FieldCp) } if m.FieldCleared(card.FieldURL) { fields = append(fields, card.FieldURL) } if m.FieldCleared(card.FieldCreatedAt) { fields = append(fields, card.FieldCreatedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *CardMutation) 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 *CardMutation) ClearField(name string) error { switch name { case card.FieldCard: m.ClearCard() return nil case card.FieldStatus: m.ClearStatus() return nil case card.FieldCp: m.ClearCp() return nil case card.FieldURL: m.ClearURL() return nil case card.FieldCreatedAt: m.ClearCreatedAt() return nil } return fmt.Errorf("unknown Card 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 *CardMutation) ResetField(name string) error { switch name { case card.FieldCard: m.ResetCard() return nil case card.FieldStatus: m.ResetStatus() return nil case card.FieldCp: m.ResetCp() return nil case card.FieldURL: m.ResetURL() return nil case card.FieldCreatedAt: m.ResetCreatedAt() return nil } return fmt.Errorf("unknown Card field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *CardMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { edges = append(edges, card.EdgeOwner) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *CardMutation) AddedIDs(name string) []ent.Value { switch name { case card.EdgeOwner: if id := m.owner; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *CardMutation) 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 *CardMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *CardMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { edges = append(edges, card.EdgeOwner) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *CardMutation) EdgeCleared(name string) bool { switch name { case card.EdgeOwner: return m.clearedowner } 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 *CardMutation) ClearEdge(name string) error { switch name { case card.EdgeOwner: m.ClearOwner() return nil } return fmt.Errorf("unknown Card 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 *CardMutation) ResetEdge(name string) error { switch name { case card.EdgeOwner: m.ResetOwner() return nil } return fmt.Errorf("unknown Card edge %s", name) } // GroupMutation represents an operation that mutates the Group nodes in the graph. type GroupMutation struct { config op Op typ string id *int name *string clearedFields map[string]struct{} users map[int]struct{} removedusers map[int]struct{} clearedusers bool done bool oldValue func(context.Context) (*Group, error) predicates []predicate.Group } var _ ent.Mutation = (*GroupMutation)(nil) // groupOption allows management of the mutation configuration using functional options. type groupOption func(*GroupMutation) // newGroupMutation creates new mutation for the Group entity. func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation { m := &GroupMutation{ config: c, op: op, typ: TypeGroup, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withGroupID sets the ID field of the mutation. func withGroupID(id int) groupOption { return func(m *GroupMutation) { var ( err error once sync.Once value *Group ) m.oldValue = func(ctx context.Context) (*Group, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Group.Get(ctx, id) } }) return value, err } m.id = &id } } // withGroup sets the old Group of the mutation. func withGroup(node *Group) groupOption { return func(m *GroupMutation) { m.oldValue = func(context.Context) (*Group, 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 GroupMutation) 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 GroupMutation) 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 *GroupMutation) 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 *GroupMutation) 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().Group.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 *GroupMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *GroupMutation) 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 Group entity. // If the Group 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 *GroupMutation) 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 *GroupMutation) ResetName() { m.name = nil } // AddUserIDs adds the "users" edge to the User entity by ids. func (m *GroupMutation) AddUserIDs(ids ...int) { if m.users == nil { m.users = make(map[int]struct{}) } for i := range ids { m.users[ids[i]] = struct{}{} } } // ClearUsers clears the "users" edge to the User entity. func (m *GroupMutation) ClearUsers() { m.clearedusers = true } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *GroupMutation) UsersCleared() bool { return m.clearedusers } // RemoveUserIDs removes the "users" edge to the User entity by IDs. func (m *GroupMutation) RemoveUserIDs(ids ...int) { if m.removedusers == nil { m.removedusers = make(map[int]struct{}) } for i := range ids { delete(m.users, ids[i]) m.removedusers[ids[i]] = struct{}{} } } // RemovedUsers returns the removed IDs of the "users" edge to the User entity. func (m *GroupMutation) RemovedUsersIDs() (ids []int) { for id := range m.removedusers { ids = append(ids, id) } return } // UsersIDs returns the "users" edge IDs in the mutation. func (m *GroupMutation) UsersIDs() (ids []int) { for id := range m.users { ids = append(ids, id) } return } // ResetUsers resets all changes to the "users" edge. func (m *GroupMutation) ResetUsers() { m.users = nil m.clearedusers = false m.removedusers = nil } // Where appends a list predicates to the GroupMutation builder. func (m *GroupMutation) Where(ps ...predicate.Group) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the GroupMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *GroupMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Group, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *GroupMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *GroupMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Group). func (m *GroupMutation) 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 *GroupMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, group.FieldName) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *GroupMutation) Field(name string) (ent.Value, bool) { switch name { case group.FieldName: return m.Name() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case group.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown Group 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 *GroupMutation) SetField(name string, value ent.Value) error { switch name { case group.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown Group field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *GroupMutation) 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 *GroupMutation) 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 *GroupMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Group numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *GroupMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *GroupMutation) 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 *GroupMutation) ClearField(name string) error { return fmt.Errorf("unknown Group 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 *GroupMutation) ResetField(name string) error { switch name { case group.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown Group field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *GroupMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.users != nil { edges = append(edges, group.EdgeUsers) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *GroupMutation) AddedIDs(name string) []ent.Value { switch name { case group.EdgeUsers: ids := make([]ent.Value, 0, len(m.users)) for id := range m.users { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *GroupMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedusers != nil { edges = append(edges, group.EdgeUsers) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *GroupMutation) RemovedIDs(name string) []ent.Value { switch name { case group.EdgeUsers: ids := make([]ent.Value, 0, len(m.removedusers)) for id := range m.removedusers { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *GroupMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedusers { edges = append(edges, group.EdgeUsers) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *GroupMutation) EdgeCleared(name string) bool { switch name { case group.EdgeUsers: return m.clearedusers } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *GroupMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Group 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 *GroupMutation) ResetEdge(name string) error { switch name { case group.EdgeUsers: m.ResetUsers() return nil } return fmt.Errorf("unknown Group 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 username *string created_at *time.Time updated_at *time.Time next *string clearedFields map[string]struct{} card map[int]struct{} removedcard map[int]struct{} clearedcard 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) } } // SetUsername sets the "username" field. func (m *UserMutation) SetUsername(s string) { m.username = &s } // Username returns the value of the "username" field in the mutation. func (m *UserMutation) Username() (r string, exists bool) { v := m.username if v == nil { return } return *v, true } // OldUsername returns the old "username" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUsername: %w", err) } return oldValue.Username, nil } // ResetUsername resets all changes to the "username" field. func (m *UserMutation) ResetUsername() { m.username = nil } // SetCreatedAt sets the "created_at" field. func (m *UserMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ClearCreatedAt clears the value of the "created_at" field. func (m *UserMutation) ClearCreatedAt() { m.created_at = nil m.clearedFields[user.FieldCreatedAt] = struct{}{} } // CreatedAtCleared returns if the "created_at" field was cleared in this mutation. func (m *UserMutation) CreatedAtCleared() bool { _, ok := m.clearedFields[user.FieldCreatedAt] return ok } // ResetCreatedAt resets all changes to the "created_at" field. func (m *UserMutation) ResetCreatedAt() { m.created_at = nil delete(m.clearedFields, user.FieldCreatedAt) } // SetUpdatedAt sets the "updated_at" field. func (m *UserMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ClearUpdatedAt clears the value of the "updated_at" field. func (m *UserMutation) ClearUpdatedAt() { m.updated_at = nil m.clearedFields[user.FieldUpdatedAt] = struct{}{} } // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. func (m *UserMutation) UpdatedAtCleared() bool { _, ok := m.clearedFields[user.FieldUpdatedAt] return ok } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *UserMutation) ResetUpdatedAt() { m.updated_at = nil delete(m.clearedFields, user.FieldUpdatedAt) } // SetNext sets the "next" field. func (m *UserMutation) SetNext(s string) { m.next = &s } // Next returns the value of the "next" field in the mutation. func (m *UserMutation) Next() (r string, exists bool) { v := m.next if v == nil { return } return *v, true } // OldNext returns the old "next" 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) OldNext(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldNext is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldNext requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldNext: %w", err) } return oldValue.Next, nil } // ClearNext clears the value of the "next" field. func (m *UserMutation) ClearNext() { m.next = nil m.clearedFields[user.FieldNext] = struct{}{} } // NextCleared returns if the "next" field was cleared in this mutation. func (m *UserMutation) NextCleared() bool { _, ok := m.clearedFields[user.FieldNext] return ok } // ResetNext resets all changes to the "next" field. func (m *UserMutation) ResetNext() { m.next = nil delete(m.clearedFields, user.FieldNext) } // AddCardIDs adds the "card" edge to the Card entity by ids. func (m *UserMutation) AddCardIDs(ids ...int) { if m.card == nil { m.card = make(map[int]struct{}) } for i := range ids { m.card[ids[i]] = struct{}{} } } // ClearCard clears the "card" edge to the Card entity. func (m *UserMutation) ClearCard() { m.clearedcard = true } // CardCleared reports if the "card" edge to the Card entity was cleared. func (m *UserMutation) CardCleared() bool { return m.clearedcard } // RemoveCardIDs removes the "card" edge to the Card entity by IDs. func (m *UserMutation) RemoveCardIDs(ids ...int) { if m.removedcard == nil { m.removedcard = make(map[int]struct{}) } for i := range ids { delete(m.card, ids[i]) m.removedcard[ids[i]] = struct{}{} } } // RemovedCard returns the removed IDs of the "card" edge to the Card entity. func (m *UserMutation) RemovedCardIDs() (ids []int) { for id := range m.removedcard { ids = append(ids, id) } return } // CardIDs returns the "card" edge IDs in the mutation. func (m *UserMutation) CardIDs() (ids []int) { for id := range m.card { ids = append(ids, id) } return } // ResetCard resets all changes to the "card" edge. func (m *UserMutation) ResetCard() { m.card = nil m.clearedcard = false m.removedcard = nil } // Where appends a list predicates to the UserMutation builder. func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.User, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { fields := make([]string, 0, 4) if m.username != nil { fields = append(fields, user.FieldUsername) } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } if m.next != nil { fields = append(fields, user.FieldNext) } 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.FieldUsername: return m.Username() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() case user.FieldNext: return m.Next() } 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.FieldUsername: return m.OldUsername(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case user.FieldNext: return m.OldNext(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.FieldUsername: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsername(v) return nil case user.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case user.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case user.FieldNext: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNext(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 { 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 *UserMutation) 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 *UserMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown User numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { var fields []string if m.FieldCleared(user.FieldCreatedAt) { fields = append(fields, user.FieldCreatedAt) } if m.FieldCleared(user.FieldUpdatedAt) { fields = append(fields, user.FieldUpdatedAt) } if m.FieldCleared(user.FieldNext) { fields = append(fields, user.FieldNext) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { switch name { case user.FieldCreatedAt: m.ClearCreatedAt() return nil case user.FieldUpdatedAt: m.ClearUpdatedAt() return nil case user.FieldNext: m.ClearNext() return nil } return fmt.Errorf("unknown User nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *UserMutation) ResetField(name string) error { switch name { case user.FieldUsername: m.ResetUsername() return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() return nil case user.FieldNext: m.ResetNext() 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, 1) if m.card != nil { edges = append(edges, user.EdgeCard) } 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.EdgeCard: ids := make([]ent.Value, 0, len(m.card)) for id := range m.card { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedcard != nil { edges = append(edges, user.EdgeCard) } 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.EdgeCard: ids := make([]ent.Value, 0, len(m.removedcard)) for id := range m.removedcard { 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, 1) if m.clearedcard { edges = append(edges, user.EdgeCard) } 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.EdgeCard: return m.clearedcard } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *UserMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown User unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *UserMutation) ResetEdge(name string) error { switch name { case user.EdgeCard: m.ResetCard() return nil } return fmt.Errorf("unknown User edge %s", name) }