// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "git.dcentral.systems/toolz/goplt/internal/ent/auditlog" "git.dcentral.systems/toolz/goplt/internal/ent/permission" "git.dcentral.systems/toolz/goplt/internal/ent/predicate" "git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken" "git.dcentral.systems/toolz/goplt/internal/ent/role" "git.dcentral.systems/toolz/goplt/internal/ent/rolepermission" "git.dcentral.systems/toolz/goplt/internal/ent/user" "git.dcentral.systems/toolz/goplt/internal/ent/userrole" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeAuditLog = "AuditLog" TypePermission = "Permission" TypeRefreshToken = "RefreshToken" TypeRole = "Role" TypeRolePermission = "RolePermission" TypeUser = "User" TypeUserRole = "UserRole" ) // AuditLogMutation represents an operation that mutates the AuditLog nodes in the graph. type AuditLogMutation struct { config op Op typ string id *string user_id *string action *string resource *string resource_id *string ip_address *string user_agent *string metadata *map[string]interface{} timestamp *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*AuditLog, error) predicates []predicate.AuditLog } var _ ent.Mutation = (*AuditLogMutation)(nil) // auditlogOption allows management of the mutation configuration using functional options. type auditlogOption func(*AuditLogMutation) // newAuditLogMutation creates new mutation for the AuditLog entity. func newAuditLogMutation(c config, op Op, opts ...auditlogOption) *AuditLogMutation { m := &AuditLogMutation{ config: c, op: op, typ: TypeAuditLog, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAuditLogID sets the ID field of the mutation. func withAuditLogID(id string) auditlogOption { return func(m *AuditLogMutation) { var ( err error once sync.Once value *AuditLog ) m.oldValue = func(ctx context.Context) (*AuditLog, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AuditLog.Get(ctx, id) } }) return value, err } m.id = &id } } // withAuditLog sets the old AuditLog of the mutation. func withAuditLog(node *AuditLog) auditlogOption { return func(m *AuditLogMutation) { m.oldValue = func(context.Context) (*AuditLog, 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 AuditLogMutation) 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 AuditLogMutation) 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 } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of AuditLog entities. func (m *AuditLogMutation) SetID(id string) { m.id = &id } // 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 *AuditLogMutation) ID() (id string, 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 *AuditLogMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().AuditLog.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUserID sets the "user_id" field. func (m *AuditLogMutation) SetUserID(s string) { m.user_id = &s } // UserID returns the value of the "user_id" field in the mutation. func (m *AuditLogMutation) UserID() (r string, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *AuditLogMutation) ResetUserID() { m.user_id = nil } // SetAction sets the "action" field. func (m *AuditLogMutation) SetAction(s string) { m.action = &s } // Action returns the value of the "action" field in the mutation. func (m *AuditLogMutation) Action() (r string, exists bool) { v := m.action if v == nil { return } return *v, true } // OldAction returns the old "action" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldAction(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAction is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAction requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAction: %w", err) } return oldValue.Action, nil } // ResetAction resets all changes to the "action" field. func (m *AuditLogMutation) ResetAction() { m.action = nil } // SetResource sets the "resource" field. func (m *AuditLogMutation) SetResource(s string) { m.resource = &s } // Resource returns the value of the "resource" field in the mutation. func (m *AuditLogMutation) Resource() (r string, exists bool) { v := m.resource if v == nil { return } return *v, true } // OldResource returns the old "resource" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldResource(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldResource is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldResource requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldResource: %w", err) } return oldValue.Resource, nil } // ClearResource clears the value of the "resource" field. func (m *AuditLogMutation) ClearResource() { m.resource = nil m.clearedFields[auditlog.FieldResource] = struct{}{} } // ResourceCleared returns if the "resource" field was cleared in this mutation. func (m *AuditLogMutation) ResourceCleared() bool { _, ok := m.clearedFields[auditlog.FieldResource] return ok } // ResetResource resets all changes to the "resource" field. func (m *AuditLogMutation) ResetResource() { m.resource = nil delete(m.clearedFields, auditlog.FieldResource) } // SetResourceID sets the "resource_id" field. func (m *AuditLogMutation) SetResourceID(s string) { m.resource_id = &s } // ResourceID returns the value of the "resource_id" field in the mutation. func (m *AuditLogMutation) ResourceID() (r string, exists bool) { v := m.resource_id if v == nil { return } return *v, true } // OldResourceID returns the old "resource_id" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldResourceID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldResourceID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldResourceID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldResourceID: %w", err) } return oldValue.ResourceID, nil } // ClearResourceID clears the value of the "resource_id" field. func (m *AuditLogMutation) ClearResourceID() { m.resource_id = nil m.clearedFields[auditlog.FieldResourceID] = struct{}{} } // ResourceIDCleared returns if the "resource_id" field was cleared in this mutation. func (m *AuditLogMutation) ResourceIDCleared() bool { _, ok := m.clearedFields[auditlog.FieldResourceID] return ok } // ResetResourceID resets all changes to the "resource_id" field. func (m *AuditLogMutation) ResetResourceID() { m.resource_id = nil delete(m.clearedFields, auditlog.FieldResourceID) } // SetIPAddress sets the "ip_address" field. func (m *AuditLogMutation) SetIPAddress(s string) { m.ip_address = &s } // IPAddress returns the value of the "ip_address" field in the mutation. func (m *AuditLogMutation) IPAddress() (r string, exists bool) { v := m.ip_address if v == nil { return } return *v, true } // OldIPAddress returns the old "ip_address" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldIPAddress(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIPAddress is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIPAddress requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIPAddress: %w", err) } return oldValue.IPAddress, nil } // ClearIPAddress clears the value of the "ip_address" field. func (m *AuditLogMutation) ClearIPAddress() { m.ip_address = nil m.clearedFields[auditlog.FieldIPAddress] = struct{}{} } // IPAddressCleared returns if the "ip_address" field was cleared in this mutation. func (m *AuditLogMutation) IPAddressCleared() bool { _, ok := m.clearedFields[auditlog.FieldIPAddress] return ok } // ResetIPAddress resets all changes to the "ip_address" field. func (m *AuditLogMutation) ResetIPAddress() { m.ip_address = nil delete(m.clearedFields, auditlog.FieldIPAddress) } // SetUserAgent sets the "user_agent" field. func (m *AuditLogMutation) SetUserAgent(s string) { m.user_agent = &s } // UserAgent returns the value of the "user_agent" field in the mutation. func (m *AuditLogMutation) UserAgent() (r string, exists bool) { v := m.user_agent if v == nil { return } return *v, true } // OldUserAgent returns the old "user_agent" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldUserAgent(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserAgent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserAgent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserAgent: %w", err) } return oldValue.UserAgent, nil } // ClearUserAgent clears the value of the "user_agent" field. func (m *AuditLogMutation) ClearUserAgent() { m.user_agent = nil m.clearedFields[auditlog.FieldUserAgent] = struct{}{} } // UserAgentCleared returns if the "user_agent" field was cleared in this mutation. func (m *AuditLogMutation) UserAgentCleared() bool { _, ok := m.clearedFields[auditlog.FieldUserAgent] return ok } // ResetUserAgent resets all changes to the "user_agent" field. func (m *AuditLogMutation) ResetUserAgent() { m.user_agent = nil delete(m.clearedFields, auditlog.FieldUserAgent) } // SetMetadata sets the "metadata" field. func (m *AuditLogMutation) SetMetadata(value map[string]interface{}) { m.metadata = &value } // Metadata returns the value of the "metadata" field in the mutation. func (m *AuditLogMutation) Metadata() (r map[string]interface{}, exists bool) { v := m.metadata if v == nil { return } return *v, true } // OldMetadata returns the old "metadata" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldMetadata(ctx context.Context) (v map[string]interface{}, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldMetadata is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldMetadata requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldMetadata: %w", err) } return oldValue.Metadata, nil } // ClearMetadata clears the value of the "metadata" field. func (m *AuditLogMutation) ClearMetadata() { m.metadata = nil m.clearedFields[auditlog.FieldMetadata] = struct{}{} } // MetadataCleared returns if the "metadata" field was cleared in this mutation. func (m *AuditLogMutation) MetadataCleared() bool { _, ok := m.clearedFields[auditlog.FieldMetadata] return ok } // ResetMetadata resets all changes to the "metadata" field. func (m *AuditLogMutation) ResetMetadata() { m.metadata = nil delete(m.clearedFields, auditlog.FieldMetadata) } // SetTimestamp sets the "timestamp" field. func (m *AuditLogMutation) SetTimestamp(t time.Time) { m.timestamp = &t } // Timestamp returns the value of the "timestamp" field in the mutation. func (m *AuditLogMutation) Timestamp() (r time.Time, exists bool) { v := m.timestamp if v == nil { return } return *v, true } // OldTimestamp returns the old "timestamp" field's value of the AuditLog entity. // If the AuditLog 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 *AuditLogMutation) OldTimestamp(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTimestamp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTimestamp requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTimestamp: %w", err) } return oldValue.Timestamp, nil } // ResetTimestamp resets all changes to the "timestamp" field. func (m *AuditLogMutation) ResetTimestamp() { m.timestamp = nil } // Where appends a list predicates to the AuditLogMutation builder. func (m *AuditLogMutation) Where(ps ...predicate.AuditLog) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AuditLogMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AuditLogMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.AuditLog, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AuditLogMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AuditLogMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (AuditLog). func (m *AuditLogMutation) 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 *AuditLogMutation) Fields() []string { fields := make([]string, 0, 8) if m.user_id != nil { fields = append(fields, auditlog.FieldUserID) } if m.action != nil { fields = append(fields, auditlog.FieldAction) } if m.resource != nil { fields = append(fields, auditlog.FieldResource) } if m.resource_id != nil { fields = append(fields, auditlog.FieldResourceID) } if m.ip_address != nil { fields = append(fields, auditlog.FieldIPAddress) } if m.user_agent != nil { fields = append(fields, auditlog.FieldUserAgent) } if m.metadata != nil { fields = append(fields, auditlog.FieldMetadata) } if m.timestamp != nil { fields = append(fields, auditlog.FieldTimestamp) } 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 *AuditLogMutation) Field(name string) (ent.Value, bool) { switch name { case auditlog.FieldUserID: return m.UserID() case auditlog.FieldAction: return m.Action() case auditlog.FieldResource: return m.Resource() case auditlog.FieldResourceID: return m.ResourceID() case auditlog.FieldIPAddress: return m.IPAddress() case auditlog.FieldUserAgent: return m.UserAgent() case auditlog.FieldMetadata: return m.Metadata() case auditlog.FieldTimestamp: return m.Timestamp() } 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 *AuditLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case auditlog.FieldUserID: return m.OldUserID(ctx) case auditlog.FieldAction: return m.OldAction(ctx) case auditlog.FieldResource: return m.OldResource(ctx) case auditlog.FieldResourceID: return m.OldResourceID(ctx) case auditlog.FieldIPAddress: return m.OldIPAddress(ctx) case auditlog.FieldUserAgent: return m.OldUserAgent(ctx) case auditlog.FieldMetadata: return m.OldMetadata(ctx) case auditlog.FieldTimestamp: return m.OldTimestamp(ctx) } return nil, fmt.Errorf("unknown AuditLog 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 *AuditLogMutation) SetField(name string, value ent.Value) error { switch name { case auditlog.FieldUserID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case auditlog.FieldAction: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAction(v) return nil case auditlog.FieldResource: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetResource(v) return nil case auditlog.FieldResourceID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetResourceID(v) return nil case auditlog.FieldIPAddress: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIPAddress(v) return nil case auditlog.FieldUserAgent: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserAgent(v) return nil case auditlog.FieldMetadata: v, ok := value.(map[string]interface{}) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMetadata(v) return nil case auditlog.FieldTimestamp: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTimestamp(v) return nil } return fmt.Errorf("unknown AuditLog field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AuditLogMutation) 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 *AuditLogMutation) 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 *AuditLogMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown AuditLog numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AuditLogMutation) ClearedFields() []string { var fields []string if m.FieldCleared(auditlog.FieldResource) { fields = append(fields, auditlog.FieldResource) } if m.FieldCleared(auditlog.FieldResourceID) { fields = append(fields, auditlog.FieldResourceID) } if m.FieldCleared(auditlog.FieldIPAddress) { fields = append(fields, auditlog.FieldIPAddress) } if m.FieldCleared(auditlog.FieldUserAgent) { fields = append(fields, auditlog.FieldUserAgent) } if m.FieldCleared(auditlog.FieldMetadata) { fields = append(fields, auditlog.FieldMetadata) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AuditLogMutation) 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 *AuditLogMutation) ClearField(name string) error { switch name { case auditlog.FieldResource: m.ClearResource() return nil case auditlog.FieldResourceID: m.ClearResourceID() return nil case auditlog.FieldIPAddress: m.ClearIPAddress() return nil case auditlog.FieldUserAgent: m.ClearUserAgent() return nil case auditlog.FieldMetadata: m.ClearMetadata() return nil } return fmt.Errorf("unknown AuditLog 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 *AuditLogMutation) ResetField(name string) error { switch name { case auditlog.FieldUserID: m.ResetUserID() return nil case auditlog.FieldAction: m.ResetAction() return nil case auditlog.FieldResource: m.ResetResource() return nil case auditlog.FieldResourceID: m.ResetResourceID() return nil case auditlog.FieldIPAddress: m.ResetIPAddress() return nil case auditlog.FieldUserAgent: m.ResetUserAgent() return nil case auditlog.FieldMetadata: m.ResetMetadata() return nil case auditlog.FieldTimestamp: m.ResetTimestamp() return nil } return fmt.Errorf("unknown AuditLog field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AuditLogMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AuditLogMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AuditLogMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AuditLogMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AuditLogMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AuditLogMutation) EdgeCleared(name string) bool { return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *AuditLogMutation) ClearEdge(name string) error { return fmt.Errorf("unknown AuditLog 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 *AuditLogMutation) ResetEdge(name string) error { return fmt.Errorf("unknown AuditLog edge %s", name) } // PermissionMutation represents an operation that mutates the Permission nodes in the graph. type PermissionMutation struct { config op Op typ string id *string name *string clearedFields map[string]struct{} role_permissions map[int]struct{} removedrole_permissions map[int]struct{} clearedrole_permissions bool done bool oldValue func(context.Context) (*Permission, error) predicates []predicate.Permission } var _ ent.Mutation = (*PermissionMutation)(nil) // permissionOption allows management of the mutation configuration using functional options. type permissionOption func(*PermissionMutation) // newPermissionMutation creates new mutation for the Permission entity. func newPermissionMutation(c config, op Op, opts ...permissionOption) *PermissionMutation { m := &PermissionMutation{ config: c, op: op, typ: TypePermission, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withPermissionID sets the ID field of the mutation. func withPermissionID(id string) permissionOption { return func(m *PermissionMutation) { var ( err error once sync.Once value *Permission ) m.oldValue = func(ctx context.Context) (*Permission, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Permission.Get(ctx, id) } }) return value, err } m.id = &id } } // withPermission sets the old Permission of the mutation. func withPermission(node *Permission) permissionOption { return func(m *PermissionMutation) { m.oldValue = func(context.Context) (*Permission, 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 PermissionMutation) 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 PermissionMutation) 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 } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Permission entities. func (m *PermissionMutation) SetID(id string) { m.id = &id } // 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 *PermissionMutation) ID() (id string, 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 *PermissionMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Permission.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 *PermissionMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *PermissionMutation) 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 Permission entity. // If the Permission 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 *PermissionMutation) 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 *PermissionMutation) ResetName() { m.name = nil } // AddRolePermissionIDs adds the "role_permissions" edge to the RolePermission entity by ids. func (m *PermissionMutation) AddRolePermissionIDs(ids ...int) { if m.role_permissions == nil { m.role_permissions = make(map[int]struct{}) } for i := range ids { m.role_permissions[ids[i]] = struct{}{} } } // ClearRolePermissions clears the "role_permissions" edge to the RolePermission entity. func (m *PermissionMutation) ClearRolePermissions() { m.clearedrole_permissions = true } // RolePermissionsCleared reports if the "role_permissions" edge to the RolePermission entity was cleared. func (m *PermissionMutation) RolePermissionsCleared() bool { return m.clearedrole_permissions } // RemoveRolePermissionIDs removes the "role_permissions" edge to the RolePermission entity by IDs. func (m *PermissionMutation) RemoveRolePermissionIDs(ids ...int) { if m.removedrole_permissions == nil { m.removedrole_permissions = make(map[int]struct{}) } for i := range ids { delete(m.role_permissions, ids[i]) m.removedrole_permissions[ids[i]] = struct{}{} } } // RemovedRolePermissions returns the removed IDs of the "role_permissions" edge to the RolePermission entity. func (m *PermissionMutation) RemovedRolePermissionsIDs() (ids []int) { for id := range m.removedrole_permissions { ids = append(ids, id) } return } // RolePermissionsIDs returns the "role_permissions" edge IDs in the mutation. func (m *PermissionMutation) RolePermissionsIDs() (ids []int) { for id := range m.role_permissions { ids = append(ids, id) } return } // ResetRolePermissions resets all changes to the "role_permissions" edge. func (m *PermissionMutation) ResetRolePermissions() { m.role_permissions = nil m.clearedrole_permissions = false m.removedrole_permissions = nil } // Where appends a list predicates to the PermissionMutation builder. func (m *PermissionMutation) Where(ps ...predicate.Permission) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the PermissionMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *PermissionMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Permission, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *PermissionMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *PermissionMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Permission). func (m *PermissionMutation) 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 *PermissionMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, permission.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 *PermissionMutation) Field(name string) (ent.Value, bool) { switch name { case permission.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 *PermissionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case permission.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown Permission 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 *PermissionMutation) SetField(name string, value ent.Value) error { switch name { case permission.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 Permission field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *PermissionMutation) 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 *PermissionMutation) 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 *PermissionMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Permission numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *PermissionMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *PermissionMutation) 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 *PermissionMutation) ClearField(name string) error { return fmt.Errorf("unknown Permission 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 *PermissionMutation) ResetField(name string) error { switch name { case permission.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown Permission field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *PermissionMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.role_permissions != nil { edges = append(edges, permission.EdgeRolePermissions) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *PermissionMutation) AddedIDs(name string) []ent.Value { switch name { case permission.EdgeRolePermissions: ids := make([]ent.Value, 0, len(m.role_permissions)) for id := range m.role_permissions { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PermissionMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedrole_permissions != nil { edges = append(edges, permission.EdgeRolePermissions) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PermissionMutation) RemovedIDs(name string) []ent.Value { switch name { case permission.EdgeRolePermissions: ids := make([]ent.Value, 0, len(m.removedrole_permissions)) for id := range m.removedrole_permissions { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PermissionMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedrole_permissions { edges = append(edges, permission.EdgeRolePermissions) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *PermissionMutation) EdgeCleared(name string) bool { switch name { case permission.EdgeRolePermissions: return m.clearedrole_permissions } 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 *PermissionMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Permission 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 *PermissionMutation) ResetEdge(name string) error { switch name { case permission.EdgeRolePermissions: m.ResetRolePermissions() return nil } return fmt.Errorf("unknown Permission edge %s", name) } // RefreshTokenMutation represents an operation that mutates the RefreshToken nodes in the graph. type RefreshTokenMutation struct { config op Op typ string id *string user_id *string token_hash *string expires_at *time.Time created_at *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*RefreshToken, error) predicates []predicate.RefreshToken } var _ ent.Mutation = (*RefreshTokenMutation)(nil) // refreshtokenOption allows management of the mutation configuration using functional options. type refreshtokenOption func(*RefreshTokenMutation) // newRefreshTokenMutation creates new mutation for the RefreshToken entity. func newRefreshTokenMutation(c config, op Op, opts ...refreshtokenOption) *RefreshTokenMutation { m := &RefreshTokenMutation{ config: c, op: op, typ: TypeRefreshToken, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withRefreshTokenID sets the ID field of the mutation. func withRefreshTokenID(id string) refreshtokenOption { return func(m *RefreshTokenMutation) { var ( err error once sync.Once value *RefreshToken ) m.oldValue = func(ctx context.Context) (*RefreshToken, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().RefreshToken.Get(ctx, id) } }) return value, err } m.id = &id } } // withRefreshToken sets the old RefreshToken of the mutation. func withRefreshToken(node *RefreshToken) refreshtokenOption { return func(m *RefreshTokenMutation) { m.oldValue = func(context.Context) (*RefreshToken, 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 RefreshTokenMutation) 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 RefreshTokenMutation) 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 } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of RefreshToken entities. func (m *RefreshTokenMutation) SetID(id string) { m.id = &id } // 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 *RefreshTokenMutation) ID() (id string, 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 *RefreshTokenMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().RefreshToken.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUserID sets the "user_id" field. func (m *RefreshTokenMutation) SetUserID(s string) { m.user_id = &s } // UserID returns the value of the "user_id" field in the mutation. func (m *RefreshTokenMutation) UserID() (r string, exists bool) { v := m.user_id if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the RefreshToken entity. // If the RefreshToken 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 *RefreshTokenMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *RefreshTokenMutation) ResetUserID() { m.user_id = nil } // SetTokenHash sets the "token_hash" field. func (m *RefreshTokenMutation) SetTokenHash(s string) { m.token_hash = &s } // TokenHash returns the value of the "token_hash" field in the mutation. func (m *RefreshTokenMutation) TokenHash() (r string, exists bool) { v := m.token_hash if v == nil { return } return *v, true } // OldTokenHash returns the old "token_hash" field's value of the RefreshToken entity. // If the RefreshToken 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 *RefreshTokenMutation) OldTokenHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTokenHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTokenHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTokenHash: %w", err) } return oldValue.TokenHash, nil } // ResetTokenHash resets all changes to the "token_hash" field. func (m *RefreshTokenMutation) ResetTokenHash() { m.token_hash = nil } // SetExpiresAt sets the "expires_at" field. func (m *RefreshTokenMutation) SetExpiresAt(t time.Time) { m.expires_at = &t } // ExpiresAt returns the value of the "expires_at" field in the mutation. func (m *RefreshTokenMutation) ExpiresAt() (r time.Time, exists bool) { v := m.expires_at if v == nil { return } return *v, true } // OldExpiresAt returns the old "expires_at" field's value of the RefreshToken entity. // If the RefreshToken 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 *RefreshTokenMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldExpiresAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err) } return oldValue.ExpiresAt, nil } // ResetExpiresAt resets all changes to the "expires_at" field. func (m *RefreshTokenMutation) ResetExpiresAt() { m.expires_at = nil } // SetCreatedAt sets the "created_at" field. func (m *RefreshTokenMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *RefreshTokenMutation) 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 RefreshToken entity. // If the RefreshToken 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 *RefreshTokenMutation) 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 } // ResetCreatedAt resets all changes to the "created_at" field. func (m *RefreshTokenMutation) ResetCreatedAt() { m.created_at = nil } // Where appends a list predicates to the RefreshTokenMutation builder. func (m *RefreshTokenMutation) Where(ps ...predicate.RefreshToken) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the RefreshTokenMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *RefreshTokenMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.RefreshToken, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *RefreshTokenMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *RefreshTokenMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (RefreshToken). func (m *RefreshTokenMutation) 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 *RefreshTokenMutation) Fields() []string { fields := make([]string, 0, 4) if m.user_id != nil { fields = append(fields, refreshtoken.FieldUserID) } if m.token_hash != nil { fields = append(fields, refreshtoken.FieldTokenHash) } if m.expires_at != nil { fields = append(fields, refreshtoken.FieldExpiresAt) } if m.created_at != nil { fields = append(fields, refreshtoken.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 *RefreshTokenMutation) Field(name string) (ent.Value, bool) { switch name { case refreshtoken.FieldUserID: return m.UserID() case refreshtoken.FieldTokenHash: return m.TokenHash() case refreshtoken.FieldExpiresAt: return m.ExpiresAt() case refreshtoken.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 *RefreshTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case refreshtoken.FieldUserID: return m.OldUserID(ctx) case refreshtoken.FieldTokenHash: return m.OldTokenHash(ctx) case refreshtoken.FieldExpiresAt: return m.OldExpiresAt(ctx) case refreshtoken.FieldCreatedAt: return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown RefreshToken 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 *RefreshTokenMutation) SetField(name string, value ent.Value) error { switch name { case refreshtoken.FieldUserID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case refreshtoken.FieldTokenHash: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTokenHash(v) return nil case refreshtoken.FieldExpiresAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetExpiresAt(v) return nil case refreshtoken.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 RefreshToken field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *RefreshTokenMutation) 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 *RefreshTokenMutation) 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 *RefreshTokenMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown RefreshToken numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *RefreshTokenMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *RefreshTokenMutation) 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 *RefreshTokenMutation) ClearField(name string) error { return fmt.Errorf("unknown RefreshToken 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 *RefreshTokenMutation) ResetField(name string) error { switch name { case refreshtoken.FieldUserID: m.ResetUserID() return nil case refreshtoken.FieldTokenHash: m.ResetTokenHash() return nil case refreshtoken.FieldExpiresAt: m.ResetExpiresAt() return nil case refreshtoken.FieldCreatedAt: m.ResetCreatedAt() return nil } return fmt.Errorf("unknown RefreshToken field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *RefreshTokenMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *RefreshTokenMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *RefreshTokenMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *RefreshTokenMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RefreshTokenMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *RefreshTokenMutation) EdgeCleared(name string) bool { return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *RefreshTokenMutation) ClearEdge(name string) error { return fmt.Errorf("unknown RefreshToken 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 *RefreshTokenMutation) ResetEdge(name string) error { return fmt.Errorf("unknown RefreshToken edge %s", name) } // RoleMutation represents an operation that mutates the Role nodes in the graph. type RoleMutation struct { config op Op typ string id *string name *string description *string created_at *time.Time clearedFields map[string]struct{} role_permissions map[int]struct{} removedrole_permissions map[int]struct{} clearedrole_permissions bool user_roles map[int]struct{} removeduser_roles map[int]struct{} cleareduser_roles bool done bool oldValue func(context.Context) (*Role, error) predicates []predicate.Role } var _ ent.Mutation = (*RoleMutation)(nil) // roleOption allows management of the mutation configuration using functional options. type roleOption func(*RoleMutation) // newRoleMutation creates new mutation for the Role entity. func newRoleMutation(c config, op Op, opts ...roleOption) *RoleMutation { m := &RoleMutation{ config: c, op: op, typ: TypeRole, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withRoleID sets the ID field of the mutation. func withRoleID(id string) roleOption { return func(m *RoleMutation) { var ( err error once sync.Once value *Role ) m.oldValue = func(ctx context.Context) (*Role, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Role.Get(ctx, id) } }) return value, err } m.id = &id } } // withRole sets the old Role of the mutation. func withRole(node *Role) roleOption { return func(m *RoleMutation) { m.oldValue = func(context.Context) (*Role, 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 RoleMutation) 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 RoleMutation) 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 } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Role entities. func (m *RoleMutation) SetID(id string) { m.id = &id } // 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 *RoleMutation) ID() (id string, 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 *RoleMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Role.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 *RoleMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 *RoleMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *RoleMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 } // ClearDescription clears the value of the "description" field. func (m *RoleMutation) ClearDescription() { m.description = nil m.clearedFields[role.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *RoleMutation) DescriptionCleared() bool { _, ok := m.clearedFields[role.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *RoleMutation) ResetDescription() { m.description = nil delete(m.clearedFields, role.FieldDescription) } // SetCreatedAt sets the "created_at" field. func (m *RoleMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 } // ResetCreatedAt resets all changes to the "created_at" field. func (m *RoleMutation) ResetCreatedAt() { m.created_at = nil } // AddRolePermissionIDs adds the "role_permissions" edge to the RolePermission entity by ids. func (m *RoleMutation) AddRolePermissionIDs(ids ...int) { if m.role_permissions == nil { m.role_permissions = make(map[int]struct{}) } for i := range ids { m.role_permissions[ids[i]] = struct{}{} } } // ClearRolePermissions clears the "role_permissions" edge to the RolePermission entity. func (m *RoleMutation) ClearRolePermissions() { m.clearedrole_permissions = true } // RolePermissionsCleared reports if the "role_permissions" edge to the RolePermission entity was cleared. func (m *RoleMutation) RolePermissionsCleared() bool { return m.clearedrole_permissions } // RemoveRolePermissionIDs removes the "role_permissions" edge to the RolePermission entity by IDs. func (m *RoleMutation) RemoveRolePermissionIDs(ids ...int) { if m.removedrole_permissions == nil { m.removedrole_permissions = make(map[int]struct{}) } for i := range ids { delete(m.role_permissions, ids[i]) m.removedrole_permissions[ids[i]] = struct{}{} } } // RemovedRolePermissions returns the removed IDs of the "role_permissions" edge to the RolePermission entity. func (m *RoleMutation) RemovedRolePermissionsIDs() (ids []int) { for id := range m.removedrole_permissions { ids = append(ids, id) } return } // RolePermissionsIDs returns the "role_permissions" edge IDs in the mutation. func (m *RoleMutation) RolePermissionsIDs() (ids []int) { for id := range m.role_permissions { ids = append(ids, id) } return } // ResetRolePermissions resets all changes to the "role_permissions" edge. func (m *RoleMutation) ResetRolePermissions() { m.role_permissions = nil m.clearedrole_permissions = false m.removedrole_permissions = nil } // AddUserRoleIDs adds the "user_roles" edge to the UserRole entity by ids. func (m *RoleMutation) AddUserRoleIDs(ids ...int) { if m.user_roles == nil { m.user_roles = make(map[int]struct{}) } for i := range ids { m.user_roles[ids[i]] = struct{}{} } } // ClearUserRoles clears the "user_roles" edge to the UserRole entity. func (m *RoleMutation) ClearUserRoles() { m.cleareduser_roles = true } // UserRolesCleared reports if the "user_roles" edge to the UserRole entity was cleared. func (m *RoleMutation) UserRolesCleared() bool { return m.cleareduser_roles } // RemoveUserRoleIDs removes the "user_roles" edge to the UserRole entity by IDs. func (m *RoleMutation) RemoveUserRoleIDs(ids ...int) { if m.removeduser_roles == nil { m.removeduser_roles = make(map[int]struct{}) } for i := range ids { delete(m.user_roles, ids[i]) m.removeduser_roles[ids[i]] = struct{}{} } } // RemovedUserRoles returns the removed IDs of the "user_roles" edge to the UserRole entity. func (m *RoleMutation) RemovedUserRolesIDs() (ids []int) { for id := range m.removeduser_roles { ids = append(ids, id) } return } // UserRolesIDs returns the "user_roles" edge IDs in the mutation. func (m *RoleMutation) UserRolesIDs() (ids []int) { for id := range m.user_roles { ids = append(ids, id) } return } // ResetUserRoles resets all changes to the "user_roles" edge. func (m *RoleMutation) ResetUserRoles() { m.user_roles = nil m.cleareduser_roles = false m.removeduser_roles = nil } // Where appends a list predicates to the RoleMutation builder. func (m *RoleMutation) Where(ps ...predicate.Role) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the RoleMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *RoleMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Role, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *RoleMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *RoleMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Role). func (m *RoleMutation) 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 *RoleMutation) Fields() []string { fields := make([]string, 0, 3) if m.name != nil { fields = append(fields, role.FieldName) } if m.description != nil { fields = append(fields, role.FieldDescription) } if m.created_at != nil { fields = append(fields, role.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 *RoleMutation) Field(name string) (ent.Value, bool) { switch name { case role.FieldName: return m.Name() case role.FieldDescription: return m.Description() case role.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 *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case role.FieldName: return m.OldName(ctx) case role.FieldDescription: return m.OldDescription(ctx) case role.FieldCreatedAt: return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown Role 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 *RoleMutation) SetField(name string, value ent.Value) error { switch name { case role.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case role.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case role.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 Role field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *RoleMutation) 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 *RoleMutation) 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 *RoleMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Role numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *RoleMutation) ClearedFields() []string { var fields []string if m.FieldCleared(role.FieldDescription) { fields = append(fields, role.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *RoleMutation) 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 *RoleMutation) ClearField(name string) error { switch name { case role.FieldDescription: m.ClearDescription() return nil } return fmt.Errorf("unknown Role 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 *RoleMutation) ResetField(name string) error { switch name { case role.FieldName: m.ResetName() return nil case role.FieldDescription: m.ResetDescription() return nil case role.FieldCreatedAt: m.ResetCreatedAt() return nil } return fmt.Errorf("unknown Role field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *RoleMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.role_permissions != nil { edges = append(edges, role.EdgeRolePermissions) } if m.user_roles != nil { edges = append(edges, role.EdgeUserRoles) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *RoleMutation) AddedIDs(name string) []ent.Value { switch name { case role.EdgeRolePermissions: ids := make([]ent.Value, 0, len(m.role_permissions)) for id := range m.role_permissions { ids = append(ids, id) } return ids case role.EdgeUserRoles: ids := make([]ent.Value, 0, len(m.user_roles)) for id := range m.user_roles { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *RoleMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedrole_permissions != nil { edges = append(edges, role.EdgeRolePermissions) } if m.removeduser_roles != nil { edges = append(edges, role.EdgeUserRoles) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *RoleMutation) RemovedIDs(name string) []ent.Value { switch name { case role.EdgeRolePermissions: ids := make([]ent.Value, 0, len(m.removedrole_permissions)) for id := range m.removedrole_permissions { ids = append(ids, id) } return ids case role.EdgeUserRoles: ids := make([]ent.Value, 0, len(m.removeduser_roles)) for id := range m.removeduser_roles { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RoleMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedrole_permissions { edges = append(edges, role.EdgeRolePermissions) } if m.cleareduser_roles { edges = append(edges, role.EdgeUserRoles) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *RoleMutation) EdgeCleared(name string) bool { switch name { case role.EdgeRolePermissions: return m.clearedrole_permissions case role.EdgeUserRoles: return m.cleareduser_roles } 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 *RoleMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Role 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 *RoleMutation) ResetEdge(name string) error { switch name { case role.EdgeRolePermissions: m.ResetRolePermissions() return nil case role.EdgeUserRoles: m.ResetUserRoles() return nil } return fmt.Errorf("unknown Role edge %s", name) } // RolePermissionMutation represents an operation that mutates the RolePermission nodes in the graph. type RolePermissionMutation struct { config op Op typ string id *int clearedFields map[string]struct{} role *string clearedrole bool permission *string clearedpermission bool done bool oldValue func(context.Context) (*RolePermission, error) predicates []predicate.RolePermission } var _ ent.Mutation = (*RolePermissionMutation)(nil) // rolepermissionOption allows management of the mutation configuration using functional options. type rolepermissionOption func(*RolePermissionMutation) // newRolePermissionMutation creates new mutation for the RolePermission entity. func newRolePermissionMutation(c config, op Op, opts ...rolepermissionOption) *RolePermissionMutation { m := &RolePermissionMutation{ config: c, op: op, typ: TypeRolePermission, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withRolePermissionID sets the ID field of the mutation. func withRolePermissionID(id int) rolepermissionOption { return func(m *RolePermissionMutation) { var ( err error once sync.Once value *RolePermission ) m.oldValue = func(ctx context.Context) (*RolePermission, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().RolePermission.Get(ctx, id) } }) return value, err } m.id = &id } } // withRolePermission sets the old RolePermission of the mutation. func withRolePermission(node *RolePermission) rolepermissionOption { return func(m *RolePermissionMutation) { m.oldValue = func(context.Context) (*RolePermission, 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 RolePermissionMutation) 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 RolePermissionMutation) 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 *RolePermissionMutation) 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 *RolePermissionMutation) 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().RolePermission.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetRoleID sets the "role_id" field. func (m *RolePermissionMutation) SetRoleID(s string) { m.role = &s } // RoleID returns the value of the "role_id" field in the mutation. func (m *RolePermissionMutation) RoleID() (r string, exists bool) { v := m.role if v == nil { return } return *v, true } // OldRoleID returns the old "role_id" field's value of the RolePermission entity. // If the RolePermission 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 *RolePermissionMutation) OldRoleID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRoleID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRoleID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRoleID: %w", err) } return oldValue.RoleID, nil } // ResetRoleID resets all changes to the "role_id" field. func (m *RolePermissionMutation) ResetRoleID() { m.role = nil } // SetPermissionID sets the "permission_id" field. func (m *RolePermissionMutation) SetPermissionID(s string) { m.permission = &s } // PermissionID returns the value of the "permission_id" field in the mutation. func (m *RolePermissionMutation) PermissionID() (r string, exists bool) { v := m.permission if v == nil { return } return *v, true } // OldPermissionID returns the old "permission_id" field's value of the RolePermission entity. // If the RolePermission 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 *RolePermissionMutation) OldPermissionID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPermissionID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPermissionID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPermissionID: %w", err) } return oldValue.PermissionID, nil } // ResetPermissionID resets all changes to the "permission_id" field. func (m *RolePermissionMutation) ResetPermissionID() { m.permission = nil } // ClearRole clears the "role" edge to the Role entity. func (m *RolePermissionMutation) ClearRole() { m.clearedrole = true m.clearedFields[rolepermission.FieldRoleID] = struct{}{} } // RoleCleared reports if the "role" edge to the Role entity was cleared. func (m *RolePermissionMutation) RoleCleared() bool { return m.clearedrole } // RoleIDs returns the "role" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // RoleID instead. It exists only for internal usage by the builders. func (m *RolePermissionMutation) RoleIDs() (ids []string) { if id := m.role; id != nil { ids = append(ids, *id) } return } // ResetRole resets all changes to the "role" edge. func (m *RolePermissionMutation) ResetRole() { m.role = nil m.clearedrole = false } // ClearPermission clears the "permission" edge to the Permission entity. func (m *RolePermissionMutation) ClearPermission() { m.clearedpermission = true m.clearedFields[rolepermission.FieldPermissionID] = struct{}{} } // PermissionCleared reports if the "permission" edge to the Permission entity was cleared. func (m *RolePermissionMutation) PermissionCleared() bool { return m.clearedpermission } // PermissionIDs returns the "permission" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // PermissionID instead. It exists only for internal usage by the builders. func (m *RolePermissionMutation) PermissionIDs() (ids []string) { if id := m.permission; id != nil { ids = append(ids, *id) } return } // ResetPermission resets all changes to the "permission" edge. func (m *RolePermissionMutation) ResetPermission() { m.permission = nil m.clearedpermission = false } // Where appends a list predicates to the RolePermissionMutation builder. func (m *RolePermissionMutation) Where(ps ...predicate.RolePermission) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the RolePermissionMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *RolePermissionMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.RolePermission, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *RolePermissionMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *RolePermissionMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (RolePermission). func (m *RolePermissionMutation) 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 *RolePermissionMutation) Fields() []string { fields := make([]string, 0, 2) if m.role != nil { fields = append(fields, rolepermission.FieldRoleID) } if m.permission != nil { fields = append(fields, rolepermission.FieldPermissionID) } 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 *RolePermissionMutation) Field(name string) (ent.Value, bool) { switch name { case rolepermission.FieldRoleID: return m.RoleID() case rolepermission.FieldPermissionID: return m.PermissionID() } 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 *RolePermissionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case rolepermission.FieldRoleID: return m.OldRoleID(ctx) case rolepermission.FieldPermissionID: return m.OldPermissionID(ctx) } return nil, fmt.Errorf("unknown RolePermission 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 *RolePermissionMutation) SetField(name string, value ent.Value) error { switch name { case rolepermission.FieldRoleID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRoleID(v) return nil case rolepermission.FieldPermissionID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPermissionID(v) return nil } return fmt.Errorf("unknown RolePermission field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *RolePermissionMutation) 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 *RolePermissionMutation) 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 *RolePermissionMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown RolePermission numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *RolePermissionMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *RolePermissionMutation) 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 *RolePermissionMutation) ClearField(name string) error { return fmt.Errorf("unknown RolePermission 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 *RolePermissionMutation) ResetField(name string) error { switch name { case rolepermission.FieldRoleID: m.ResetRoleID() return nil case rolepermission.FieldPermissionID: m.ResetPermissionID() return nil } return fmt.Errorf("unknown RolePermission field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *RolePermissionMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.role != nil { edges = append(edges, rolepermission.EdgeRole) } if m.permission != nil { edges = append(edges, rolepermission.EdgePermission) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *RolePermissionMutation) AddedIDs(name string) []ent.Value { switch name { case rolepermission.EdgeRole: if id := m.role; id != nil { return []ent.Value{*id} } case rolepermission.EdgePermission: if id := m.permission; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *RolePermissionMutation) RemovedEdges() []string { edges := make([]string, 0, 2) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *RolePermissionMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RolePermissionMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedrole { edges = append(edges, rolepermission.EdgeRole) } if m.clearedpermission { edges = append(edges, rolepermission.EdgePermission) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *RolePermissionMutation) EdgeCleared(name string) bool { switch name { case rolepermission.EdgeRole: return m.clearedrole case rolepermission.EdgePermission: return m.clearedpermission } 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 *RolePermissionMutation) ClearEdge(name string) error { switch name { case rolepermission.EdgeRole: m.ClearRole() return nil case rolepermission.EdgePermission: m.ClearPermission() return nil } return fmt.Errorf("unknown RolePermission 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 *RolePermissionMutation) ResetEdge(name string) error { switch name { case rolepermission.EdgeRole: m.ResetRole() return nil case rolepermission.EdgePermission: m.ResetPermission() return nil } return fmt.Errorf("unknown RolePermission edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config op Op typ string id *string email *string username *string first_name *string last_name *string password_hash *string verified *bool email_verification_token *string password_reset_token *string password_reset_expires_at *time.Time created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} user_roles map[int]struct{} removeduser_roles map[int]struct{} cleareduser_roles 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 string) 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 } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of User entities. func (m *UserMutation) SetID(id string) { m.id = &id } // 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 string, 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) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().User.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetEmail sets the "email" field. func (m *UserMutation) SetEmail(s string) { m.email = &s } // Email returns the value of the "email" field in the mutation. func (m *UserMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old "email" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmail: %w", err) } return oldValue.Email, nil } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil } // 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 } // ClearUsername clears the value of the "username" field. func (m *UserMutation) ClearUsername() { m.username = nil m.clearedFields[user.FieldUsername] = struct{}{} } // UsernameCleared returns if the "username" field was cleared in this mutation. func (m *UserMutation) UsernameCleared() bool { _, ok := m.clearedFields[user.FieldUsername] return ok } // ResetUsername resets all changes to the "username" field. func (m *UserMutation) ResetUsername() { m.username = nil delete(m.clearedFields, user.FieldUsername) } // SetFirstName sets the "first_name" field. func (m *UserMutation) SetFirstName(s string) { m.first_name = &s } // FirstName returns the value of the "first_name" field in the mutation. func (m *UserMutation) FirstName() (r string, exists bool) { v := m.first_name if v == nil { return } return *v, true } // OldFirstName returns the old "first_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) OldFirstName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldFirstName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldFirstName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldFirstName: %w", err) } return oldValue.FirstName, nil } // ClearFirstName clears the value of the "first_name" field. func (m *UserMutation) ClearFirstName() { m.first_name = nil m.clearedFields[user.FieldFirstName] = struct{}{} } // FirstNameCleared returns if the "first_name" field was cleared in this mutation. func (m *UserMutation) FirstNameCleared() bool { _, ok := m.clearedFields[user.FieldFirstName] return ok } // ResetFirstName resets all changes to the "first_name" field. func (m *UserMutation) ResetFirstName() { m.first_name = nil delete(m.clearedFields, user.FieldFirstName) } // SetLastName sets the "last_name" field. func (m *UserMutation) SetLastName(s string) { m.last_name = &s } // LastName returns the value of the "last_name" field in the mutation. func (m *UserMutation) LastName() (r string, exists bool) { v := m.last_name if v == nil { return } return *v, true } // OldLastName returns the old "last_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) OldLastName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLastName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLastName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLastName: %w", err) } return oldValue.LastName, nil } // ClearLastName clears the value of the "last_name" field. func (m *UserMutation) ClearLastName() { m.last_name = nil m.clearedFields[user.FieldLastName] = struct{}{} } // LastNameCleared returns if the "last_name" field was cleared in this mutation. func (m *UserMutation) LastNameCleared() bool { _, ok := m.clearedFields[user.FieldLastName] return ok } // ResetLastName resets all changes to the "last_name" field. func (m *UserMutation) ResetLastName() { m.last_name = nil delete(m.clearedFields, user.FieldLastName) } // SetPasswordHash sets the "password_hash" field. func (m *UserMutation) SetPasswordHash(s string) { m.password_hash = &s } // PasswordHash returns the value of the "password_hash" field in the mutation. func (m *UserMutation) PasswordHash() (r string, exists bool) { v := m.password_hash if v == nil { return } return *v, true } // OldPasswordHash returns the old "password_hash" 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) OldPasswordHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPasswordHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPasswordHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPasswordHash: %w", err) } return oldValue.PasswordHash, nil } // ResetPasswordHash resets all changes to the "password_hash" field. func (m *UserMutation) ResetPasswordHash() { m.password_hash = nil } // SetVerified sets the "verified" field. func (m *UserMutation) SetVerified(b bool) { m.verified = &b } // Verified returns the value of the "verified" field in the mutation. func (m *UserMutation) Verified() (r bool, exists bool) { v := m.verified if v == nil { return } return *v, true } // OldVerified returns the old "verified" 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) OldVerified(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVerified is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVerified requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVerified: %w", err) } return oldValue.Verified, nil } // ResetVerified resets all changes to the "verified" field. func (m *UserMutation) ResetVerified() { m.verified = nil } // SetEmailVerificationToken sets the "email_verification_token" field. func (m *UserMutation) SetEmailVerificationToken(s string) { m.email_verification_token = &s } // EmailVerificationToken returns the value of the "email_verification_token" field in the mutation. func (m *UserMutation) EmailVerificationToken() (r string, exists bool) { v := m.email_verification_token if v == nil { return } return *v, true } // OldEmailVerificationToken returns the old "email_verification_token" 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) OldEmailVerificationToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmailVerificationToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmailVerificationToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmailVerificationToken: %w", err) } return oldValue.EmailVerificationToken, nil } // ClearEmailVerificationToken clears the value of the "email_verification_token" field. func (m *UserMutation) ClearEmailVerificationToken() { m.email_verification_token = nil m.clearedFields[user.FieldEmailVerificationToken] = struct{}{} } // EmailVerificationTokenCleared returns if the "email_verification_token" field was cleared in this mutation. func (m *UserMutation) EmailVerificationTokenCleared() bool { _, ok := m.clearedFields[user.FieldEmailVerificationToken] return ok } // ResetEmailVerificationToken resets all changes to the "email_verification_token" field. func (m *UserMutation) ResetEmailVerificationToken() { m.email_verification_token = nil delete(m.clearedFields, user.FieldEmailVerificationToken) } // SetPasswordResetToken sets the "password_reset_token" field. func (m *UserMutation) SetPasswordResetToken(s string) { m.password_reset_token = &s } // PasswordResetToken returns the value of the "password_reset_token" field in the mutation. func (m *UserMutation) PasswordResetToken() (r string, exists bool) { v := m.password_reset_token if v == nil { return } return *v, true } // OldPasswordResetToken returns the old "password_reset_token" 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) OldPasswordResetToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPasswordResetToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPasswordResetToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPasswordResetToken: %w", err) } return oldValue.PasswordResetToken, nil } // ClearPasswordResetToken clears the value of the "password_reset_token" field. func (m *UserMutation) ClearPasswordResetToken() { m.password_reset_token = nil m.clearedFields[user.FieldPasswordResetToken] = struct{}{} } // PasswordResetTokenCleared returns if the "password_reset_token" field was cleared in this mutation. func (m *UserMutation) PasswordResetTokenCleared() bool { _, ok := m.clearedFields[user.FieldPasswordResetToken] return ok } // ResetPasswordResetToken resets all changes to the "password_reset_token" field. func (m *UserMutation) ResetPasswordResetToken() { m.password_reset_token = nil delete(m.clearedFields, user.FieldPasswordResetToken) } // SetPasswordResetExpiresAt sets the "password_reset_expires_at" field. func (m *UserMutation) SetPasswordResetExpiresAt(t time.Time) { m.password_reset_expires_at = &t } // PasswordResetExpiresAt returns the value of the "password_reset_expires_at" field in the mutation. func (m *UserMutation) PasswordResetExpiresAt() (r time.Time, exists bool) { v := m.password_reset_expires_at if v == nil { return } return *v, true } // OldPasswordResetExpiresAt returns the old "password_reset_expires_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) OldPasswordResetExpiresAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPasswordResetExpiresAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPasswordResetExpiresAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPasswordResetExpiresAt: %w", err) } return oldValue.PasswordResetExpiresAt, nil } // ClearPasswordResetExpiresAt clears the value of the "password_reset_expires_at" field. func (m *UserMutation) ClearPasswordResetExpiresAt() { m.password_reset_expires_at = nil m.clearedFields[user.FieldPasswordResetExpiresAt] = struct{}{} } // PasswordResetExpiresAtCleared returns if the "password_reset_expires_at" field was cleared in this mutation. func (m *UserMutation) PasswordResetExpiresAtCleared() bool { _, ok := m.clearedFields[user.FieldPasswordResetExpiresAt] return ok } // ResetPasswordResetExpiresAt resets all changes to the "password_reset_expires_at" field. func (m *UserMutation) ResetPasswordResetExpiresAt() { m.password_reset_expires_at = nil delete(m.clearedFields, user.FieldPasswordResetExpiresAt) } // 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 } // ResetCreatedAt resets all changes to the "created_at" field. func (m *UserMutation) ResetCreatedAt() { m.created_at = nil } // 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *UserMutation) ResetUpdatedAt() { m.updated_at = nil } // AddUserRoleIDs adds the "user_roles" edge to the UserRole entity by ids. func (m *UserMutation) AddUserRoleIDs(ids ...int) { if m.user_roles == nil { m.user_roles = make(map[int]struct{}) } for i := range ids { m.user_roles[ids[i]] = struct{}{} } } // ClearUserRoles clears the "user_roles" edge to the UserRole entity. func (m *UserMutation) ClearUserRoles() { m.cleareduser_roles = true } // UserRolesCleared reports if the "user_roles" edge to the UserRole entity was cleared. func (m *UserMutation) UserRolesCleared() bool { return m.cleareduser_roles } // RemoveUserRoleIDs removes the "user_roles" edge to the UserRole entity by IDs. func (m *UserMutation) RemoveUserRoleIDs(ids ...int) { if m.removeduser_roles == nil { m.removeduser_roles = make(map[int]struct{}) } for i := range ids { delete(m.user_roles, ids[i]) m.removeduser_roles[ids[i]] = struct{}{} } } // RemovedUserRoles returns the removed IDs of the "user_roles" edge to the UserRole entity. func (m *UserMutation) RemovedUserRolesIDs() (ids []int) { for id := range m.removeduser_roles { ids = append(ids, id) } return } // UserRolesIDs returns the "user_roles" edge IDs in the mutation. func (m *UserMutation) UserRolesIDs() (ids []int) { for id := range m.user_roles { ids = append(ids, id) } return } // ResetUserRoles resets all changes to the "user_roles" edge. func (m *UserMutation) ResetUserRoles() { m.user_roles = nil m.cleareduser_roles = false m.removeduser_roles = 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, 11) if m.email != nil { fields = append(fields, user.FieldEmail) } if m.username != nil { fields = append(fields, user.FieldUsername) } if m.first_name != nil { fields = append(fields, user.FieldFirstName) } if m.last_name != nil { fields = append(fields, user.FieldLastName) } if m.password_hash != nil { fields = append(fields, user.FieldPasswordHash) } if m.verified != nil { fields = append(fields, user.FieldVerified) } if m.email_verification_token != nil { fields = append(fields, user.FieldEmailVerificationToken) } if m.password_reset_token != nil { fields = append(fields, user.FieldPasswordResetToken) } if m.password_reset_expires_at != nil { fields = append(fields, user.FieldPasswordResetExpiresAt) } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldEmail: return m.Email() case user.FieldUsername: return m.Username() case user.FieldFirstName: return m.FirstName() case user.FieldLastName: return m.LastName() case user.FieldPasswordHash: return m.PasswordHash() case user.FieldVerified: return m.Verified() case user.FieldEmailVerificationToken: return m.EmailVerificationToken() case user.FieldPasswordResetToken: return m.PasswordResetToken() case user.FieldPasswordResetExpiresAt: return m.PasswordResetExpiresAt() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case user.FieldEmail: return m.OldEmail(ctx) case user.FieldUsername: return m.OldUsername(ctx) case user.FieldFirstName: return m.OldFirstName(ctx) case user.FieldLastName: return m.OldLastName(ctx) case user.FieldPasswordHash: return m.OldPasswordHash(ctx) case user.FieldVerified: return m.OldVerified(ctx) case user.FieldEmailVerificationToken: return m.OldEmailVerificationToken(ctx) case user.FieldPasswordResetToken: return m.OldPasswordResetToken(ctx) case user.FieldPasswordResetExpiresAt: return m.OldPasswordResetExpiresAt(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown User field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *UserMutation) SetField(name string, value ent.Value) error { switch name { case user.FieldEmail: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmail(v) return nil case user.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.FieldFirstName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetFirstName(v) return nil case user.FieldLastName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLastName(v) return nil case user.FieldPasswordHash: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPasswordHash(v) return nil case user.FieldVerified: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVerified(v) return nil case user.FieldEmailVerificationToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmailVerificationToken(v) return nil case user.FieldPasswordResetToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPasswordResetToken(v) return nil case user.FieldPasswordResetExpiresAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPasswordResetExpiresAt(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 } 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.FieldUsername) { fields = append(fields, user.FieldUsername) } if m.FieldCleared(user.FieldFirstName) { fields = append(fields, user.FieldFirstName) } if m.FieldCleared(user.FieldLastName) { fields = append(fields, user.FieldLastName) } if m.FieldCleared(user.FieldEmailVerificationToken) { fields = append(fields, user.FieldEmailVerificationToken) } if m.FieldCleared(user.FieldPasswordResetToken) { fields = append(fields, user.FieldPasswordResetToken) } if m.FieldCleared(user.FieldPasswordResetExpiresAt) { fields = append(fields, user.FieldPasswordResetExpiresAt) } 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.FieldUsername: m.ClearUsername() return nil case user.FieldFirstName: m.ClearFirstName() return nil case user.FieldLastName: m.ClearLastName() return nil case user.FieldEmailVerificationToken: m.ClearEmailVerificationToken() return nil case user.FieldPasswordResetToken: m.ClearPasswordResetToken() return nil case user.FieldPasswordResetExpiresAt: m.ClearPasswordResetExpiresAt() 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.FieldEmail: m.ResetEmail() return nil case user.FieldUsername: m.ResetUsername() return nil case user.FieldFirstName: m.ResetFirstName() return nil case user.FieldLastName: m.ResetLastName() return nil case user.FieldPasswordHash: m.ResetPasswordHash() return nil case user.FieldVerified: m.ResetVerified() return nil case user.FieldEmailVerificationToken: m.ResetEmailVerificationToken() return nil case user.FieldPasswordResetToken: m.ResetPasswordResetToken() return nil case user.FieldPasswordResetExpiresAt: m.ResetPasswordResetExpiresAt() return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() 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.user_roles != nil { edges = append(edges, user.EdgeUserRoles) } 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.EdgeUserRoles: ids := make([]ent.Value, 0, len(m.user_roles)) for id := range m.user_roles { 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.removeduser_roles != nil { edges = append(edges, user.EdgeUserRoles) } 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.EdgeUserRoles: ids := make([]ent.Value, 0, len(m.removeduser_roles)) for id := range m.removeduser_roles { 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.cleareduser_roles { edges = append(edges, user.EdgeUserRoles) } 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.EdgeUserRoles: return m.cleareduser_roles } 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.EdgeUserRoles: m.ResetUserRoles() return nil } return fmt.Errorf("unknown User edge %s", name) } // UserRoleMutation represents an operation that mutates the UserRole nodes in the graph. type UserRoleMutation struct { config op Op typ string id *int clearedFields map[string]struct{} user *string cleareduser bool role *string clearedrole bool done bool oldValue func(context.Context) (*UserRole, error) predicates []predicate.UserRole } var _ ent.Mutation = (*UserRoleMutation)(nil) // userroleOption allows management of the mutation configuration using functional options. type userroleOption func(*UserRoleMutation) // newUserRoleMutation creates new mutation for the UserRole entity. func newUserRoleMutation(c config, op Op, opts ...userroleOption) *UserRoleMutation { m := &UserRoleMutation{ config: c, op: op, typ: TypeUserRole, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserRoleID sets the ID field of the mutation. func withUserRoleID(id int) userroleOption { return func(m *UserRoleMutation) { var ( err error once sync.Once value *UserRole ) m.oldValue = func(ctx context.Context) (*UserRole, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().UserRole.Get(ctx, id) } }) return value, err } m.id = &id } } // withUserRole sets the old UserRole of the mutation. func withUserRole(node *UserRole) userroleOption { return func(m *UserRoleMutation) { m.oldValue = func(context.Context) (*UserRole, 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 UserRoleMutation) 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 UserRoleMutation) 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 *UserRoleMutation) 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 *UserRoleMutation) 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().UserRole.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUserID sets the "user_id" field. func (m *UserRoleMutation) SetUserID(s string) { m.user = &s } // UserID returns the value of the "user_id" field in the mutation. func (m *UserRoleMutation) UserID() (r string, exists bool) { v := m.user if v == nil { return } return *v, true } // OldUserID returns the old "user_id" field's value of the UserRole entity. // If the UserRole 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 *UserRoleMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserID: %w", err) } return oldValue.UserID, nil } // ResetUserID resets all changes to the "user_id" field. func (m *UserRoleMutation) ResetUserID() { m.user = nil } // SetRoleID sets the "role_id" field. func (m *UserRoleMutation) SetRoleID(s string) { m.role = &s } // RoleID returns the value of the "role_id" field in the mutation. func (m *UserRoleMutation) RoleID() (r string, exists bool) { v := m.role if v == nil { return } return *v, true } // OldRoleID returns the old "role_id" field's value of the UserRole entity. // If the UserRole 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 *UserRoleMutation) OldRoleID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRoleID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldRoleID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldRoleID: %w", err) } return oldValue.RoleID, nil } // ResetRoleID resets all changes to the "role_id" field. func (m *UserRoleMutation) ResetRoleID() { m.role = nil } // ClearUser clears the "user" edge to the User entity. func (m *UserRoleMutation) ClearUser() { m.cleareduser = true m.clearedFields[userrole.FieldUserID] = struct{}{} } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *UserRoleMutation) UserCleared() bool { return m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *UserRoleMutation) UserIDs() (ids []string) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *UserRoleMutation) ResetUser() { m.user = nil m.cleareduser = false } // ClearRole clears the "role" edge to the Role entity. func (m *UserRoleMutation) ClearRole() { m.clearedrole = true m.clearedFields[userrole.FieldRoleID] = struct{}{} } // RoleCleared reports if the "role" edge to the Role entity was cleared. func (m *UserRoleMutation) RoleCleared() bool { return m.clearedrole } // RoleIDs returns the "role" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // RoleID instead. It exists only for internal usage by the builders. func (m *UserRoleMutation) RoleIDs() (ids []string) { if id := m.role; id != nil { ids = append(ids, *id) } return } // ResetRole resets all changes to the "role" edge. func (m *UserRoleMutation) ResetRole() { m.role = nil m.clearedrole = false } // Where appends a list predicates to the UserRoleMutation builder. func (m *UserRoleMutation) Where(ps ...predicate.UserRole) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserRoleMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserRoleMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.UserRole, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserRoleMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserRoleMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (UserRole). func (m *UserRoleMutation) 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 *UserRoleMutation) Fields() []string { fields := make([]string, 0, 2) if m.user != nil { fields = append(fields, userrole.FieldUserID) } if m.role != nil { fields = append(fields, userrole.FieldRoleID) } 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 *UserRoleMutation) Field(name string) (ent.Value, bool) { switch name { case userrole.FieldUserID: return m.UserID() case userrole.FieldRoleID: return m.RoleID() } 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 *UserRoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case userrole.FieldUserID: return m.OldUserID(ctx) case userrole.FieldRoleID: return m.OldRoleID(ctx) } return nil, fmt.Errorf("unknown UserRole 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 *UserRoleMutation) SetField(name string, value ent.Value) error { switch name { case userrole.FieldUserID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil case userrole.FieldRoleID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRoleID(v) return nil } return fmt.Errorf("unknown UserRole field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserRoleMutation) 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 *UserRoleMutation) 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 *UserRoleMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown UserRole numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserRoleMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserRoleMutation) 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 *UserRoleMutation) ClearField(name string) error { return fmt.Errorf("unknown UserRole 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 *UserRoleMutation) ResetField(name string) error { switch name { case userrole.FieldUserID: m.ResetUserID() return nil case userrole.FieldRoleID: m.ResetRoleID() return nil } return fmt.Errorf("unknown UserRole field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserRoleMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.user != nil { edges = append(edges, userrole.EdgeUser) } if m.role != nil { edges = append(edges, userrole.EdgeRole) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserRoleMutation) AddedIDs(name string) []ent.Value { switch name { case userrole.EdgeUser: if id := m.user; id != nil { return []ent.Value{*id} } case userrole.EdgeRole: if id := m.role; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserRoleMutation) RemovedEdges() []string { edges := make([]string, 0, 2) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *UserRoleMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserRoleMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.cleareduser { edges = append(edges, userrole.EdgeUser) } if m.clearedrole { edges = append(edges, userrole.EdgeRole) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserRoleMutation) EdgeCleared(name string) bool { switch name { case userrole.EdgeUser: return m.cleareduser case userrole.EdgeRole: return m.clearedrole } 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 *UserRoleMutation) ClearEdge(name string) error { switch name { case userrole.EdgeUser: m.ClearUser() return nil case userrole.EdgeRole: m.ClearRole() return nil } return fmt.Errorf("unknown UserRole 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 *UserRoleMutation) ResetEdge(name string) error { switch name { case userrole.EdgeUser: m.ResetUser() return nil case userrole.EdgeRole: m.ResetRole() return nil } return fmt.Errorf("unknown UserRole edge %s", name) }