Files
juwan-backend/app/users/rpc/internal/models/mutation.go
T
2026-03-31 22:12:06 +08:00

2324 lines
71 KiB
Go

// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/users/rpc/internal/models/predicate"
"juwan-backend/app/users/rpc/internal/models/schema"
"juwan-backend/app/users/rpc/internal/models/userfollows"
"juwan-backend/app/users/rpc/internal/models/userpreferences"
"juwan-backend/app/users/rpc/internal/models/users"
"juwan-backend/pkg/types"
"sync"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeUserFollows = "UserFollows"
TypeUserPreferences = "UserPreferences"
TypeUsers = "Users"
)
// UserFollowsMutation represents an operation that mutates the UserFollows nodes in the graph.
type UserFollowsMutation struct {
config
op Op
typ string
id *int64
follower_id *int64
addfollower_id *int64
followee_id *int64
addfollowee_id *int64
created_at *time.Time
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*UserFollows, error)
predicates []predicate.UserFollows
}
var _ ent.Mutation = (*UserFollowsMutation)(nil)
// userfollowsOption allows management of the mutation configuration using functional options.
type userfollowsOption func(*UserFollowsMutation)
// newUserFollowsMutation creates new mutation for the UserFollows entity.
func newUserFollowsMutation(c config, op Op, opts ...userfollowsOption) *UserFollowsMutation {
m := &UserFollowsMutation{
config: c,
op: op,
typ: TypeUserFollows,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserFollowsID sets the ID field of the mutation.
func withUserFollowsID(id int64) userfollowsOption {
return func(m *UserFollowsMutation) {
var (
err error
once sync.Once
value *UserFollows
)
m.oldValue = func(ctx context.Context) (*UserFollows, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserFollows.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserFollows sets the old UserFollows of the mutation.
func withUserFollows(node *UserFollows) userfollowsOption {
return func(m *UserFollowsMutation) {
m.oldValue = func(context.Context) (*UserFollows, 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 UserFollowsMutation) 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 UserFollowsMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("models: 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 UserFollows entities.
func (m *UserFollowsMutation) SetID(id int64) {
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 *UserFollowsMutation) ID() (id int64, 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 *UserFollowsMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().UserFollows.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetFollowerID sets the "follower_id" field.
func (m *UserFollowsMutation) SetFollowerID(i int64) {
m.follower_id = &i
m.addfollower_id = nil
}
// FollowerID returns the value of the "follower_id" field in the mutation.
func (m *UserFollowsMutation) FollowerID() (r int64, exists bool) {
v := m.follower_id
if v == nil {
return
}
return *v, true
}
// OldFollowerID returns the old "follower_id" field's value of the UserFollows entity.
// If the UserFollows 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 *UserFollowsMutation) OldFollowerID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFollowerID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFollowerID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFollowerID: %w", err)
}
return oldValue.FollowerID, nil
}
// AddFollowerID adds i to the "follower_id" field.
func (m *UserFollowsMutation) AddFollowerID(i int64) {
if m.addfollower_id != nil {
*m.addfollower_id += i
} else {
m.addfollower_id = &i
}
}
// AddedFollowerID returns the value that was added to the "follower_id" field in this mutation.
func (m *UserFollowsMutation) AddedFollowerID() (r int64, exists bool) {
v := m.addfollower_id
if v == nil {
return
}
return *v, true
}
// ResetFollowerID resets all changes to the "follower_id" field.
func (m *UserFollowsMutation) ResetFollowerID() {
m.follower_id = nil
m.addfollower_id = nil
}
// SetFolloweeID sets the "followee_id" field.
func (m *UserFollowsMutation) SetFolloweeID(i int64) {
m.followee_id = &i
m.addfollowee_id = nil
}
// FolloweeID returns the value of the "followee_id" field in the mutation.
func (m *UserFollowsMutation) FolloweeID() (r int64, exists bool) {
v := m.followee_id
if v == nil {
return
}
return *v, true
}
// OldFolloweeID returns the old "followee_id" field's value of the UserFollows entity.
// If the UserFollows 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 *UserFollowsMutation) OldFolloweeID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFolloweeID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFolloweeID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFolloweeID: %w", err)
}
return oldValue.FolloweeID, nil
}
// AddFolloweeID adds i to the "followee_id" field.
func (m *UserFollowsMutation) AddFolloweeID(i int64) {
if m.addfollowee_id != nil {
*m.addfollowee_id += i
} else {
m.addfollowee_id = &i
}
}
// AddedFolloweeID returns the value that was added to the "followee_id" field in this mutation.
func (m *UserFollowsMutation) AddedFolloweeID() (r int64, exists bool) {
v := m.addfollowee_id
if v == nil {
return
}
return *v, true
}
// ResetFolloweeID resets all changes to the "followee_id" field.
func (m *UserFollowsMutation) ResetFolloweeID() {
m.followee_id = nil
m.addfollowee_id = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *UserFollowsMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserFollowsMutation) 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 UserFollows entity.
// If the UserFollows 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 *UserFollowsMutation) 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 *UserFollowsMutation) ResetCreatedAt() {
m.created_at = nil
}
// Where appends a list predicates to the UserFollowsMutation builder.
func (m *UserFollowsMutation) Where(ps ...predicate.UserFollows) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserFollowsMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserFollowsMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UserFollows, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserFollowsMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserFollowsMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UserFollows).
func (m *UserFollowsMutation) 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 *UserFollowsMutation) Fields() []string {
fields := make([]string, 0, 3)
if m.follower_id != nil {
fields = append(fields, userfollows.FieldFollowerID)
}
if m.followee_id != nil {
fields = append(fields, userfollows.FieldFolloweeID)
}
if m.created_at != nil {
fields = append(fields, userfollows.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 *UserFollowsMutation) Field(name string) (ent.Value, bool) {
switch name {
case userfollows.FieldFollowerID:
return m.FollowerID()
case userfollows.FieldFolloweeID:
return m.FolloweeID()
case userfollows.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 *UserFollowsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case userfollows.FieldFollowerID:
return m.OldFollowerID(ctx)
case userfollows.FieldFolloweeID:
return m.OldFolloweeID(ctx)
case userfollows.FieldCreatedAt:
return m.OldCreatedAt(ctx)
}
return nil, fmt.Errorf("unknown UserFollows 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 *UserFollowsMutation) SetField(name string, value ent.Value) error {
switch name {
case userfollows.FieldFollowerID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFollowerID(v)
return nil
case userfollows.FieldFolloweeID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFolloweeID(v)
return nil
case userfollows.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 UserFollows field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserFollowsMutation) AddedFields() []string {
var fields []string
if m.addfollower_id != nil {
fields = append(fields, userfollows.FieldFollowerID)
}
if m.addfollowee_id != nil {
fields = append(fields, userfollows.FieldFolloweeID)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserFollowsMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case userfollows.FieldFollowerID:
return m.AddedFollowerID()
case userfollows.FieldFolloweeID:
return m.AddedFolloweeID()
}
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 *UserFollowsMutation) AddField(name string, value ent.Value) error {
switch name {
case userfollows.FieldFollowerID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddFollowerID(v)
return nil
case userfollows.FieldFolloweeID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddFolloweeID(v)
return nil
}
return fmt.Errorf("unknown UserFollows numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserFollowsMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserFollowsMutation) 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 *UserFollowsMutation) ClearField(name string) error {
return fmt.Errorf("unknown UserFollows 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 *UserFollowsMutation) ResetField(name string) error {
switch name {
case userfollows.FieldFollowerID:
m.ResetFollowerID()
return nil
case userfollows.FieldFolloweeID:
m.ResetFolloweeID()
return nil
case userfollows.FieldCreatedAt:
m.ResetCreatedAt()
return nil
}
return fmt.Errorf("unknown UserFollows field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserFollowsMutation) 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 *UserFollowsMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserFollowsMutation) 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 *UserFollowsMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserFollowsMutation) 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 *UserFollowsMutation) 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 *UserFollowsMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown UserFollows 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 *UserFollowsMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown UserFollows edge %s", name)
}
// UserPreferencesMutation represents an operation that mutates the UserPreferences nodes in the graph.
type UserPreferencesMutation struct {
config
op Op
typ string
id *int
user_id *int64
adduser_id *int64
notification_order *bool
notification_community *bool
notification_system *bool
theme *string
language *string
updated_at *time.Time
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*UserPreferences, error)
predicates []predicate.UserPreferences
}
var _ ent.Mutation = (*UserPreferencesMutation)(nil)
// userpreferencesOption allows management of the mutation configuration using functional options.
type userpreferencesOption func(*UserPreferencesMutation)
// newUserPreferencesMutation creates new mutation for the UserPreferences entity.
func newUserPreferencesMutation(c config, op Op, opts ...userpreferencesOption) *UserPreferencesMutation {
m := &UserPreferencesMutation{
config: c,
op: op,
typ: TypeUserPreferences,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserPreferencesID sets the ID field of the mutation.
func withUserPreferencesID(id int) userpreferencesOption {
return func(m *UserPreferencesMutation) {
var (
err error
once sync.Once
value *UserPreferences
)
m.oldValue = func(ctx context.Context) (*UserPreferences, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserPreferences.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserPreferences sets the old UserPreferences of the mutation.
func withUserPreferences(node *UserPreferences) userpreferencesOption {
return func(m *UserPreferencesMutation) {
m.oldValue = func(context.Context) (*UserPreferences, 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 UserPreferencesMutation) 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 UserPreferencesMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("models: 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 *UserPreferencesMutation) 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 *UserPreferencesMutation) 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().UserPreferences.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 *UserPreferencesMutation) SetUserID(i int64) {
m.user_id = &i
m.adduser_id = nil
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *UserPreferencesMutation) UserID() (r int64, exists bool) {
v := m.user_id
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) OldUserID(ctx context.Context) (v int64, 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
}
// AddUserID adds i to the "user_id" field.
func (m *UserPreferencesMutation) AddUserID(i int64) {
if m.adduser_id != nil {
*m.adduser_id += i
} else {
m.adduser_id = &i
}
}
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
func (m *UserPreferencesMutation) AddedUserID() (r int64, exists bool) {
v := m.adduser_id
if v == nil {
return
}
return *v, true
}
// ResetUserID resets all changes to the "user_id" field.
func (m *UserPreferencesMutation) ResetUserID() {
m.user_id = nil
m.adduser_id = nil
}
// SetNotificationOrder sets the "notification_order" field.
func (m *UserPreferencesMutation) SetNotificationOrder(b bool) {
m.notification_order = &b
}
// NotificationOrder returns the value of the "notification_order" field in the mutation.
func (m *UserPreferencesMutation) NotificationOrder() (r bool, exists bool) {
v := m.notification_order
if v == nil {
return
}
return *v, true
}
// OldNotificationOrder returns the old "notification_order" field's value of the UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) OldNotificationOrder(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotificationOrder is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotificationOrder requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotificationOrder: %w", err)
}
return oldValue.NotificationOrder, nil
}
// ResetNotificationOrder resets all changes to the "notification_order" field.
func (m *UserPreferencesMutation) ResetNotificationOrder() {
m.notification_order = nil
}
// SetNotificationCommunity sets the "notification_community" field.
func (m *UserPreferencesMutation) SetNotificationCommunity(b bool) {
m.notification_community = &b
}
// NotificationCommunity returns the value of the "notification_community" field in the mutation.
func (m *UserPreferencesMutation) NotificationCommunity() (r bool, exists bool) {
v := m.notification_community
if v == nil {
return
}
return *v, true
}
// OldNotificationCommunity returns the old "notification_community" field's value of the UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) OldNotificationCommunity(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotificationCommunity is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotificationCommunity requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotificationCommunity: %w", err)
}
return oldValue.NotificationCommunity, nil
}
// ResetNotificationCommunity resets all changes to the "notification_community" field.
func (m *UserPreferencesMutation) ResetNotificationCommunity() {
m.notification_community = nil
}
// SetNotificationSystem sets the "notification_system" field.
func (m *UserPreferencesMutation) SetNotificationSystem(b bool) {
m.notification_system = &b
}
// NotificationSystem returns the value of the "notification_system" field in the mutation.
func (m *UserPreferencesMutation) NotificationSystem() (r bool, exists bool) {
v := m.notification_system
if v == nil {
return
}
return *v, true
}
// OldNotificationSystem returns the old "notification_system" field's value of the UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) OldNotificationSystem(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotificationSystem is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotificationSystem requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotificationSystem: %w", err)
}
return oldValue.NotificationSystem, nil
}
// ResetNotificationSystem resets all changes to the "notification_system" field.
func (m *UserPreferencesMutation) ResetNotificationSystem() {
m.notification_system = nil
}
// SetTheme sets the "theme" field.
func (m *UserPreferencesMutation) SetTheme(s string) {
m.theme = &s
}
// Theme returns the value of the "theme" field in the mutation.
func (m *UserPreferencesMutation) Theme() (r string, exists bool) {
v := m.theme
if v == nil {
return
}
return *v, true
}
// OldTheme returns the old "theme" field's value of the UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) OldTheme(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTheme is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTheme requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTheme: %w", err)
}
return oldValue.Theme, nil
}
// ResetTheme resets all changes to the "theme" field.
func (m *UserPreferencesMutation) ResetTheme() {
m.theme = nil
}
// SetLanguage sets the "language" field.
func (m *UserPreferencesMutation) SetLanguage(s string) {
m.language = &s
}
// Language returns the value of the "language" field in the mutation.
func (m *UserPreferencesMutation) Language() (r string, exists bool) {
v := m.language
if v == nil {
return
}
return *v, true
}
// OldLanguage returns the old "language" field's value of the UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) OldLanguage(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLanguage is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLanguage requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLanguage: %w", err)
}
return oldValue.Language, nil
}
// ResetLanguage resets all changes to the "language" field.
func (m *UserPreferencesMutation) ResetLanguage() {
m.language = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *UserPreferencesMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UserPreferencesMutation) 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 UserPreferences entity.
// If the UserPreferences 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 *UserPreferencesMutation) 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 *UserPreferencesMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// Where appends a list predicates to the UserPreferencesMutation builder.
func (m *UserPreferencesMutation) Where(ps ...predicate.UserPreferences) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserPreferencesMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserPreferencesMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UserPreferences, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserPreferencesMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserPreferencesMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UserPreferences).
func (m *UserPreferencesMutation) 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 *UserPreferencesMutation) Fields() []string {
fields := make([]string, 0, 7)
if m.user_id != nil {
fields = append(fields, userpreferences.FieldUserID)
}
if m.notification_order != nil {
fields = append(fields, userpreferences.FieldNotificationOrder)
}
if m.notification_community != nil {
fields = append(fields, userpreferences.FieldNotificationCommunity)
}
if m.notification_system != nil {
fields = append(fields, userpreferences.FieldNotificationSystem)
}
if m.theme != nil {
fields = append(fields, userpreferences.FieldTheme)
}
if m.language != nil {
fields = append(fields, userpreferences.FieldLanguage)
}
if m.updated_at != nil {
fields = append(fields, userpreferences.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 *UserPreferencesMutation) Field(name string) (ent.Value, bool) {
switch name {
case userpreferences.FieldUserID:
return m.UserID()
case userpreferences.FieldNotificationOrder:
return m.NotificationOrder()
case userpreferences.FieldNotificationCommunity:
return m.NotificationCommunity()
case userpreferences.FieldNotificationSystem:
return m.NotificationSystem()
case userpreferences.FieldTheme:
return m.Theme()
case userpreferences.FieldLanguage:
return m.Language()
case userpreferences.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 *UserPreferencesMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case userpreferences.FieldUserID:
return m.OldUserID(ctx)
case userpreferences.FieldNotificationOrder:
return m.OldNotificationOrder(ctx)
case userpreferences.FieldNotificationCommunity:
return m.OldNotificationCommunity(ctx)
case userpreferences.FieldNotificationSystem:
return m.OldNotificationSystem(ctx)
case userpreferences.FieldTheme:
return m.OldTheme(ctx)
case userpreferences.FieldLanguage:
return m.OldLanguage(ctx)
case userpreferences.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
}
return nil, fmt.Errorf("unknown UserPreferences 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 *UserPreferencesMutation) SetField(name string, value ent.Value) error {
switch name {
case userpreferences.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case userpreferences.FieldNotificationOrder:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNotificationOrder(v)
return nil
case userpreferences.FieldNotificationCommunity:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNotificationCommunity(v)
return nil
case userpreferences.FieldNotificationSystem:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNotificationSystem(v)
return nil
case userpreferences.FieldTheme:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTheme(v)
return nil
case userpreferences.FieldLanguage:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLanguage(v)
return nil
case userpreferences.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 UserPreferences field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserPreferencesMutation) AddedFields() []string {
var fields []string
if m.adduser_id != nil {
fields = append(fields, userpreferences.FieldUserID)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserPreferencesMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case userpreferences.FieldUserID:
return m.AddedUserID()
}
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 *UserPreferencesMutation) AddField(name string, value ent.Value) error {
switch name {
case userpreferences.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUserID(v)
return nil
}
return fmt.Errorf("unknown UserPreferences numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserPreferencesMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserPreferencesMutation) 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 *UserPreferencesMutation) ClearField(name string) error {
return fmt.Errorf("unknown UserPreferences 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 *UserPreferencesMutation) ResetField(name string) error {
switch name {
case userpreferences.FieldUserID:
m.ResetUserID()
return nil
case userpreferences.FieldNotificationOrder:
m.ResetNotificationOrder()
return nil
case userpreferences.FieldNotificationCommunity:
m.ResetNotificationCommunity()
return nil
case userpreferences.FieldNotificationSystem:
m.ResetNotificationSystem()
return nil
case userpreferences.FieldTheme:
m.ResetTheme()
return nil
case userpreferences.FieldLanguage:
m.ResetLanguage()
return nil
case userpreferences.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
}
return fmt.Errorf("unknown UserPreferences field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserPreferencesMutation) 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 *UserPreferencesMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserPreferencesMutation) 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 *UserPreferencesMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserPreferencesMutation) 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 *UserPreferencesMutation) 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 *UserPreferencesMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown UserPreferences 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 *UserPreferencesMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown UserPreferences edge %s", name)
}
// UsersMutation represents an operation that mutates the Users nodes in the graph.
type UsersMutation struct {
config
op Op
typ string
id *int64
username *string
password_hash *string
email *string
phone *string
nickname *string
avatar *string
bio *string
current_role *string
verificationStatus *schema.VerificationStatusStruct
is_admin *bool
created_at *time.Time
updated_at *time.Time
deleted_at *time.Time
verified_roles *types.TextArray
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Users, error)
predicates []predicate.Users
}
var _ ent.Mutation = (*UsersMutation)(nil)
// usersOption allows management of the mutation configuration using functional options.
type usersOption func(*UsersMutation)
// newUsersMutation creates new mutation for the Users entity.
func newUsersMutation(c config, op Op, opts ...usersOption) *UsersMutation {
m := &UsersMutation{
config: c,
op: op,
typ: TypeUsers,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUsersID sets the ID field of the mutation.
func withUsersID(id int64) usersOption {
return func(m *UsersMutation) {
var (
err error
once sync.Once
value *Users
)
m.oldValue = func(ctx context.Context) (*Users, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Users.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUsers sets the old Users of the mutation.
func withUsers(node *Users) usersOption {
return func(m *UsersMutation) {
m.oldValue = func(context.Context) (*Users, 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 UsersMutation) 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 UsersMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("models: 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 Users entities.
func (m *UsersMutation) SetID(id int64) {
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 *UsersMutation) ID() (id int64, 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 *UsersMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Users.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUsername sets the "username" field.
func (m *UsersMutation) SetUsername(s string) {
m.username = &s
}
// Username returns the value of the "username" field in the mutation.
func (m *UsersMutation) Username() (r string, exists bool) {
v := m.username
if v == nil {
return
}
return *v, true
}
// OldUsername returns the old "username" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldUsername(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsername is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsername requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsername: %w", err)
}
return oldValue.Username, nil
}
// ResetUsername resets all changes to the "username" field.
func (m *UsersMutation) ResetUsername() {
m.username = nil
}
// SetPasswordHash sets the "password_hash" field.
func (m *UsersMutation) SetPasswordHash(s string) {
m.password_hash = &s
}
// PasswordHash returns the value of the "password_hash" field in the mutation.
func (m *UsersMutation) 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 Users entity.
// If the Users 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 *UsersMutation) 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 *UsersMutation) ResetPasswordHash() {
m.password_hash = nil
}
// SetEmail sets the "email" field.
func (m *UsersMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *UsersMutation) 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 Users entity.
// If the Users 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 *UsersMutation) 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 *UsersMutation) ResetEmail() {
m.email = nil
}
// SetPhone sets the "phone" field.
func (m *UsersMutation) SetPhone(s string) {
m.phone = &s
}
// Phone returns the value of the "phone" field in the mutation.
func (m *UsersMutation) Phone() (r string, exists bool) {
v := m.phone
if v == nil {
return
}
return *v, true
}
// OldPhone returns the old "phone" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldPhone(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPhone is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPhone requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPhone: %w", err)
}
return oldValue.Phone, nil
}
// ResetPhone resets all changes to the "phone" field.
func (m *UsersMutation) ResetPhone() {
m.phone = nil
}
// SetNickname sets the "nickname" field.
func (m *UsersMutation) SetNickname(s string) {
m.nickname = &s
}
// Nickname returns the value of the "nickname" field in the mutation.
func (m *UsersMutation) Nickname() (r string, exists bool) {
v := m.nickname
if v == nil {
return
}
return *v, true
}
// OldNickname returns the old "nickname" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldNickname(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNickname is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNickname requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNickname: %w", err)
}
return oldValue.Nickname, nil
}
// ResetNickname resets all changes to the "nickname" field.
func (m *UsersMutation) ResetNickname() {
m.nickname = nil
}
// SetAvatar sets the "avatar" field.
func (m *UsersMutation) SetAvatar(s string) {
m.avatar = &s
}
// Avatar returns the value of the "avatar" field in the mutation.
func (m *UsersMutation) Avatar() (r string, exists bool) {
v := m.avatar
if v == nil {
return
}
return *v, true
}
// OldAvatar returns the old "avatar" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldAvatar(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAvatar is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAvatar requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAvatar: %w", err)
}
return oldValue.Avatar, nil
}
// ResetAvatar resets all changes to the "avatar" field.
func (m *UsersMutation) ResetAvatar() {
m.avatar = nil
}
// SetBio sets the "bio" field.
func (m *UsersMutation) SetBio(s string) {
m.bio = &s
}
// Bio returns the value of the "bio" field in the mutation.
func (m *UsersMutation) Bio() (r string, exists bool) {
v := m.bio
if v == nil {
return
}
return *v, true
}
// OldBio returns the old "bio" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldBio(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBio is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBio requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBio: %w", err)
}
return oldValue.Bio, nil
}
// ResetBio resets all changes to the "bio" field.
func (m *UsersMutation) ResetBio() {
m.bio = nil
}
// SetCurrentRole sets the "current_role" field.
func (m *UsersMutation) SetCurrentRole(s string) {
m.current_role = &s
}
// CurrentRole returns the value of the "current_role" field in the mutation.
func (m *UsersMutation) CurrentRole() (r string, exists bool) {
v := m.current_role
if v == nil {
return
}
return *v, true
}
// OldCurrentRole returns the old "current_role" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldCurrentRole(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCurrentRole is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCurrentRole requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCurrentRole: %w", err)
}
return oldValue.CurrentRole, nil
}
// ResetCurrentRole resets all changes to the "current_role" field.
func (m *UsersMutation) ResetCurrentRole() {
m.current_role = nil
}
// SetVerificationStatus sets the "verificationStatus" field.
func (m *UsersMutation) SetVerificationStatus(sss schema.VerificationStatusStruct) {
m.verificationStatus = &sss
}
// VerificationStatus returns the value of the "verificationStatus" field in the mutation.
func (m *UsersMutation) VerificationStatus() (r schema.VerificationStatusStruct, exists bool) {
v := m.verificationStatus
if v == nil {
return
}
return *v, true
}
// OldVerificationStatus returns the old "verificationStatus" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldVerificationStatus(ctx context.Context) (v schema.VerificationStatusStruct, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldVerificationStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldVerificationStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldVerificationStatus: %w", err)
}
return oldValue.VerificationStatus, nil
}
// ClearVerificationStatus clears the value of the "verificationStatus" field.
func (m *UsersMutation) ClearVerificationStatus() {
m.verificationStatus = nil
m.clearedFields[users.FieldVerificationStatus] = struct{}{}
}
// VerificationStatusCleared returns if the "verificationStatus" field was cleared in this mutation.
func (m *UsersMutation) VerificationStatusCleared() bool {
_, ok := m.clearedFields[users.FieldVerificationStatus]
return ok
}
// ResetVerificationStatus resets all changes to the "verificationStatus" field.
func (m *UsersMutation) ResetVerificationStatus() {
m.verificationStatus = nil
delete(m.clearedFields, users.FieldVerificationStatus)
}
// SetIsAdmin sets the "is_admin" field.
func (m *UsersMutation) SetIsAdmin(b bool) {
m.is_admin = &b
}
// IsAdmin returns the value of the "is_admin" field in the mutation.
func (m *UsersMutation) IsAdmin() (r bool, exists bool) {
v := m.is_admin
if v == nil {
return
}
return *v, true
}
// OldIsAdmin returns the old "is_admin" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldIsAdmin(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsAdmin is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsAdmin requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsAdmin: %w", err)
}
return oldValue.IsAdmin, nil
}
// ResetIsAdmin resets all changes to the "is_admin" field.
func (m *UsersMutation) ResetIsAdmin() {
m.is_admin = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *UsersMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UsersMutation) 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 Users entity.
// If the Users 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 *UsersMutation) 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 *UsersMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *UsersMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UsersMutation) 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 Users entity.
// If the Users 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 *UsersMutation) 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 *UsersMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *UsersMutation) SetDeletedAt(t time.Time) {
m.deleted_at = &t
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *UsersMutation) DeletedAt() (r time.Time, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *UsersMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[users.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *UsersMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[users.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *UsersMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, users.FieldDeletedAt)
}
// SetVerifiedRoles sets the "verified_roles" field.
func (m *UsersMutation) SetVerifiedRoles(ta types.TextArray) {
m.verified_roles = &ta
}
// VerifiedRoles returns the value of the "verified_roles" field in the mutation.
func (m *UsersMutation) VerifiedRoles() (r types.TextArray, exists bool) {
v := m.verified_roles
if v == nil {
return
}
return *v, true
}
// OldVerifiedRoles returns the old "verified_roles" field's value of the Users entity.
// If the Users 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 *UsersMutation) OldVerifiedRoles(ctx context.Context) (v types.TextArray, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldVerifiedRoles is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldVerifiedRoles requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldVerifiedRoles: %w", err)
}
return oldValue.VerifiedRoles, nil
}
// ClearVerifiedRoles clears the value of the "verified_roles" field.
func (m *UsersMutation) ClearVerifiedRoles() {
m.verified_roles = nil
m.clearedFields[users.FieldVerifiedRoles] = struct{}{}
}
// VerifiedRolesCleared returns if the "verified_roles" field was cleared in this mutation.
func (m *UsersMutation) VerifiedRolesCleared() bool {
_, ok := m.clearedFields[users.FieldVerifiedRoles]
return ok
}
// ResetVerifiedRoles resets all changes to the "verified_roles" field.
func (m *UsersMutation) ResetVerifiedRoles() {
m.verified_roles = nil
delete(m.clearedFields, users.FieldVerifiedRoles)
}
// Where appends a list predicates to the UsersMutation builder.
func (m *UsersMutation) Where(ps ...predicate.Users) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UsersMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UsersMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Users, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UsersMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UsersMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Users).
func (m *UsersMutation) 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 *UsersMutation) Fields() []string {
fields := make([]string, 0, 14)
if m.username != nil {
fields = append(fields, users.FieldUsername)
}
if m.password_hash != nil {
fields = append(fields, users.FieldPasswordHash)
}
if m.email != nil {
fields = append(fields, users.FieldEmail)
}
if m.phone != nil {
fields = append(fields, users.FieldPhone)
}
if m.nickname != nil {
fields = append(fields, users.FieldNickname)
}
if m.avatar != nil {
fields = append(fields, users.FieldAvatar)
}
if m.bio != nil {
fields = append(fields, users.FieldBio)
}
if m.current_role != nil {
fields = append(fields, users.FieldCurrentRole)
}
if m.verificationStatus != nil {
fields = append(fields, users.FieldVerificationStatus)
}
if m.is_admin != nil {
fields = append(fields, users.FieldIsAdmin)
}
if m.created_at != nil {
fields = append(fields, users.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, users.FieldUpdatedAt)
}
if m.deleted_at != nil {
fields = append(fields, users.FieldDeletedAt)
}
if m.verified_roles != nil {
fields = append(fields, users.FieldVerifiedRoles)
}
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 *UsersMutation) Field(name string) (ent.Value, bool) {
switch name {
case users.FieldUsername:
return m.Username()
case users.FieldPasswordHash:
return m.PasswordHash()
case users.FieldEmail:
return m.Email()
case users.FieldPhone:
return m.Phone()
case users.FieldNickname:
return m.Nickname()
case users.FieldAvatar:
return m.Avatar()
case users.FieldBio:
return m.Bio()
case users.FieldCurrentRole:
return m.CurrentRole()
case users.FieldVerificationStatus:
return m.VerificationStatus()
case users.FieldIsAdmin:
return m.IsAdmin()
case users.FieldCreatedAt:
return m.CreatedAt()
case users.FieldUpdatedAt:
return m.UpdatedAt()
case users.FieldDeletedAt:
return m.DeletedAt()
case users.FieldVerifiedRoles:
return m.VerifiedRoles()
}
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 *UsersMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case users.FieldUsername:
return m.OldUsername(ctx)
case users.FieldPasswordHash:
return m.OldPasswordHash(ctx)
case users.FieldEmail:
return m.OldEmail(ctx)
case users.FieldPhone:
return m.OldPhone(ctx)
case users.FieldNickname:
return m.OldNickname(ctx)
case users.FieldAvatar:
return m.OldAvatar(ctx)
case users.FieldBio:
return m.OldBio(ctx)
case users.FieldCurrentRole:
return m.OldCurrentRole(ctx)
case users.FieldVerificationStatus:
return m.OldVerificationStatus(ctx)
case users.FieldIsAdmin:
return m.OldIsAdmin(ctx)
case users.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case users.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case users.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case users.FieldVerifiedRoles:
return m.OldVerifiedRoles(ctx)
}
return nil, fmt.Errorf("unknown Users 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 *UsersMutation) SetField(name string, value ent.Value) error {
switch name {
case users.FieldUsername:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsername(v)
return nil
case users.FieldPasswordHash:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPasswordHash(v)
return nil
case users.FieldEmail:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEmail(v)
return nil
case users.FieldPhone:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPhone(v)
return nil
case users.FieldNickname:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNickname(v)
return nil
case users.FieldAvatar:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAvatar(v)
return nil
case users.FieldBio:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBio(v)
return nil
case users.FieldCurrentRole:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCurrentRole(v)
return nil
case users.FieldVerificationStatus:
v, ok := value.(schema.VerificationStatusStruct)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetVerificationStatus(v)
return nil
case users.FieldIsAdmin:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsAdmin(v)
return nil
case users.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 users.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case users.FieldDeletedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case users.FieldVerifiedRoles:
v, ok := value.(types.TextArray)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetVerifiedRoles(v)
return nil
}
return fmt.Errorf("unknown Users field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UsersMutation) 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 *UsersMutation) 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 *UsersMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Users numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UsersMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(users.FieldVerificationStatus) {
fields = append(fields, users.FieldVerificationStatus)
}
if m.FieldCleared(users.FieldDeletedAt) {
fields = append(fields, users.FieldDeletedAt)
}
if m.FieldCleared(users.FieldVerifiedRoles) {
fields = append(fields, users.FieldVerifiedRoles)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UsersMutation) 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 *UsersMutation) ClearField(name string) error {
switch name {
case users.FieldVerificationStatus:
m.ClearVerificationStatus()
return nil
case users.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case users.FieldVerifiedRoles:
m.ClearVerifiedRoles()
return nil
}
return fmt.Errorf("unknown Users 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 *UsersMutation) ResetField(name string) error {
switch name {
case users.FieldUsername:
m.ResetUsername()
return nil
case users.FieldPasswordHash:
m.ResetPasswordHash()
return nil
case users.FieldEmail:
m.ResetEmail()
return nil
case users.FieldPhone:
m.ResetPhone()
return nil
case users.FieldNickname:
m.ResetNickname()
return nil
case users.FieldAvatar:
m.ResetAvatar()
return nil
case users.FieldBio:
m.ResetBio()
return nil
case users.FieldCurrentRole:
m.ResetCurrentRole()
return nil
case users.FieldVerificationStatus:
m.ResetVerificationStatus()
return nil
case users.FieldIsAdmin:
m.ResetIsAdmin()
return nil
case users.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case users.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case users.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case users.FieldVerifiedRoles:
m.ResetVerifiedRoles()
return nil
}
return fmt.Errorf("unknown Users field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UsersMutation) 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 *UsersMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UsersMutation) 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 *UsersMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UsersMutation) 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 *UsersMutation) 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 *UsersMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Users 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 *UsersMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Users edge %s", name)
}