TinySkin/db/ent/mutation.go
2023-09-08 22:05:22 +08:00

3106 lines
89 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/xmdhs/authlib-skin/db/ent/predicate"
"github.com/xmdhs/authlib-skin/db/ent/texture"
"github.com/xmdhs/authlib-skin/db/ent/user"
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
"github.com/xmdhs/authlib-skin/db/ent/usertexture"
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeTexture = "Texture"
TypeUser = "User"
TypeUserProfile = "UserProfile"
TypeUserTexture = "UserTexture"
TypeUserToken = "UserToken"
)
// TextureMutation represents an operation that mutates the Texture nodes in the graph.
type TextureMutation struct {
config
op Op
typ string
id *int
texture_hash *string
clearedFields map[string]struct{}
created_user *int
clearedcreated_user bool
user_profile map[int]struct{}
removeduser_profile map[int]struct{}
cleareduser_profile bool
usertexture map[int]struct{}
removedusertexture map[int]struct{}
clearedusertexture bool
done bool
oldValue func(context.Context) (*Texture, error)
predicates []predicate.Texture
}
var _ ent.Mutation = (*TextureMutation)(nil)
// textureOption allows management of the mutation configuration using functional options.
type textureOption func(*TextureMutation)
// newTextureMutation creates new mutation for the Texture entity.
func newTextureMutation(c config, op Op, opts ...textureOption) *TextureMutation {
m := &TextureMutation{
config: c,
op: op,
typ: TypeTexture,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withTextureID sets the ID field of the mutation.
func withTextureID(id int) textureOption {
return func(m *TextureMutation) {
var (
err error
once sync.Once
value *Texture
)
m.oldValue = func(ctx context.Context) (*Texture, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Texture.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withTexture sets the old Texture of the mutation.
func withTexture(node *Texture) textureOption {
return func(m *TextureMutation) {
m.oldValue = func(context.Context) (*Texture, 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 TextureMutation) 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 TextureMutation) 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 *TextureMutation) 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 *TextureMutation) 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().Texture.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetTextureHash sets the "texture_hash" field.
func (m *TextureMutation) SetTextureHash(s string) {
m.texture_hash = &s
}
// TextureHash returns the value of the "texture_hash" field in the mutation.
func (m *TextureMutation) TextureHash() (r string, exists bool) {
v := m.texture_hash
if v == nil {
return
}
return *v, true
}
// OldTextureHash returns the old "texture_hash" field's value of the Texture entity.
// If the Texture 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 *TextureMutation) OldTextureHash(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTextureHash is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTextureHash requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTextureHash: %w", err)
}
return oldValue.TextureHash, nil
}
// ResetTextureHash resets all changes to the "texture_hash" field.
func (m *TextureMutation) ResetTextureHash() {
m.texture_hash = nil
}
// SetCreatedUserID sets the "created_user" edge to the User entity by id.
func (m *TextureMutation) SetCreatedUserID(id int) {
m.created_user = &id
}
// ClearCreatedUser clears the "created_user" edge to the User entity.
func (m *TextureMutation) ClearCreatedUser() {
m.clearedcreated_user = true
}
// CreatedUserCleared reports if the "created_user" edge to the User entity was cleared.
func (m *TextureMutation) CreatedUserCleared() bool {
return m.clearedcreated_user
}
// CreatedUserID returns the "created_user" edge ID in the mutation.
func (m *TextureMutation) CreatedUserID() (id int, exists bool) {
if m.created_user != nil {
return *m.created_user, true
}
return
}
// CreatedUserIDs returns the "created_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CreatedUserID instead. It exists only for internal usage by the builders.
func (m *TextureMutation) CreatedUserIDs() (ids []int) {
if id := m.created_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCreatedUser resets all changes to the "created_user" edge.
func (m *TextureMutation) ResetCreatedUser() {
m.created_user = nil
m.clearedcreated_user = false
}
// AddUserProfileIDs adds the "user_profile" edge to the UserProfile entity by ids.
func (m *TextureMutation) AddUserProfileIDs(ids ...int) {
if m.user_profile == nil {
m.user_profile = make(map[int]struct{})
}
for i := range ids {
m.user_profile[ids[i]] = struct{}{}
}
}
// ClearUserProfile clears the "user_profile" edge to the UserProfile entity.
func (m *TextureMutation) ClearUserProfile() {
m.cleareduser_profile = true
}
// UserProfileCleared reports if the "user_profile" edge to the UserProfile entity was cleared.
func (m *TextureMutation) UserProfileCleared() bool {
return m.cleareduser_profile
}
// RemoveUserProfileIDs removes the "user_profile" edge to the UserProfile entity by IDs.
func (m *TextureMutation) RemoveUserProfileIDs(ids ...int) {
if m.removeduser_profile == nil {
m.removeduser_profile = make(map[int]struct{})
}
for i := range ids {
delete(m.user_profile, ids[i])
m.removeduser_profile[ids[i]] = struct{}{}
}
}
// RemovedUserProfile returns the removed IDs of the "user_profile" edge to the UserProfile entity.
func (m *TextureMutation) RemovedUserProfileIDs() (ids []int) {
for id := range m.removeduser_profile {
ids = append(ids, id)
}
return
}
// UserProfileIDs returns the "user_profile" edge IDs in the mutation.
func (m *TextureMutation) UserProfileIDs() (ids []int) {
for id := range m.user_profile {
ids = append(ids, id)
}
return
}
// ResetUserProfile resets all changes to the "user_profile" edge.
func (m *TextureMutation) ResetUserProfile() {
m.user_profile = nil
m.cleareduser_profile = false
m.removeduser_profile = nil
}
// AddUsertextureIDs adds the "usertexture" edge to the UserTexture entity by ids.
func (m *TextureMutation) AddUsertextureIDs(ids ...int) {
if m.usertexture == nil {
m.usertexture = make(map[int]struct{})
}
for i := range ids {
m.usertexture[ids[i]] = struct{}{}
}
}
// ClearUsertexture clears the "usertexture" edge to the UserTexture entity.
func (m *TextureMutation) ClearUsertexture() {
m.clearedusertexture = true
}
// UsertextureCleared reports if the "usertexture" edge to the UserTexture entity was cleared.
func (m *TextureMutation) UsertextureCleared() bool {
return m.clearedusertexture
}
// RemoveUsertextureIDs removes the "usertexture" edge to the UserTexture entity by IDs.
func (m *TextureMutation) RemoveUsertextureIDs(ids ...int) {
if m.removedusertexture == nil {
m.removedusertexture = make(map[int]struct{})
}
for i := range ids {
delete(m.usertexture, ids[i])
m.removedusertexture[ids[i]] = struct{}{}
}
}
// RemovedUsertexture returns the removed IDs of the "usertexture" edge to the UserTexture entity.
func (m *TextureMutation) RemovedUsertextureIDs() (ids []int) {
for id := range m.removedusertexture {
ids = append(ids, id)
}
return
}
// UsertextureIDs returns the "usertexture" edge IDs in the mutation.
func (m *TextureMutation) UsertextureIDs() (ids []int) {
for id := range m.usertexture {
ids = append(ids, id)
}
return
}
// ResetUsertexture resets all changes to the "usertexture" edge.
func (m *TextureMutation) ResetUsertexture() {
m.usertexture = nil
m.clearedusertexture = false
m.removedusertexture = nil
}
// Where appends a list predicates to the TextureMutation builder.
func (m *TextureMutation) Where(ps ...predicate.Texture) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the TextureMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *TextureMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Texture, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *TextureMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *TextureMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Texture).
func (m *TextureMutation) 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 *TextureMutation) Fields() []string {
fields := make([]string, 0, 1)
if m.texture_hash != nil {
fields = append(fields, texture.FieldTextureHash)
}
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 *TextureMutation) Field(name string) (ent.Value, bool) {
switch name {
case texture.FieldTextureHash:
return m.TextureHash()
}
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 *TextureMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case texture.FieldTextureHash:
return m.OldTextureHash(ctx)
}
return nil, fmt.Errorf("unknown Texture 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 *TextureMutation) SetField(name string, value ent.Value) error {
switch name {
case texture.FieldTextureHash:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTextureHash(v)
return nil
}
return fmt.Errorf("unknown Texture field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *TextureMutation) 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 *TextureMutation) 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 *TextureMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Texture numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *TextureMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *TextureMutation) 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 *TextureMutation) ClearField(name string) error {
return fmt.Errorf("unknown Texture 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 *TextureMutation) ResetField(name string) error {
switch name {
case texture.FieldTextureHash:
m.ResetTextureHash()
return nil
}
return fmt.Errorf("unknown Texture field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *TextureMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.created_user != nil {
edges = append(edges, texture.EdgeCreatedUser)
}
if m.user_profile != nil {
edges = append(edges, texture.EdgeUserProfile)
}
if m.usertexture != nil {
edges = append(edges, texture.EdgeUsertexture)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *TextureMutation) AddedIDs(name string) []ent.Value {
switch name {
case texture.EdgeCreatedUser:
if id := m.created_user; id != nil {
return []ent.Value{*id}
}
case texture.EdgeUserProfile:
ids := make([]ent.Value, 0, len(m.user_profile))
for id := range m.user_profile {
ids = append(ids, id)
}
return ids
case texture.EdgeUsertexture:
ids := make([]ent.Value, 0, len(m.usertexture))
for id := range m.usertexture {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *TextureMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
if m.removeduser_profile != nil {
edges = append(edges, texture.EdgeUserProfile)
}
if m.removedusertexture != nil {
edges = append(edges, texture.EdgeUsertexture)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *TextureMutation) RemovedIDs(name string) []ent.Value {
switch name {
case texture.EdgeUserProfile:
ids := make([]ent.Value, 0, len(m.removeduser_profile))
for id := range m.removeduser_profile {
ids = append(ids, id)
}
return ids
case texture.EdgeUsertexture:
ids := make([]ent.Value, 0, len(m.removedusertexture))
for id := range m.removedusertexture {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *TextureMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.clearedcreated_user {
edges = append(edges, texture.EdgeCreatedUser)
}
if m.cleareduser_profile {
edges = append(edges, texture.EdgeUserProfile)
}
if m.clearedusertexture {
edges = append(edges, texture.EdgeUsertexture)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *TextureMutation) EdgeCleared(name string) bool {
switch name {
case texture.EdgeCreatedUser:
return m.clearedcreated_user
case texture.EdgeUserProfile:
return m.cleareduser_profile
case texture.EdgeUsertexture:
return m.clearedusertexture
}
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 *TextureMutation) ClearEdge(name string) error {
switch name {
case texture.EdgeCreatedUser:
m.ClearCreatedUser()
return nil
}
return fmt.Errorf("unknown Texture 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 *TextureMutation) ResetEdge(name string) error {
switch name {
case texture.EdgeCreatedUser:
m.ResetCreatedUser()
return nil
case texture.EdgeUserProfile:
m.ResetUserProfile()
return nil
case texture.EdgeUsertexture:
m.ResetUsertexture()
return nil
}
return fmt.Errorf("unknown Texture edge %s", name)
}
// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
config
op Op
typ string
id *int
email *string
password *string
salt *string
reg_ip *string
state *int
addstate *int
reg_time *int64
addreg_time *int64
clearedFields map[string]struct{}
created_texture map[int]struct{}
removedcreated_texture map[int]struct{}
clearedcreated_texture bool
profile *int
clearedprofile bool
token *int
clearedtoken bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
}
var _ ent.Mutation = (*UserMutation)(nil)
// userOption allows management of the mutation configuration using functional options.
type userOption func(*UserMutation)
// newUserMutation creates new mutation for the User entity.
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
m := &UserMutation{
config: c,
op: op,
typ: TypeUser,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserID sets the ID field of the mutation.
func withUserID(id int) userOption {
return func(m *UserMutation) {
var (
err error
once sync.Once
value *User
)
m.oldValue = func(ctx context.Context) (*User, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().User.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
return func(m *UserMutation) {
m.oldValue = func(context.Context) (*User, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m UserMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m UserMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *UserMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetEmail sets the "email" field.
func (m *UserMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *UserMutation) Email() (r string, exists bool) {
v := m.email
if v == nil {
return
}
return *v, true
}
// OldEmail returns the old "email" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEmail is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEmail requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
}
return oldValue.Email, nil
}
// ResetEmail resets all changes to the "email" field.
func (m *UserMutation) ResetEmail() {
m.email = nil
}
// SetPassword sets the "password" field.
func (m *UserMutation) SetPassword(s string) {
m.password = &s
}
// Password returns the value of the "password" field in the mutation.
func (m *UserMutation) Password() (r string, exists bool) {
v := m.password
if v == nil {
return
}
return *v, true
}
// OldPassword returns the old "password" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPassword is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPassword requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPassword: %w", err)
}
return oldValue.Password, nil
}
// ResetPassword resets all changes to the "password" field.
func (m *UserMutation) ResetPassword() {
m.password = nil
}
// SetSalt sets the "salt" field.
func (m *UserMutation) SetSalt(s string) {
m.salt = &s
}
// Salt returns the value of the "salt" field in the mutation.
func (m *UserMutation) Salt() (r string, exists bool) {
v := m.salt
if v == nil {
return
}
return *v, true
}
// OldSalt returns the old "salt" 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) OldSalt(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSalt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSalt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSalt: %w", err)
}
return oldValue.Salt, nil
}
// ResetSalt resets all changes to the "salt" field.
func (m *UserMutation) ResetSalt() {
m.salt = nil
}
// SetRegIP sets the "reg_ip" field.
func (m *UserMutation) SetRegIP(s string) {
m.reg_ip = &s
}
// RegIP returns the value of the "reg_ip" field in the mutation.
func (m *UserMutation) RegIP() (r string, exists bool) {
v := m.reg_ip
if v == nil {
return
}
return *v, true
}
// OldRegIP returns the old "reg_ip" 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) OldRegIP(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRegIP is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRegIP requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRegIP: %w", err)
}
return oldValue.RegIP, nil
}
// ResetRegIP resets all changes to the "reg_ip" field.
func (m *UserMutation) ResetRegIP() {
m.reg_ip = nil
}
// SetState sets the "state" field.
func (m *UserMutation) SetState(i int) {
m.state = &i
m.addstate = nil
}
// State returns the value of the "state" field in the mutation.
func (m *UserMutation) State() (r int, exists bool) {
v := m.state
if v == nil {
return
}
return *v, true
}
// OldState returns the old "state" 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) OldState(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldState is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldState requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldState: %w", err)
}
return oldValue.State, nil
}
// AddState adds i to the "state" field.
func (m *UserMutation) AddState(i int) {
if m.addstate != nil {
*m.addstate += i
} else {
m.addstate = &i
}
}
// AddedState returns the value that was added to the "state" field in this mutation.
func (m *UserMutation) AddedState() (r int, exists bool) {
v := m.addstate
if v == nil {
return
}
return *v, true
}
// ResetState resets all changes to the "state" field.
func (m *UserMutation) ResetState() {
m.state = nil
m.addstate = nil
}
// SetRegTime sets the "reg_time" field.
func (m *UserMutation) SetRegTime(i int64) {
m.reg_time = &i
m.addreg_time = nil
}
// RegTime returns the value of the "reg_time" field in the mutation.
func (m *UserMutation) RegTime() (r int64, exists bool) {
v := m.reg_time
if v == nil {
return
}
return *v, true
}
// OldRegTime returns the old "reg_time" 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) OldRegTime(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRegTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRegTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRegTime: %w", err)
}
return oldValue.RegTime, nil
}
// AddRegTime adds i to the "reg_time" field.
func (m *UserMutation) AddRegTime(i int64) {
if m.addreg_time != nil {
*m.addreg_time += i
} else {
m.addreg_time = &i
}
}
// AddedRegTime returns the value that was added to the "reg_time" field in this mutation.
func (m *UserMutation) AddedRegTime() (r int64, exists bool) {
v := m.addreg_time
if v == nil {
return
}
return *v, true
}
// ResetRegTime resets all changes to the "reg_time" field.
func (m *UserMutation) ResetRegTime() {
m.reg_time = nil
m.addreg_time = nil
}
// AddCreatedTextureIDs adds the "created_texture" edge to the Texture entity by ids.
func (m *UserMutation) AddCreatedTextureIDs(ids ...int) {
if m.created_texture == nil {
m.created_texture = make(map[int]struct{})
}
for i := range ids {
m.created_texture[ids[i]] = struct{}{}
}
}
// ClearCreatedTexture clears the "created_texture" edge to the Texture entity.
func (m *UserMutation) ClearCreatedTexture() {
m.clearedcreated_texture = true
}
// CreatedTextureCleared reports if the "created_texture" edge to the Texture entity was cleared.
func (m *UserMutation) CreatedTextureCleared() bool {
return m.clearedcreated_texture
}
// RemoveCreatedTextureIDs removes the "created_texture" edge to the Texture entity by IDs.
func (m *UserMutation) RemoveCreatedTextureIDs(ids ...int) {
if m.removedcreated_texture == nil {
m.removedcreated_texture = make(map[int]struct{})
}
for i := range ids {
delete(m.created_texture, ids[i])
m.removedcreated_texture[ids[i]] = struct{}{}
}
}
// RemovedCreatedTexture returns the removed IDs of the "created_texture" edge to the Texture entity.
func (m *UserMutation) RemovedCreatedTextureIDs() (ids []int) {
for id := range m.removedcreated_texture {
ids = append(ids, id)
}
return
}
// CreatedTextureIDs returns the "created_texture" edge IDs in the mutation.
func (m *UserMutation) CreatedTextureIDs() (ids []int) {
for id := range m.created_texture {
ids = append(ids, id)
}
return
}
// ResetCreatedTexture resets all changes to the "created_texture" edge.
func (m *UserMutation) ResetCreatedTexture() {
m.created_texture = nil
m.clearedcreated_texture = false
m.removedcreated_texture = nil
}
// SetProfileID sets the "profile" edge to the UserProfile entity by id.
func (m *UserMutation) SetProfileID(id int) {
m.profile = &id
}
// ClearProfile clears the "profile" edge to the UserProfile entity.
func (m *UserMutation) ClearProfile() {
m.clearedprofile = true
}
// ProfileCleared reports if the "profile" edge to the UserProfile entity was cleared.
func (m *UserMutation) ProfileCleared() bool {
return m.clearedprofile
}
// ProfileID returns the "profile" edge ID in the mutation.
func (m *UserMutation) ProfileID() (id int, exists bool) {
if m.profile != nil {
return *m.profile, true
}
return
}
// ProfileIDs returns the "profile" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// ProfileID instead. It exists only for internal usage by the builders.
func (m *UserMutation) ProfileIDs() (ids []int) {
if id := m.profile; id != nil {
ids = append(ids, *id)
}
return
}
// ResetProfile resets all changes to the "profile" edge.
func (m *UserMutation) ResetProfile() {
m.profile = nil
m.clearedprofile = false
}
// SetTokenID sets the "token" edge to the UserToken entity by id.
func (m *UserMutation) SetTokenID(id int) {
m.token = &id
}
// ClearToken clears the "token" edge to the UserToken entity.
func (m *UserMutation) ClearToken() {
m.clearedtoken = true
}
// TokenCleared reports if the "token" edge to the UserToken entity was cleared.
func (m *UserMutation) TokenCleared() bool {
return m.clearedtoken
}
// TokenID returns the "token" edge ID in the mutation.
func (m *UserMutation) TokenID() (id int, exists bool) {
if m.token != nil {
return *m.token, true
}
return
}
// TokenIDs returns the "token" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// TokenID instead. It exists only for internal usage by the builders.
func (m *UserMutation) TokenIDs() (ids []int) {
if id := m.token; id != nil {
ids = append(ids, *id)
}
return
}
// ResetToken resets all changes to the "token" edge.
func (m *UserMutation) ResetToken() {
m.token = nil
m.clearedtoken = false
}
// 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, 6)
if m.email != nil {
fields = append(fields, user.FieldEmail)
}
if m.password != nil {
fields = append(fields, user.FieldPassword)
}
if m.salt != nil {
fields = append(fields, user.FieldSalt)
}
if m.reg_ip != nil {
fields = append(fields, user.FieldRegIP)
}
if m.state != nil {
fields = append(fields, user.FieldState)
}
if m.reg_time != nil {
fields = append(fields, user.FieldRegTime)
}
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.FieldPassword:
return m.Password()
case user.FieldSalt:
return m.Salt()
case user.FieldRegIP:
return m.RegIP()
case user.FieldState:
return m.State()
case user.FieldRegTime:
return m.RegTime()
}
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.FieldPassword:
return m.OldPassword(ctx)
case user.FieldSalt:
return m.OldSalt(ctx)
case user.FieldRegIP:
return m.OldRegIP(ctx)
case user.FieldState:
return m.OldState(ctx)
case user.FieldRegTime:
return m.OldRegTime(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.FieldPassword:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
case user.FieldSalt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSalt(v)
return nil
case user.FieldRegIP:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRegIP(v)
return nil
case user.FieldState:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetState(v)
return nil
case user.FieldRegTime:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRegTime(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 {
var fields []string
if m.addstate != nil {
fields = append(fields, user.FieldState)
}
if m.addreg_time != nil {
fields = append(fields, user.FieldRegTime)
}
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 *UserMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case user.FieldState:
return m.AddedState()
case user.FieldRegTime:
return m.AddedRegTime()
}
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 {
case user.FieldState:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddState(v)
return nil
case user.FieldRegTime:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRegTime(v)
return nil
}
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.FieldPassword:
m.ResetPassword()
return nil
case user.FieldSalt:
m.ResetSalt()
return nil
case user.FieldRegIP:
m.ResetRegIP()
return nil
case user.FieldState:
m.ResetState()
return nil
case user.FieldRegTime:
m.ResetRegTime()
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, 3)
if m.created_texture != nil {
edges = append(edges, user.EdgeCreatedTexture)
}
if m.profile != nil {
edges = append(edges, user.EdgeProfile)
}
if m.token != nil {
edges = append(edges, user.EdgeToken)
}
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.EdgeCreatedTexture:
ids := make([]ent.Value, 0, len(m.created_texture))
for id := range m.created_texture {
ids = append(ids, id)
}
return ids
case user.EdgeProfile:
if id := m.profile; id != nil {
return []ent.Value{*id}
}
case user.EdgeToken:
if id := m.token; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
if m.removedcreated_texture != nil {
edges = append(edges, user.EdgeCreatedTexture)
}
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.EdgeCreatedTexture:
ids := make([]ent.Value, 0, len(m.removedcreated_texture))
for id := range m.removedcreated_texture {
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, 3)
if m.clearedcreated_texture {
edges = append(edges, user.EdgeCreatedTexture)
}
if m.clearedprofile {
edges = append(edges, user.EdgeProfile)
}
if m.clearedtoken {
edges = append(edges, user.EdgeToken)
}
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.EdgeCreatedTexture:
return m.clearedcreated_texture
case user.EdgeProfile:
return m.clearedprofile
case user.EdgeToken:
return m.clearedtoken
}
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 {
case user.EdgeProfile:
m.ClearProfile()
return nil
case user.EdgeToken:
m.ClearToken()
return nil
}
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.EdgeCreatedTexture:
m.ResetCreatedTexture()
return nil
case user.EdgeProfile:
m.ResetProfile()
return nil
case user.EdgeToken:
m.ResetToken()
return nil
}
return fmt.Errorf("unknown User edge %s", name)
}
// UserProfileMutation represents an operation that mutates the UserProfile nodes in the graph.
type UserProfileMutation struct {
config
op Op
typ string
id *int
name *string
uuid *string
clearedFields map[string]struct{}
user *int
cleareduser bool
texture map[int]struct{}
removedtexture map[int]struct{}
clearedtexture bool
usertexture map[int]struct{}
removedusertexture map[int]struct{}
clearedusertexture bool
done bool
oldValue func(context.Context) (*UserProfile, error)
predicates []predicate.UserProfile
}
var _ ent.Mutation = (*UserProfileMutation)(nil)
// userprofileOption allows management of the mutation configuration using functional options.
type userprofileOption func(*UserProfileMutation)
// newUserProfileMutation creates new mutation for the UserProfile entity.
func newUserProfileMutation(c config, op Op, opts ...userprofileOption) *UserProfileMutation {
m := &UserProfileMutation{
config: c,
op: op,
typ: TypeUserProfile,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserProfileID sets the ID field of the mutation.
func withUserProfileID(id int) userprofileOption {
return func(m *UserProfileMutation) {
var (
err error
once sync.Once
value *UserProfile
)
m.oldValue = func(ctx context.Context) (*UserProfile, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserProfile.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserProfile sets the old UserProfile of the mutation.
func withUserProfile(node *UserProfile) userprofileOption {
return func(m *UserProfileMutation) {
m.oldValue = func(context.Context) (*UserProfile, 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 UserProfileMutation) 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 UserProfileMutation) 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 *UserProfileMutation) 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 *UserProfileMutation) 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().UserProfile.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 *UserProfileMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *UserProfileMutation) 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 UserProfile entity.
// If the UserProfile 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 *UserProfileMutation) 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 *UserProfileMutation) ResetName() {
m.name = nil
}
// SetUUID sets the "uuid" field.
func (m *UserProfileMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *UserProfileMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the UserProfile entity.
// If the UserProfile 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 *UserProfileMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ResetUUID resets all changes to the "uuid" field.
func (m *UserProfileMutation) ResetUUID() {
m.uuid = nil
}
// SetUserID sets the "user" edge to the User entity by id.
func (m *UserProfileMutation) SetUserID(id int) {
m.user = &id
}
// ClearUser clears the "user" edge to the User entity.
func (m *UserProfileMutation) ClearUser() {
m.cleareduser = true
}
// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UserProfileMutation) UserCleared() bool {
return m.cleareduser
}
// UserID returns the "user" edge ID in the mutation.
func (m *UserProfileMutation) UserID() (id int, exists bool) {
if m.user != nil {
return *m.user, true
}
return
}
// 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 *UserProfileMutation) UserIDs() (ids []int) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *UserProfileMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// AddTextureIDs adds the "texture" edge to the Texture entity by ids.
func (m *UserProfileMutation) AddTextureIDs(ids ...int) {
if m.texture == nil {
m.texture = make(map[int]struct{})
}
for i := range ids {
m.texture[ids[i]] = struct{}{}
}
}
// ClearTexture clears the "texture" edge to the Texture entity.
func (m *UserProfileMutation) ClearTexture() {
m.clearedtexture = true
}
// TextureCleared reports if the "texture" edge to the Texture entity was cleared.
func (m *UserProfileMutation) TextureCleared() bool {
return m.clearedtexture
}
// RemoveTextureIDs removes the "texture" edge to the Texture entity by IDs.
func (m *UserProfileMutation) RemoveTextureIDs(ids ...int) {
if m.removedtexture == nil {
m.removedtexture = make(map[int]struct{})
}
for i := range ids {
delete(m.texture, ids[i])
m.removedtexture[ids[i]] = struct{}{}
}
}
// RemovedTexture returns the removed IDs of the "texture" edge to the Texture entity.
func (m *UserProfileMutation) RemovedTextureIDs() (ids []int) {
for id := range m.removedtexture {
ids = append(ids, id)
}
return
}
// TextureIDs returns the "texture" edge IDs in the mutation.
func (m *UserProfileMutation) TextureIDs() (ids []int) {
for id := range m.texture {
ids = append(ids, id)
}
return
}
// ResetTexture resets all changes to the "texture" edge.
func (m *UserProfileMutation) ResetTexture() {
m.texture = nil
m.clearedtexture = false
m.removedtexture = nil
}
// AddUsertextureIDs adds the "usertexture" edge to the UserTexture entity by ids.
func (m *UserProfileMutation) AddUsertextureIDs(ids ...int) {
if m.usertexture == nil {
m.usertexture = make(map[int]struct{})
}
for i := range ids {
m.usertexture[ids[i]] = struct{}{}
}
}
// ClearUsertexture clears the "usertexture" edge to the UserTexture entity.
func (m *UserProfileMutation) ClearUsertexture() {
m.clearedusertexture = true
}
// UsertextureCleared reports if the "usertexture" edge to the UserTexture entity was cleared.
func (m *UserProfileMutation) UsertextureCleared() bool {
return m.clearedusertexture
}
// RemoveUsertextureIDs removes the "usertexture" edge to the UserTexture entity by IDs.
func (m *UserProfileMutation) RemoveUsertextureIDs(ids ...int) {
if m.removedusertexture == nil {
m.removedusertexture = make(map[int]struct{})
}
for i := range ids {
delete(m.usertexture, ids[i])
m.removedusertexture[ids[i]] = struct{}{}
}
}
// RemovedUsertexture returns the removed IDs of the "usertexture" edge to the UserTexture entity.
func (m *UserProfileMutation) RemovedUsertextureIDs() (ids []int) {
for id := range m.removedusertexture {
ids = append(ids, id)
}
return
}
// UsertextureIDs returns the "usertexture" edge IDs in the mutation.
func (m *UserProfileMutation) UsertextureIDs() (ids []int) {
for id := range m.usertexture {
ids = append(ids, id)
}
return
}
// ResetUsertexture resets all changes to the "usertexture" edge.
func (m *UserProfileMutation) ResetUsertexture() {
m.usertexture = nil
m.clearedusertexture = false
m.removedusertexture = nil
}
// Where appends a list predicates to the UserProfileMutation builder.
func (m *UserProfileMutation) Where(ps ...predicate.UserProfile) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserProfileMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserProfileMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UserProfile, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserProfileMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserProfileMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UserProfile).
func (m *UserProfileMutation) 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 *UserProfileMutation) Fields() []string {
fields := make([]string, 0, 2)
if m.name != nil {
fields = append(fields, userprofile.FieldName)
}
if m.uuid != nil {
fields = append(fields, userprofile.FieldUUID)
}
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 *UserProfileMutation) Field(name string) (ent.Value, bool) {
switch name {
case userprofile.FieldName:
return m.Name()
case userprofile.FieldUUID:
return m.UUID()
}
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 *UserProfileMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case userprofile.FieldName:
return m.OldName(ctx)
case userprofile.FieldUUID:
return m.OldUUID(ctx)
}
return nil, fmt.Errorf("unknown UserProfile 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 *UserProfileMutation) SetField(name string, value ent.Value) error {
switch name {
case userprofile.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case userprofile.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
}
return fmt.Errorf("unknown UserProfile field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserProfileMutation) 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 *UserProfileMutation) 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 *UserProfileMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown UserProfile numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserProfileMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserProfileMutation) 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 *UserProfileMutation) ClearField(name string) error {
return fmt.Errorf("unknown UserProfile 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 *UserProfileMutation) ResetField(name string) error {
switch name {
case userprofile.FieldName:
m.ResetName()
return nil
case userprofile.FieldUUID:
m.ResetUUID()
return nil
}
return fmt.Errorf("unknown UserProfile field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserProfileMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.user != nil {
edges = append(edges, userprofile.EdgeUser)
}
if m.texture != nil {
edges = append(edges, userprofile.EdgeTexture)
}
if m.usertexture != nil {
edges = append(edges, userprofile.EdgeUsertexture)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserProfileMutation) AddedIDs(name string) []ent.Value {
switch name {
case userprofile.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
case userprofile.EdgeTexture:
ids := make([]ent.Value, 0, len(m.texture))
for id := range m.texture {
ids = append(ids, id)
}
return ids
case userprofile.EdgeUsertexture:
ids := make([]ent.Value, 0, len(m.usertexture))
for id := range m.usertexture {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserProfileMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
if m.removedtexture != nil {
edges = append(edges, userprofile.EdgeTexture)
}
if m.removedusertexture != nil {
edges = append(edges, userprofile.EdgeUsertexture)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserProfileMutation) RemovedIDs(name string) []ent.Value {
switch name {
case userprofile.EdgeTexture:
ids := make([]ent.Value, 0, len(m.removedtexture))
for id := range m.removedtexture {
ids = append(ids, id)
}
return ids
case userprofile.EdgeUsertexture:
ids := make([]ent.Value, 0, len(m.removedusertexture))
for id := range m.removedusertexture {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserProfileMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.cleareduser {
edges = append(edges, userprofile.EdgeUser)
}
if m.clearedtexture {
edges = append(edges, userprofile.EdgeTexture)
}
if m.clearedusertexture {
edges = append(edges, userprofile.EdgeUsertexture)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserProfileMutation) EdgeCleared(name string) bool {
switch name {
case userprofile.EdgeUser:
return m.cleareduser
case userprofile.EdgeTexture:
return m.clearedtexture
case userprofile.EdgeUsertexture:
return m.clearedusertexture
}
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 *UserProfileMutation) ClearEdge(name string) error {
switch name {
case userprofile.EdgeUser:
m.ClearUser()
return nil
}
return fmt.Errorf("unknown UserProfile 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 *UserProfileMutation) ResetEdge(name string) error {
switch name {
case userprofile.EdgeUser:
m.ResetUser()
return nil
case userprofile.EdgeTexture:
m.ResetTexture()
return nil
case userprofile.EdgeUsertexture:
m.ResetUsertexture()
return nil
}
return fmt.Errorf("unknown UserProfile edge %s", name)
}
// UserTextureMutation represents an operation that mutates the UserTexture nodes in the graph.
type UserTextureMutation struct {
config
op Op
typ string
id *int
_type *string
variant *string
clearedFields map[string]struct{}
user_profile *int
cleareduser_profile bool
texture *int
clearedtexture bool
done bool
oldValue func(context.Context) (*UserTexture, error)
predicates []predicate.UserTexture
}
var _ ent.Mutation = (*UserTextureMutation)(nil)
// usertextureOption allows management of the mutation configuration using functional options.
type usertextureOption func(*UserTextureMutation)
// newUserTextureMutation creates new mutation for the UserTexture entity.
func newUserTextureMutation(c config, op Op, opts ...usertextureOption) *UserTextureMutation {
m := &UserTextureMutation{
config: c,
op: op,
typ: TypeUserTexture,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserTextureID sets the ID field of the mutation.
func withUserTextureID(id int) usertextureOption {
return func(m *UserTextureMutation) {
var (
err error
once sync.Once
value *UserTexture
)
m.oldValue = func(ctx context.Context) (*UserTexture, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserTexture.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserTexture sets the old UserTexture of the mutation.
func withUserTexture(node *UserTexture) usertextureOption {
return func(m *UserTextureMutation) {
m.oldValue = func(context.Context) (*UserTexture, 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 UserTextureMutation) 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 UserTextureMutation) 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 *UserTextureMutation) 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 *UserTextureMutation) 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().UserTexture.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUserProfileID sets the "user_profile_id" field.
func (m *UserTextureMutation) SetUserProfileID(i int) {
m.user_profile = &i
}
// UserProfileID returns the value of the "user_profile_id" field in the mutation.
func (m *UserTextureMutation) UserProfileID() (r int, exists bool) {
v := m.user_profile
if v == nil {
return
}
return *v, true
}
// OldUserProfileID returns the old "user_profile_id" field's value of the UserTexture entity.
// If the UserTexture 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 *UserTextureMutation) OldUserProfileID(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserProfileID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserProfileID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserProfileID: %w", err)
}
return oldValue.UserProfileID, nil
}
// ResetUserProfileID resets all changes to the "user_profile_id" field.
func (m *UserTextureMutation) ResetUserProfileID() {
m.user_profile = nil
}
// SetTextureID sets the "texture_id" field.
func (m *UserTextureMutation) SetTextureID(i int) {
m.texture = &i
}
// TextureID returns the value of the "texture_id" field in the mutation.
func (m *UserTextureMutation) TextureID() (r int, exists bool) {
v := m.texture
if v == nil {
return
}
return *v, true
}
// OldTextureID returns the old "texture_id" field's value of the UserTexture entity.
// If the UserTexture 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 *UserTextureMutation) OldTextureID(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTextureID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTextureID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTextureID: %w", err)
}
return oldValue.TextureID, nil
}
// ResetTextureID resets all changes to the "texture_id" field.
func (m *UserTextureMutation) ResetTextureID() {
m.texture = nil
}
// SetType sets the "type" field.
func (m *UserTextureMutation) SetType(s string) {
m._type = &s
}
// GetType returns the value of the "type" field in the mutation.
func (m *UserTextureMutation) GetType() (r string, exists bool) {
v := m._type
if v == nil {
return
}
return *v, true
}
// OldType returns the old "type" field's value of the UserTexture entity.
// If the UserTexture 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 *UserTextureMutation) OldType(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldType: %w", err)
}
return oldValue.Type, nil
}
// ResetType resets all changes to the "type" field.
func (m *UserTextureMutation) ResetType() {
m._type = nil
}
// SetVariant sets the "variant" field.
func (m *UserTextureMutation) SetVariant(s string) {
m.variant = &s
}
// Variant returns the value of the "variant" field in the mutation.
func (m *UserTextureMutation) Variant() (r string, exists bool) {
v := m.variant
if v == nil {
return
}
return *v, true
}
// OldVariant returns the old "variant" field's value of the UserTexture entity.
// If the UserTexture 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 *UserTextureMutation) OldVariant(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldVariant is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldVariant requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldVariant: %w", err)
}
return oldValue.Variant, nil
}
// ResetVariant resets all changes to the "variant" field.
func (m *UserTextureMutation) ResetVariant() {
m.variant = nil
}
// ClearUserProfile clears the "user_profile" edge to the UserProfile entity.
func (m *UserTextureMutation) ClearUserProfile() {
m.cleareduser_profile = true
}
// UserProfileCleared reports if the "user_profile" edge to the UserProfile entity was cleared.
func (m *UserTextureMutation) UserProfileCleared() bool {
return m.cleareduser_profile
}
// UserProfileIDs returns the "user_profile" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserProfileID instead. It exists only for internal usage by the builders.
func (m *UserTextureMutation) UserProfileIDs() (ids []int) {
if id := m.user_profile; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUserProfile resets all changes to the "user_profile" edge.
func (m *UserTextureMutation) ResetUserProfile() {
m.user_profile = nil
m.cleareduser_profile = false
}
// ClearTexture clears the "texture" edge to the Texture entity.
func (m *UserTextureMutation) ClearTexture() {
m.clearedtexture = true
}
// TextureCleared reports if the "texture" edge to the Texture entity was cleared.
func (m *UserTextureMutation) TextureCleared() bool {
return m.clearedtexture
}
// TextureIDs returns the "texture" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// TextureID instead. It exists only for internal usage by the builders.
func (m *UserTextureMutation) TextureIDs() (ids []int) {
if id := m.texture; id != nil {
ids = append(ids, *id)
}
return
}
// ResetTexture resets all changes to the "texture" edge.
func (m *UserTextureMutation) ResetTexture() {
m.texture = nil
m.clearedtexture = false
}
// Where appends a list predicates to the UserTextureMutation builder.
func (m *UserTextureMutation) Where(ps ...predicate.UserTexture) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserTextureMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserTextureMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UserTexture, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserTextureMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserTextureMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UserTexture).
func (m *UserTextureMutation) 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 *UserTextureMutation) Fields() []string {
fields := make([]string, 0, 4)
if m.user_profile != nil {
fields = append(fields, usertexture.FieldUserProfileID)
}
if m.texture != nil {
fields = append(fields, usertexture.FieldTextureID)
}
if m._type != nil {
fields = append(fields, usertexture.FieldType)
}
if m.variant != nil {
fields = append(fields, usertexture.FieldVariant)
}
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 *UserTextureMutation) Field(name string) (ent.Value, bool) {
switch name {
case usertexture.FieldUserProfileID:
return m.UserProfileID()
case usertexture.FieldTextureID:
return m.TextureID()
case usertexture.FieldType:
return m.GetType()
case usertexture.FieldVariant:
return m.Variant()
}
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 *UserTextureMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case usertexture.FieldUserProfileID:
return m.OldUserProfileID(ctx)
case usertexture.FieldTextureID:
return m.OldTextureID(ctx)
case usertexture.FieldType:
return m.OldType(ctx)
case usertexture.FieldVariant:
return m.OldVariant(ctx)
}
return nil, fmt.Errorf("unknown UserTexture 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 *UserTextureMutation) SetField(name string, value ent.Value) error {
switch name {
case usertexture.FieldUserProfileID:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserProfileID(v)
return nil
case usertexture.FieldTextureID:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTextureID(v)
return nil
case usertexture.FieldType:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetType(v)
return nil
case usertexture.FieldVariant:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetVariant(v)
return nil
}
return fmt.Errorf("unknown UserTexture field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserTextureMutation) AddedFields() []string {
var fields []string
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 *UserTextureMutation) AddedField(name string) (ent.Value, bool) {
switch name {
}
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 *UserTextureMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown UserTexture numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserTextureMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserTextureMutation) 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 *UserTextureMutation) ClearField(name string) error {
return fmt.Errorf("unknown UserTexture 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 *UserTextureMutation) ResetField(name string) error {
switch name {
case usertexture.FieldUserProfileID:
m.ResetUserProfileID()
return nil
case usertexture.FieldTextureID:
m.ResetTextureID()
return nil
case usertexture.FieldType:
m.ResetType()
return nil
case usertexture.FieldVariant:
m.ResetVariant()
return nil
}
return fmt.Errorf("unknown UserTexture field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserTextureMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.user_profile != nil {
edges = append(edges, usertexture.EdgeUserProfile)
}
if m.texture != nil {
edges = append(edges, usertexture.EdgeTexture)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserTextureMutation) AddedIDs(name string) []ent.Value {
switch name {
case usertexture.EdgeUserProfile:
if id := m.user_profile; id != nil {
return []ent.Value{*id}
}
case usertexture.EdgeTexture:
if id := m.texture; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserTextureMutation) 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 *UserTextureMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserTextureMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.cleareduser_profile {
edges = append(edges, usertexture.EdgeUserProfile)
}
if m.clearedtexture {
edges = append(edges, usertexture.EdgeTexture)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserTextureMutation) EdgeCleared(name string) bool {
switch name {
case usertexture.EdgeUserProfile:
return m.cleareduser_profile
case usertexture.EdgeTexture:
return m.clearedtexture
}
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 *UserTextureMutation) ClearEdge(name string) error {
switch name {
case usertexture.EdgeUserProfile:
m.ClearUserProfile()
return nil
case usertexture.EdgeTexture:
m.ClearTexture()
return nil
}
return fmt.Errorf("unknown UserTexture 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 *UserTextureMutation) ResetEdge(name string) error {
switch name {
case usertexture.EdgeUserProfile:
m.ResetUserProfile()
return nil
case usertexture.EdgeTexture:
m.ResetTexture()
return nil
}
return fmt.Errorf("unknown UserTexture edge %s", name)
}
// UserTokenMutation represents an operation that mutates the UserToken nodes in the graph.
type UserTokenMutation struct {
config
op Op
typ string
id *int
token_id *uint64
addtoken_id *int64
clearedFields map[string]struct{}
user *int
cleareduser bool
done bool
oldValue func(context.Context) (*UserToken, error)
predicates []predicate.UserToken
}
var _ ent.Mutation = (*UserTokenMutation)(nil)
// usertokenOption allows management of the mutation configuration using functional options.
type usertokenOption func(*UserTokenMutation)
// newUserTokenMutation creates new mutation for the UserToken entity.
func newUserTokenMutation(c config, op Op, opts ...usertokenOption) *UserTokenMutation {
m := &UserTokenMutation{
config: c,
op: op,
typ: TypeUserToken,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserTokenID sets the ID field of the mutation.
func withUserTokenID(id int) usertokenOption {
return func(m *UserTokenMutation) {
var (
err error
once sync.Once
value *UserToken
)
m.oldValue = func(ctx context.Context) (*UserToken, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserToken.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserToken sets the old UserToken of the mutation.
func withUserToken(node *UserToken) usertokenOption {
return func(m *UserTokenMutation) {
m.oldValue = func(context.Context) (*UserToken, 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 UserTokenMutation) 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 UserTokenMutation) 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 *UserTokenMutation) 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 *UserTokenMutation) 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().UserToken.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetTokenID sets the "token_id" field.
func (m *UserTokenMutation) SetTokenID(u uint64) {
m.token_id = &u
m.addtoken_id = nil
}
// TokenID returns the value of the "token_id" field in the mutation.
func (m *UserTokenMutation) TokenID() (r uint64, exists bool) {
v := m.token_id
if v == nil {
return
}
return *v, true
}
// OldTokenID returns the old "token_id" field's value of the UserToken entity.
// If the UserToken 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 *UserTokenMutation) OldTokenID(ctx context.Context) (v uint64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTokenID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTokenID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTokenID: %w", err)
}
return oldValue.TokenID, nil
}
// AddTokenID adds u to the "token_id" field.
func (m *UserTokenMutation) AddTokenID(u int64) {
if m.addtoken_id != nil {
*m.addtoken_id += u
} else {
m.addtoken_id = &u
}
}
// AddedTokenID returns the value that was added to the "token_id" field in this mutation.
func (m *UserTokenMutation) AddedTokenID() (r int64, exists bool) {
v := m.addtoken_id
if v == nil {
return
}
return *v, true
}
// ResetTokenID resets all changes to the "token_id" field.
func (m *UserTokenMutation) ResetTokenID() {
m.token_id = nil
m.addtoken_id = nil
}
// SetUserID sets the "user" edge to the User entity by id.
func (m *UserTokenMutation) SetUserID(id int) {
m.user = &id
}
// ClearUser clears the "user" edge to the User entity.
func (m *UserTokenMutation) ClearUser() {
m.cleareduser = true
}
// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UserTokenMutation) UserCleared() bool {
return m.cleareduser
}
// UserID returns the "user" edge ID in the mutation.
func (m *UserTokenMutation) UserID() (id int, exists bool) {
if m.user != nil {
return *m.user, true
}
return
}
// 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 *UserTokenMutation) UserIDs() (ids []int) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *UserTokenMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// Where appends a list predicates to the UserTokenMutation builder.
func (m *UserTokenMutation) Where(ps ...predicate.UserToken) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserTokenMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserTokenMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UserToken, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserTokenMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserTokenMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UserToken).
func (m *UserTokenMutation) 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 *UserTokenMutation) Fields() []string {
fields := make([]string, 0, 1)
if m.token_id != nil {
fields = append(fields, usertoken.FieldTokenID)
}
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 *UserTokenMutation) Field(name string) (ent.Value, bool) {
switch name {
case usertoken.FieldTokenID:
return m.TokenID()
}
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 *UserTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case usertoken.FieldTokenID:
return m.OldTokenID(ctx)
}
return nil, fmt.Errorf("unknown UserToken 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 *UserTokenMutation) SetField(name string, value ent.Value) error {
switch name {
case usertoken.FieldTokenID:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTokenID(v)
return nil
}
return fmt.Errorf("unknown UserToken field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserTokenMutation) AddedFields() []string {
var fields []string
if m.addtoken_id != nil {
fields = append(fields, usertoken.FieldTokenID)
}
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 *UserTokenMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case usertoken.FieldTokenID:
return m.AddedTokenID()
}
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 *UserTokenMutation) AddField(name string, value ent.Value) error {
switch name {
case usertoken.FieldTokenID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddTokenID(v)
return nil
}
return fmt.Errorf("unknown UserToken numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserTokenMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserTokenMutation) 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 *UserTokenMutation) ClearField(name string) error {
return fmt.Errorf("unknown UserToken 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 *UserTokenMutation) ResetField(name string) error {
switch name {
case usertoken.FieldTokenID:
m.ResetTokenID()
return nil
}
return fmt.Errorf("unknown UserToken field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserTokenMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.user != nil {
edges = append(edges, usertoken.EdgeUser)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserTokenMutation) AddedIDs(name string) []ent.Value {
switch name {
case usertoken.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserTokenMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserTokenMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserTokenMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.cleareduser {
edges = append(edges, usertoken.EdgeUser)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserTokenMutation) EdgeCleared(name string) bool {
switch name {
case usertoken.EdgeUser:
return m.cleareduser
}
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 *UserTokenMutation) ClearEdge(name string) error {
switch name {
case usertoken.EdgeUser:
m.ClearUser()
return nil
}
return fmt.Errorf("unknown UserToken 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 *UserTokenMutation) ResetEdge(name string) error {
switch name {
case usertoken.EdgeUser:
m.ResetUser()
return nil
}
return fmt.Errorf("unknown UserToken edge %s", name)
}