1779 lines
49 KiB
Go
1779 lines
49 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/skin"
|
|
"github.com/xmdhs/authlib-skin/db/ent/user"
|
|
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
|
)
|
|
|
|
const (
|
|
// Operation types.
|
|
OpCreate = ent.OpCreate
|
|
OpDelete = ent.OpDelete
|
|
OpDeleteOne = ent.OpDeleteOne
|
|
OpUpdate = ent.OpUpdate
|
|
OpUpdateOne = ent.OpUpdateOne
|
|
|
|
// Node types.
|
|
TypeSkin = "Skin"
|
|
TypeUser = "User"
|
|
TypeUserProfile = "UserProfile"
|
|
)
|
|
|
|
// SkinMutation represents an operation that mutates the Skin nodes in the graph.
|
|
type SkinMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
skin_hash *string
|
|
_type *uint8
|
|
add_type *int8
|
|
variant *string
|
|
clearedFields map[string]struct{}
|
|
user *int
|
|
cleareduser bool
|
|
done bool
|
|
oldValue func(context.Context) (*Skin, error)
|
|
predicates []predicate.Skin
|
|
}
|
|
|
|
var _ ent.Mutation = (*SkinMutation)(nil)
|
|
|
|
// skinOption allows management of the mutation configuration using functional options.
|
|
type skinOption func(*SkinMutation)
|
|
|
|
// newSkinMutation creates new mutation for the Skin entity.
|
|
func newSkinMutation(c config, op Op, opts ...skinOption) *SkinMutation {
|
|
m := &SkinMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeSkin,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withSkinID sets the ID field of the mutation.
|
|
func withSkinID(id int) skinOption {
|
|
return func(m *SkinMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Skin
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Skin, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Skin.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withSkin sets the old Skin of the mutation.
|
|
func withSkin(node *Skin) skinOption {
|
|
return func(m *SkinMutation) {
|
|
m.oldValue = func(context.Context) (*Skin, 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 SkinMutation) 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 SkinMutation) 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 *SkinMutation) 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 *SkinMutation) 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().Skin.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetSkinHash sets the "skin_hash" field.
|
|
func (m *SkinMutation) SetSkinHash(s string) {
|
|
m.skin_hash = &s
|
|
}
|
|
|
|
// SkinHash returns the value of the "skin_hash" field in the mutation.
|
|
func (m *SkinMutation) SkinHash() (r string, exists bool) {
|
|
v := m.skin_hash
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldSkinHash returns the old "skin_hash" field's value of the Skin entity.
|
|
// If the Skin 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 *SkinMutation) OldSkinHash(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldSkinHash is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldSkinHash requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldSkinHash: %w", err)
|
|
}
|
|
return oldValue.SkinHash, nil
|
|
}
|
|
|
|
// ResetSkinHash resets all changes to the "skin_hash" field.
|
|
func (m *SkinMutation) ResetSkinHash() {
|
|
m.skin_hash = nil
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (m *SkinMutation) SetType(u uint8) {
|
|
m._type = &u
|
|
m.add_type = nil
|
|
}
|
|
|
|
// GetType returns the value of the "type" field in the mutation.
|
|
func (m *SkinMutation) GetType() (r uint8, exists bool) {
|
|
v := m._type
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldType returns the old "type" field's value of the Skin entity.
|
|
// If the Skin 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 *SkinMutation) OldType(ctx context.Context) (v uint8, 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
|
|
}
|
|
|
|
// AddType adds u to the "type" field.
|
|
func (m *SkinMutation) AddType(u int8) {
|
|
if m.add_type != nil {
|
|
*m.add_type += u
|
|
} else {
|
|
m.add_type = &u
|
|
}
|
|
}
|
|
|
|
// AddedType returns the value that was added to the "type" field in this mutation.
|
|
func (m *SkinMutation) AddedType() (r int8, exists bool) {
|
|
v := m.add_type
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetType resets all changes to the "type" field.
|
|
func (m *SkinMutation) ResetType() {
|
|
m._type = nil
|
|
m.add_type = nil
|
|
}
|
|
|
|
// SetVariant sets the "variant" field.
|
|
func (m *SkinMutation) SetVariant(s string) {
|
|
m.variant = &s
|
|
}
|
|
|
|
// Variant returns the value of the "variant" field in the mutation.
|
|
func (m *SkinMutation) 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 Skin entity.
|
|
// If the Skin 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 *SkinMutation) 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 *SkinMutation) ResetVariant() {
|
|
m.variant = nil
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by id.
|
|
func (m *SkinMutation) SetUserID(id int) {
|
|
m.user = &id
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (m *SkinMutation) ClearUser() {
|
|
m.cleareduser = true
|
|
}
|
|
|
|
// UserCleared reports if the "user" edge to the User entity was cleared.
|
|
func (m *SkinMutation) UserCleared() bool {
|
|
return m.cleareduser
|
|
}
|
|
|
|
// UserID returns the "user" edge ID in the mutation.
|
|
func (m *SkinMutation) 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 *SkinMutation) UserIDs() (ids []int) {
|
|
if id := m.user; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetUser resets all changes to the "user" edge.
|
|
func (m *SkinMutation) ResetUser() {
|
|
m.user = nil
|
|
m.cleareduser = false
|
|
}
|
|
|
|
// Where appends a list predicates to the SkinMutation builder.
|
|
func (m *SkinMutation) Where(ps ...predicate.Skin) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the SkinMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *SkinMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Skin, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *SkinMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *SkinMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Skin).
|
|
func (m *SkinMutation) 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 *SkinMutation) Fields() []string {
|
|
fields := make([]string, 0, 3)
|
|
if m.skin_hash != nil {
|
|
fields = append(fields, skin.FieldSkinHash)
|
|
}
|
|
if m._type != nil {
|
|
fields = append(fields, skin.FieldType)
|
|
}
|
|
if m.variant != nil {
|
|
fields = append(fields, skin.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 *SkinMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case skin.FieldSkinHash:
|
|
return m.SkinHash()
|
|
case skin.FieldType:
|
|
return m.GetType()
|
|
case skin.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 *SkinMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case skin.FieldSkinHash:
|
|
return m.OldSkinHash(ctx)
|
|
case skin.FieldType:
|
|
return m.OldType(ctx)
|
|
case skin.FieldVariant:
|
|
return m.OldVariant(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Skin 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 *SkinMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case skin.FieldSkinHash:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetSkinHash(v)
|
|
return nil
|
|
case skin.FieldType:
|
|
v, ok := value.(uint8)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetType(v)
|
|
return nil
|
|
case skin.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 Skin field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *SkinMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.add_type != nil {
|
|
fields = append(fields, skin.FieldType)
|
|
}
|
|
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 *SkinMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case skin.FieldType:
|
|
return m.AddedType()
|
|
}
|
|
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 *SkinMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case skin.FieldType:
|
|
v, ok := value.(int8)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddType(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Skin numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *SkinMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *SkinMutation) 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 *SkinMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Skin 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 *SkinMutation) ResetField(name string) error {
|
|
switch name {
|
|
case skin.FieldSkinHash:
|
|
m.ResetSkinHash()
|
|
return nil
|
|
case skin.FieldType:
|
|
m.ResetType()
|
|
return nil
|
|
case skin.FieldVariant:
|
|
m.ResetVariant()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Skin field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *SkinMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.user != nil {
|
|
edges = append(edges, skin.EdgeUser)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *SkinMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case skin.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 *SkinMutation) 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 *SkinMutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *SkinMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.cleareduser {
|
|
edges = append(edges, skin.EdgeUser)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *SkinMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case skin.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 *SkinMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
case skin.EdgeUser:
|
|
m.ClearUser()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Skin 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 *SkinMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case skin.EdgeUser:
|
|
m.ResetUser()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Skin 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
|
|
state *int
|
|
addstate *int
|
|
reg_time *int64
|
|
addreg_time *int64
|
|
clearedFields map[string]struct{}
|
|
skin map[int]struct{}
|
|
removedskin map[int]struct{}
|
|
clearedskin bool
|
|
profile *int
|
|
clearedprofile 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// AddSkinIDs adds the "skin" edge to the Skin entity by ids.
|
|
func (m *UserMutation) AddSkinIDs(ids ...int) {
|
|
if m.skin == nil {
|
|
m.skin = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.skin[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearSkin clears the "skin" edge to the Skin entity.
|
|
func (m *UserMutation) ClearSkin() {
|
|
m.clearedskin = true
|
|
}
|
|
|
|
// SkinCleared reports if the "skin" edge to the Skin entity was cleared.
|
|
func (m *UserMutation) SkinCleared() bool {
|
|
return m.clearedskin
|
|
}
|
|
|
|
// RemoveSkinIDs removes the "skin" edge to the Skin entity by IDs.
|
|
func (m *UserMutation) RemoveSkinIDs(ids ...int) {
|
|
if m.removedskin == nil {
|
|
m.removedskin = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m.skin, ids[i])
|
|
m.removedskin[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedSkin returns the removed IDs of the "skin" edge to the Skin entity.
|
|
func (m *UserMutation) RemovedSkinIDs() (ids []int) {
|
|
for id := range m.removedskin {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// SkinIDs returns the "skin" edge IDs in the mutation.
|
|
func (m *UserMutation) SkinIDs() (ids []int) {
|
|
for id := range m.skin {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetSkin resets all changes to the "skin" edge.
|
|
func (m *UserMutation) ResetSkin() {
|
|
m.skin = nil
|
|
m.clearedskin = false
|
|
m.removedskin = 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
|
|
}
|
|
|
|
// Where appends a list predicates to the UserMutation builder.
|
|
func (m *UserMutation) Where(ps ...predicate.User) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.User, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *UserMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *UserMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (User).
|
|
func (m *UserMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *UserMutation) Fields() []string {
|
|
fields := make([]string, 0, 5)
|
|
if m.email != nil {
|
|
fields = append(fields, user.FieldEmail)
|
|
}
|
|
if m.password != nil {
|
|
fields = append(fields, user.FieldPassword)
|
|
}
|
|
if m.salt != nil {
|
|
fields = append(fields, user.FieldSalt)
|
|
}
|
|
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.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.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.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.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, 2)
|
|
if m.skin != nil {
|
|
edges = append(edges, user.EdgeSkin)
|
|
}
|
|
if m.profile != nil {
|
|
edges = append(edges, user.EdgeProfile)
|
|
}
|
|
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.EdgeSkin:
|
|
ids := make([]ent.Value, 0, len(m.skin))
|
|
for id := range m.skin {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case user.EdgeProfile:
|
|
if id := m.profile; 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, 2)
|
|
if m.removedskin != nil {
|
|
edges = append(edges, user.EdgeSkin)
|
|
}
|
|
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.EdgeSkin:
|
|
ids := make([]ent.Value, 0, len(m.removedskin))
|
|
for id := range m.removedskin {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *UserMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.clearedskin {
|
|
edges = append(edges, user.EdgeSkin)
|
|
}
|
|
if m.clearedprofile {
|
|
edges = append(edges, user.EdgeProfile)
|
|
}
|
|
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.EdgeSkin:
|
|
return m.clearedskin
|
|
case user.EdgeProfile:
|
|
return m.clearedprofile
|
|
}
|
|
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
|
|
}
|
|
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.EdgeSkin:
|
|
m.ResetSkin()
|
|
return nil
|
|
case user.EdgeProfile:
|
|
m.ResetProfile()
|
|
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
|
|
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
|
|
}
|
|
|
|
// 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, 1)
|
|
if m.user != nil {
|
|
edges = append(edges, userprofile.EdgeUser)
|
|
}
|
|
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}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *UserProfileMutation) 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 *UserProfileMutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *UserProfileMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.cleareduser {
|
|
edges = append(edges, userprofile.EdgeUser)
|
|
}
|
|
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
|
|
}
|
|
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
|
|
}
|
|
return fmt.Errorf("unknown UserProfile edge %s", name)
|
|
}
|