Files
goplt/internal/ent/mutation.go
0x1d 30320304f6 feat(epic1): implement core infrastructure (stories 1.1-1.5)
Implemented Epic 1 core kernel and infrastructure stories:

Story 1.1: Enhanced DI Container
- Added providers for database, health, metrics, and error bus
- Extended CoreModule to include all core services

Story 1.2: Database Layer with Ent ORM
- Created Ent schema for User, Role, Permission, AuditLog entities
- Implemented many-to-many relationships (User-Role, Role-Permission)
- Created database client wrapper with connection pooling
- Added database provider to DI container with migration support

Story 1.3: Health Monitoring and Metrics System
- Implemented health check registry and interface
- Added database health checker
- Created Prometheus metrics system with HTTP instrumentation
- Added health and metrics providers to DI container

Story 1.4: Error Handling and Error Bus
- Implemented channel-based error bus
- Created ErrorPublisher interface
- Added error bus provider with lifecycle management

Story 1.5: HTTP Server Foundation
- Created HTTP server with Gin framework
- Implemented comprehensive middleware stack:
  - Request ID generation
  - Structured logging
  - Panic recovery with error bus integration
  - Prometheus metrics collection
  - CORS support
- Registered core routes: /healthz, /ready, /metrics
- Integrated with FX lifecycle for graceful shutdown

All components are integrated via DI container and ready for use.
2025-11-05 18:11:11 +01:00

3292 lines
97 KiB
Go

// 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/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"
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
actor_id *string
action *string
target_id *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)
}
}
// SetActorID sets the "actor_id" field.
func (m *AuditLogMutation) SetActorID(s string) {
m.actor_id = &s
}
// ActorID returns the value of the "actor_id" field in the mutation.
func (m *AuditLogMutation) ActorID() (r string, exists bool) {
v := m.actor_id
if v == nil {
return
}
return *v, true
}
// OldActorID returns the old "actor_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) OldActorID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActorID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActorID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActorID: %w", err)
}
return oldValue.ActorID, nil
}
// ResetActorID resets all changes to the "actor_id" field.
func (m *AuditLogMutation) ResetActorID() {
m.actor_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
}
// SetTargetID sets the "target_id" field.
func (m *AuditLogMutation) SetTargetID(s string) {
m.target_id = &s
}
// TargetID returns the value of the "target_id" field in the mutation.
func (m *AuditLogMutation) TargetID() (r string, exists bool) {
v := m.target_id
if v == nil {
return
}
return *v, true
}
// OldTargetID returns the old "target_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) OldTargetID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTargetID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTargetID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTargetID: %w", err)
}
return oldValue.TargetID, nil
}
// ClearTargetID clears the value of the "target_id" field.
func (m *AuditLogMutation) ClearTargetID() {
m.target_id = nil
m.clearedFields[auditlog.FieldTargetID] = struct{}{}
}
// TargetIDCleared returns if the "target_id" field was cleared in this mutation.
func (m *AuditLogMutation) TargetIDCleared() bool {
_, ok := m.clearedFields[auditlog.FieldTargetID]
return ok
}
// ResetTargetID resets all changes to the "target_id" field.
func (m *AuditLogMutation) ResetTargetID() {
m.target_id = nil
delete(m.clearedFields, auditlog.FieldTargetID)
}
// 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, 5)
if m.actor_id != nil {
fields = append(fields, auditlog.FieldActorID)
}
if m.action != nil {
fields = append(fields, auditlog.FieldAction)
}
if m.target_id != nil {
fields = append(fields, auditlog.FieldTargetID)
}
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.FieldActorID:
return m.ActorID()
case auditlog.FieldAction:
return m.Action()
case auditlog.FieldTargetID:
return m.TargetID()
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.FieldActorID:
return m.OldActorID(ctx)
case auditlog.FieldAction:
return m.OldAction(ctx)
case auditlog.FieldTargetID:
return m.OldTargetID(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.FieldActorID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActorID(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.FieldTargetID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTargetID(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.FieldTargetID) {
fields = append(fields, auditlog.FieldTargetID)
}
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.FieldTargetID:
m.ClearTargetID()
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.FieldActorID:
m.ResetActorID()
return nil
case auditlog.FieldAction:
m.ResetAction()
return nil
case auditlog.FieldTargetID:
m.ResetTargetID()
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)
}
// 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
password_hash *string
verified *bool
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
}
// 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
}
// 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, 5)
if m.email != nil {
fields = append(fields, user.FieldEmail)
}
if m.password_hash != nil {
fields = append(fields, user.FieldPasswordHash)
}
if m.verified != nil {
fields = append(fields, user.FieldVerified)
}
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.FieldPasswordHash:
return m.PasswordHash()
case user.FieldVerified:
return m.Verified()
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.FieldPasswordHash:
return m.OldPasswordHash(ctx)
case user.FieldVerified:
return m.OldVerified(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.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.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 {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
return fmt.Errorf("unknown User nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error {
switch name {
case user.FieldEmail:
m.ResetEmail()
return nil
case user.FieldPasswordHash:
m.ResetPasswordHash()
return nil
case user.FieldVerified:
m.ResetVerified()
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)
}