// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "portfolio/database/ent/predicate" "portfolio/database/ent/project" "portfolio/database/ent/team" "portfolio/database/ent/user" "sync" "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. TypeProject = "Project" TypeTeam = "Team" TypeUser = "User" ) // ProjectMutation represents an operation that mutates the Project nodes in the graph. type ProjectMutation struct { config op Op typ string id *int name *string description *string url *string image_url *string doc_url *string clearedFields map[string]struct{} users map[int]struct{} removedusers map[int]struct{} clearedusers bool teams map[int]struct{} removedteams map[int]struct{} clearedteams bool done bool oldValue func(context.Context) (*Project, error) predicates []predicate.Project } var _ ent.Mutation = (*ProjectMutation)(nil) // projectOption allows management of the mutation configuration using functional options. type projectOption func(*ProjectMutation) // newProjectMutation creates new mutation for the Project entity. func newProjectMutation(c config, op Op, opts ...projectOption) *ProjectMutation { m := &ProjectMutation{ config: c, op: op, typ: TypeProject, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withProjectID sets the ID field of the mutation. func withProjectID(id int) projectOption { return func(m *ProjectMutation) { var ( err error once sync.Once value *Project ) m.oldValue = func(ctx context.Context) (*Project, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Project.Get(ctx, id) } }) return value, err } m.id = &id } } // withProject sets the old Project of the mutation. func withProject(node *Project) projectOption { return func(m *ProjectMutation) { m.oldValue = func(context.Context) (*Project, 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 ProjectMutation) 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 ProjectMutation) 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 *ProjectMutation) 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 *ProjectMutation) 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().Project.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 *ProjectMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ProjectMutation) 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 Project entity. // If the Project 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 *ProjectMutation) 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 *ProjectMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *ProjectMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *ProjectMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the Project entity. // If the Project 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 *ProjectMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ResetDescription resets all changes to the "description" field. func (m *ProjectMutation) ResetDescription() { m.description = nil } // SetURL sets the "url" field. func (m *ProjectMutation) SetURL(s string) { m.url = &s } // URL returns the value of the "url" field in the mutation. func (m *ProjectMutation) 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 Project entity. // If the Project 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 *ProjectMutation) 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 } // ResetURL resets all changes to the "url" field. func (m *ProjectMutation) ResetURL() { m.url = nil } // SetImageURL sets the "image_url" field. func (m *ProjectMutation) SetImageURL(s string) { m.image_url = &s } // ImageURL returns the value of the "image_url" field in the mutation. func (m *ProjectMutation) ImageURL() (r string, exists bool) { v := m.image_url if v == nil { return } return *v, true } // OldImageURL returns the old "image_url" field's value of the Project entity. // If the Project 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 *ProjectMutation) OldImageURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldImageURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldImageURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldImageURL: %w", err) } return oldValue.ImageURL, nil } // ResetImageURL resets all changes to the "image_url" field. func (m *ProjectMutation) ResetImageURL() { m.image_url = nil } // SetDocURL sets the "doc_url" field. func (m *ProjectMutation) SetDocURL(s string) { m.doc_url = &s } // DocURL returns the value of the "doc_url" field in the mutation. func (m *ProjectMutation) DocURL() (r string, exists bool) { v := m.doc_url if v == nil { return } return *v, true } // OldDocURL returns the old "doc_url" field's value of the Project entity. // If the Project 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 *ProjectMutation) OldDocURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDocURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDocURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDocURL: %w", err) } return oldValue.DocURL, nil } // ResetDocURL resets all changes to the "doc_url" field. func (m *ProjectMutation) ResetDocURL() { m.doc_url = nil } // AddUserIDs adds the "users" edge to the User entity by ids. func (m *ProjectMutation) 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 *ProjectMutation) ClearUsers() { m.clearedusers = true } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *ProjectMutation) UsersCleared() bool { return m.clearedusers } // RemoveUserIDs removes the "users" edge to the User entity by IDs. func (m *ProjectMutation) 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 *ProjectMutation) RemovedUsersIDs() (ids []int) { for id := range m.removedusers { ids = append(ids, id) } return } // UsersIDs returns the "users" edge IDs in the mutation. func (m *ProjectMutation) UsersIDs() (ids []int) { for id := range m.users { ids = append(ids, id) } return } // ResetUsers resets all changes to the "users" edge. func (m *ProjectMutation) ResetUsers() { m.users = nil m.clearedusers = false m.removedusers = nil } // AddTeamIDs adds the "teams" edge to the Team entity by ids. func (m *ProjectMutation) AddTeamIDs(ids ...int) { if m.teams == nil { m.teams = make(map[int]struct{}) } for i := range ids { m.teams[ids[i]] = struct{}{} } } // ClearTeams clears the "teams" edge to the Team entity. func (m *ProjectMutation) ClearTeams() { m.clearedteams = true } // TeamsCleared reports if the "teams" edge to the Team entity was cleared. func (m *ProjectMutation) TeamsCleared() bool { return m.clearedteams } // RemoveTeamIDs removes the "teams" edge to the Team entity by IDs. func (m *ProjectMutation) RemoveTeamIDs(ids ...int) { if m.removedteams == nil { m.removedteams = make(map[int]struct{}) } for i := range ids { delete(m.teams, ids[i]) m.removedteams[ids[i]] = struct{}{} } } // RemovedTeams returns the removed IDs of the "teams" edge to the Team entity. func (m *ProjectMutation) RemovedTeamsIDs() (ids []int) { for id := range m.removedteams { ids = append(ids, id) } return } // TeamsIDs returns the "teams" edge IDs in the mutation. func (m *ProjectMutation) TeamsIDs() (ids []int) { for id := range m.teams { ids = append(ids, id) } return } // ResetTeams resets all changes to the "teams" edge. func (m *ProjectMutation) ResetTeams() { m.teams = nil m.clearedteams = false m.removedteams = nil } // Where appends a list predicates to the ProjectMutation builder. func (m *ProjectMutation) Where(ps ...predicate.Project) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ProjectMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ProjectMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Project, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ProjectMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ProjectMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Project). func (m *ProjectMutation) 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 *ProjectMutation) Fields() []string { fields := make([]string, 0, 5) if m.name != nil { fields = append(fields, project.FieldName) } if m.description != nil { fields = append(fields, project.FieldDescription) } if m.url != nil { fields = append(fields, project.FieldURL) } if m.image_url != nil { fields = append(fields, project.FieldImageURL) } if m.doc_url != nil { fields = append(fields, project.FieldDocURL) } 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 *ProjectMutation) Field(name string) (ent.Value, bool) { switch name { case project.FieldName: return m.Name() case project.FieldDescription: return m.Description() case project.FieldURL: return m.URL() case project.FieldImageURL: return m.ImageURL() case project.FieldDocURL: return m.DocURL() } 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 *ProjectMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case project.FieldName: return m.OldName(ctx) case project.FieldDescription: return m.OldDescription(ctx) case project.FieldURL: return m.OldURL(ctx) case project.FieldImageURL: return m.OldImageURL(ctx) case project.FieldDocURL: return m.OldDocURL(ctx) } return nil, fmt.Errorf("unknown Project 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 *ProjectMutation) SetField(name string, value ent.Value) error { switch name { case project.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case project.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case project.FieldURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetURL(v) return nil case project.FieldImageURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetImageURL(v) return nil case project.FieldDocURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDocURL(v) return nil } return fmt.Errorf("unknown Project field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ProjectMutation) 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 *ProjectMutation) 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 *ProjectMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Project numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ProjectMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ProjectMutation) 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 *ProjectMutation) ClearField(name string) error { return fmt.Errorf("unknown Project 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 *ProjectMutation) ResetField(name string) error { switch name { case project.FieldName: m.ResetName() return nil case project.FieldDescription: m.ResetDescription() return nil case project.FieldURL: m.ResetURL() return nil case project.FieldImageURL: m.ResetImageURL() return nil case project.FieldDocURL: m.ResetDocURL() return nil } return fmt.Errorf("unknown Project field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ProjectMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.users != nil { edges = append(edges, project.EdgeUsers) } if m.teams != nil { edges = append(edges, project.EdgeTeams) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ProjectMutation) AddedIDs(name string) []ent.Value { switch name { case project.EdgeUsers: ids := make([]ent.Value, 0, len(m.users)) for id := range m.users { ids = append(ids, id) } return ids case project.EdgeTeams: ids := make([]ent.Value, 0, len(m.teams)) for id := range m.teams { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ProjectMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedusers != nil { edges = append(edges, project.EdgeUsers) } if m.removedteams != nil { edges = append(edges, project.EdgeTeams) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ProjectMutation) RemovedIDs(name string) []ent.Value { switch name { case project.EdgeUsers: ids := make([]ent.Value, 0, len(m.removedusers)) for id := range m.removedusers { ids = append(ids, id) } return ids case project.EdgeTeams: ids := make([]ent.Value, 0, len(m.removedteams)) for id := range m.removedteams { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ProjectMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedusers { edges = append(edges, project.EdgeUsers) } if m.clearedteams { edges = append(edges, project.EdgeTeams) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ProjectMutation) EdgeCleared(name string) bool { switch name { case project.EdgeUsers: return m.clearedusers case project.EdgeTeams: return m.clearedteams } 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 *ProjectMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Project 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 *ProjectMutation) ResetEdge(name string) error { switch name { case project.EdgeUsers: m.ResetUsers() return nil case project.EdgeTeams: m.ResetTeams() return nil } return fmt.Errorf("unknown Project edge %s", name) } // TeamMutation represents an operation that mutates the Team nodes in the graph. type TeamMutation struct { config op Op typ string id *int name *string clearedFields map[string]struct{} projects map[int]struct{} removedprojects map[int]struct{} clearedprojects bool users map[int]struct{} removedusers map[int]struct{} clearedusers bool done bool oldValue func(context.Context) (*Team, error) predicates []predicate.Team } var _ ent.Mutation = (*TeamMutation)(nil) // teamOption allows management of the mutation configuration using functional options. type teamOption func(*TeamMutation) // newTeamMutation creates new mutation for the Team entity. func newTeamMutation(c config, op Op, opts ...teamOption) *TeamMutation { m := &TeamMutation{ config: c, op: op, typ: TypeTeam, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withTeamID sets the ID field of the mutation. func withTeamID(id int) teamOption { return func(m *TeamMutation) { var ( err error once sync.Once value *Team ) m.oldValue = func(ctx context.Context) (*Team, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Team.Get(ctx, id) } }) return value, err } m.id = &id } } // withTeam sets the old Team of the mutation. func withTeam(node *Team) teamOption { return func(m *TeamMutation) { m.oldValue = func(context.Context) (*Team, 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 TeamMutation) 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 TeamMutation) 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 *TeamMutation) 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 *TeamMutation) 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().Team.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 *TeamMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *TeamMutation) 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 Team entity. // If the Team 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 *TeamMutation) 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 *TeamMutation) ResetName() { m.name = nil } // AddProjectIDs adds the "projects" edge to the Project entity by ids. func (m *TeamMutation) AddProjectIDs(ids ...int) { if m.projects == nil { m.projects = make(map[int]struct{}) } for i := range ids { m.projects[ids[i]] = struct{}{} } } // ClearProjects clears the "projects" edge to the Project entity. func (m *TeamMutation) ClearProjects() { m.clearedprojects = true } // ProjectsCleared reports if the "projects" edge to the Project entity was cleared. func (m *TeamMutation) ProjectsCleared() bool { return m.clearedprojects } // RemoveProjectIDs removes the "projects" edge to the Project entity by IDs. func (m *TeamMutation) RemoveProjectIDs(ids ...int) { if m.removedprojects == nil { m.removedprojects = make(map[int]struct{}) } for i := range ids { delete(m.projects, ids[i]) m.removedprojects[ids[i]] = struct{}{} } } // RemovedProjects returns the removed IDs of the "projects" edge to the Project entity. func (m *TeamMutation) RemovedProjectsIDs() (ids []int) { for id := range m.removedprojects { ids = append(ids, id) } return } // ProjectsIDs returns the "projects" edge IDs in the mutation. func (m *TeamMutation) ProjectsIDs() (ids []int) { for id := range m.projects { ids = append(ids, id) } return } // ResetProjects resets all changes to the "projects" edge. func (m *TeamMutation) ResetProjects() { m.projects = nil m.clearedprojects = false m.removedprojects = nil } // AddUserIDs adds the "users" edge to the User entity by ids. func (m *TeamMutation) 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 *TeamMutation) ClearUsers() { m.clearedusers = true } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *TeamMutation) UsersCleared() bool { return m.clearedusers } // RemoveUserIDs removes the "users" edge to the User entity by IDs. func (m *TeamMutation) 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 *TeamMutation) RemovedUsersIDs() (ids []int) { for id := range m.removedusers { ids = append(ids, id) } return } // UsersIDs returns the "users" edge IDs in the mutation. func (m *TeamMutation) UsersIDs() (ids []int) { for id := range m.users { ids = append(ids, id) } return } // ResetUsers resets all changes to the "users" edge. func (m *TeamMutation) ResetUsers() { m.users = nil m.clearedusers = false m.removedusers = nil } // Where appends a list predicates to the TeamMutation builder. func (m *TeamMutation) Where(ps ...predicate.Team) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the TeamMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *TeamMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Team, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *TeamMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *TeamMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Team). func (m *TeamMutation) 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 *TeamMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, team.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 *TeamMutation) Field(name string) (ent.Value, bool) { switch name { case team.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 *TeamMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case team.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown Team 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 *TeamMutation) SetField(name string, value ent.Value) error { switch name { case team.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 Team field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *TeamMutation) 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 *TeamMutation) 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 *TeamMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Team numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TeamMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *TeamMutation) 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 *TeamMutation) ClearField(name string) error { return fmt.Errorf("unknown Team 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 *TeamMutation) ResetField(name string) error { switch name { case team.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown Team field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *TeamMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.projects != nil { edges = append(edges, team.EdgeProjects) } if m.users != nil { edges = append(edges, team.EdgeUsers) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *TeamMutation) AddedIDs(name string) []ent.Value { switch name { case team.EdgeProjects: ids := make([]ent.Value, 0, len(m.projects)) for id := range m.projects { ids = append(ids, id) } return ids case team.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 *TeamMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedprojects != nil { edges = append(edges, team.EdgeProjects) } if m.removedusers != nil { edges = append(edges, team.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 *TeamMutation) RemovedIDs(name string) []ent.Value { switch name { case team.EdgeProjects: ids := make([]ent.Value, 0, len(m.removedprojects)) for id := range m.removedprojects { ids = append(ids, id) } return ids case team.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 *TeamMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedprojects { edges = append(edges, team.EdgeProjects) } if m.clearedusers { edges = append(edges, team.EdgeUsers) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *TeamMutation) EdgeCleared(name string) bool { switch name { case team.EdgeProjects: return m.clearedprojects case team.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 *TeamMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Team 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 *TeamMutation) ResetEdge(name string) error { switch name { case team.EdgeProjects: m.ResetProjects() return nil case team.EdgeUsers: m.ResetUsers() return nil } return fmt.Errorf("unknown Team 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 name *string email *string password *string role *user.Role clearedFields map[string]struct{} teams map[int]struct{} removedteams map[int]struct{} clearedteams bool projects map[int]struct{} removedprojects map[int]struct{} clearedprojects 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) } } // SetName sets the "name" field. func (m *UserMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *UserMutation) 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 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) 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 *UserMutation) ResetName() { m.name = nil } // SetEmail sets the "email" field. func (m *UserMutation) SetEmail(s string) { m.email = &s } // Email returns the value of the "email" field in the mutation. func (m *UserMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old "email" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmail: %w", err) } return oldValue.Email, nil } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil } // SetPassword sets the "password" field. func (m *UserMutation) SetPassword(s string) { m.password = &s } // Password returns the value of the "password" field in the mutation. func (m *UserMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old "password" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPassword requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPassword: %w", err) } return oldValue.Password, nil } // ResetPassword resets all changes to the "password" field. func (m *UserMutation) ResetPassword() { m.password = nil } // SetRole sets the "role" field. func (m *UserMutation) SetRole(u user.Role) { m.role = &u } // Role returns the value of the "role" field in the mutation. func (m *UserMutation) Role() (r user.Role, exists bool) { v := m.role if v == nil { return } return *v, true } // OldRole returns the old "role" 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) OldRole(ctx context.Context) (v user.Role, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRole is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRole requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRole: %w", err) } return oldValue.Role, nil } // ResetRole resets all changes to the "role" field. func (m *UserMutation) ResetRole() { m.role = nil } // AddTeamIDs adds the "teams" edge to the Team entity by ids. func (m *UserMutation) AddTeamIDs(ids ...int) { if m.teams == nil { m.teams = make(map[int]struct{}) } for i := range ids { m.teams[ids[i]] = struct{}{} } } // ClearTeams clears the "teams" edge to the Team entity. func (m *UserMutation) ClearTeams() { m.clearedteams = true } // TeamsCleared reports if the "teams" edge to the Team entity was cleared. func (m *UserMutation) TeamsCleared() bool { return m.clearedteams } // RemoveTeamIDs removes the "teams" edge to the Team entity by IDs. func (m *UserMutation) RemoveTeamIDs(ids ...int) { if m.removedteams == nil { m.removedteams = make(map[int]struct{}) } for i := range ids { delete(m.teams, ids[i]) m.removedteams[ids[i]] = struct{}{} } } // RemovedTeams returns the removed IDs of the "teams" edge to the Team entity. func (m *UserMutation) RemovedTeamsIDs() (ids []int) { for id := range m.removedteams { ids = append(ids, id) } return } // TeamsIDs returns the "teams" edge IDs in the mutation. func (m *UserMutation) TeamsIDs() (ids []int) { for id := range m.teams { ids = append(ids, id) } return } // ResetTeams resets all changes to the "teams" edge. func (m *UserMutation) ResetTeams() { m.teams = nil m.clearedteams = false m.removedteams = nil } // AddProjectIDs adds the "projects" edge to the Project entity by ids. func (m *UserMutation) AddProjectIDs(ids ...int) { if m.projects == nil { m.projects = make(map[int]struct{}) } for i := range ids { m.projects[ids[i]] = struct{}{} } } // ClearProjects clears the "projects" edge to the Project entity. func (m *UserMutation) ClearProjects() { m.clearedprojects = true } // ProjectsCleared reports if the "projects" edge to the Project entity was cleared. func (m *UserMutation) ProjectsCleared() bool { return m.clearedprojects } // RemoveProjectIDs removes the "projects" edge to the Project entity by IDs. func (m *UserMutation) RemoveProjectIDs(ids ...int) { if m.removedprojects == nil { m.removedprojects = make(map[int]struct{}) } for i := range ids { delete(m.projects, ids[i]) m.removedprojects[ids[i]] = struct{}{} } } // RemovedProjects returns the removed IDs of the "projects" edge to the Project entity. func (m *UserMutation) RemovedProjectsIDs() (ids []int) { for id := range m.removedprojects { ids = append(ids, id) } return } // ProjectsIDs returns the "projects" edge IDs in the mutation. func (m *UserMutation) ProjectsIDs() (ids []int) { for id := range m.projects { ids = append(ids, id) } return } // ResetProjects resets all changes to the "projects" edge. func (m *UserMutation) ResetProjects() { m.projects = nil m.clearedprojects = false m.removedprojects = 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.name != nil { fields = append(fields, user.FieldName) } if m.email != nil { fields = append(fields, user.FieldEmail) } if m.password != nil { fields = append(fields, user.FieldPassword) } if m.role != nil { fields = append(fields, user.FieldRole) } 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.FieldName: return m.Name() case user.FieldEmail: return m.Email() case user.FieldPassword: return m.Password() case user.FieldRole: return m.Role() } 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.FieldName: return m.OldName(ctx) case user.FieldEmail: return m.OldEmail(ctx) case user.FieldPassword: return m.OldPassword(ctx) case user.FieldRole: return m.OldRole(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.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case user.FieldEmail: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmail(v) return nil case user.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(v) return nil case user.FieldRole: v, ok := value.(user.Role) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRole(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 { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *UserMutation) ClearField(name string) error { return fmt.Errorf("unknown User nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *UserMutation) ResetField(name string) error { switch name { case user.FieldName: m.ResetName() return nil case user.FieldEmail: m.ResetEmail() return nil case user.FieldPassword: m.ResetPassword() return nil case user.FieldRole: m.ResetRole() 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, 2) if m.teams != nil { edges = append(edges, user.EdgeTeams) } if m.projects != nil { edges = append(edges, user.EdgeProjects) } 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.EdgeTeams: ids := make([]ent.Value, 0, len(m.teams)) for id := range m.teams { ids = append(ids, id) } return ids case user.EdgeProjects: ids := make([]ent.Value, 0, len(m.projects)) for id := range m.projects { 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, 2) if m.removedteams != nil { edges = append(edges, user.EdgeTeams) } if m.removedprojects != nil { edges = append(edges, user.EdgeProjects) } 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.EdgeTeams: ids := make([]ent.Value, 0, len(m.removedteams)) for id := range m.removedteams { ids = append(ids, id) } return ids case user.EdgeProjects: ids := make([]ent.Value, 0, len(m.removedprojects)) for id := range m.removedprojects { 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, 2) if m.clearedteams { edges = append(edges, user.EdgeTeams) } if m.clearedprojects { edges = append(edges, user.EdgeProjects) } 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.EdgeTeams: return m.clearedteams case user.EdgeProjects: return m.clearedprojects } 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.EdgeTeams: m.ResetTeams() return nil case user.EdgeProjects: m.ResetProjects() return nil } return fmt.Errorf("unknown User edge %s", name) }