Files

1718 lines
50 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"omctf.ru/block-game-backend/codegen/ent/level"
"omctf.ru/block-game-backend/codegen/ent/predicate"
"omctf.ru/block-game-backend/codegen/ent/setting"
"omctf.ru/block-game-backend/codegen/ent/user"
"omctf.ru/block-game-backend/schema"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeLevel = "Level"
TypeSetting = "Setting"
TypeUser = "User"
)
// LevelMutation represents an operation that mutates the Level nodes in the graph.
type LevelMutation struct {
config
op Op
typ string
id *int
name *string
description *string
visibility *level.Visibility
data *schema.LevelData
prize *string
createdAt *time.Time
clearedFields map[string]struct{}
owner *int
clearedowner bool
invitedPlayers map[int]struct{}
removedinvitedPlayers map[int]struct{}
clearedinvitedPlayers bool
done bool
oldValue func(context.Context) (*Level, error)
predicates []predicate.Level
}
var _ ent.Mutation = (*LevelMutation)(nil)
// levelOption allows management of the mutation configuration using functional options.
type levelOption func(*LevelMutation)
// newLevelMutation creates new mutation for the Level entity.
func newLevelMutation(c config, op Op, opts ...levelOption) *LevelMutation {
m := &LevelMutation{
config: c,
op: op,
typ: TypeLevel,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withLevelID sets the ID field of the mutation.
func withLevelID(id int) levelOption {
return func(m *LevelMutation) {
var (
err error
once sync.Once
value *Level
)
m.oldValue = func(ctx context.Context) (*Level, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Level.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withLevel sets the old Level of the mutation.
func withLevel(node *Level) levelOption {
return func(m *LevelMutation) {
m.oldValue = func(context.Context) (*Level, 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 LevelMutation) 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 LevelMutation) 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 *LevelMutation) 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 *LevelMutation) 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().Level.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 *LevelMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *LevelMutation) 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 Level entity.
// If the Level 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 *LevelMutation) 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 *LevelMutation) ResetName() {
m.name = nil
}
// SetDescription sets the "description" field.
func (m *LevelMutation) SetDescription(s string) {
m.description = &s
}
// Description returns the value of the "description" field in the mutation.
func (m *LevelMutation) Description() (r string, exists bool) {
v := m.description
if v == nil {
return
}
return *v, true
}
// OldDescription returns the old "description" field's value of the Level entity.
// If the Level 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 *LevelMutation) OldDescription(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDescription: %w", err)
}
return oldValue.Description, nil
}
// ResetDescription resets all changes to the "description" field.
func (m *LevelMutation) ResetDescription() {
m.description = nil
}
// SetVisibility sets the "visibility" field.
func (m *LevelMutation) SetVisibility(l level.Visibility) {
m.visibility = &l
}
// Visibility returns the value of the "visibility" field in the mutation.
func (m *LevelMutation) Visibility() (r level.Visibility, exists bool) {
v := m.visibility
if v == nil {
return
}
return *v, true
}
// OldVisibility returns the old "visibility" field's value of the Level entity.
// If the Level 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 *LevelMutation) OldVisibility(ctx context.Context) (v level.Visibility, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldVisibility is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldVisibility requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldVisibility: %w", err)
}
return oldValue.Visibility, nil
}
// ResetVisibility resets all changes to the "visibility" field.
func (m *LevelMutation) ResetVisibility() {
m.visibility = nil
}
// SetData sets the "data" field.
func (m *LevelMutation) SetData(sd schema.LevelData) {
m.data = &sd
}
// Data returns the value of the "data" field in the mutation.
func (m *LevelMutation) Data() (r schema.LevelData, exists bool) {
v := m.data
if v == nil {
return
}
return *v, true
}
// OldData returns the old "data" field's value of the Level entity.
// If the Level 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 *LevelMutation) OldData(ctx context.Context) (v schema.LevelData, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldData is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldData requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldData: %w", err)
}
return oldValue.Data, nil
}
// ResetData resets all changes to the "data" field.
func (m *LevelMutation) ResetData() {
m.data = nil
}
// SetPrize sets the "prize" field.
func (m *LevelMutation) SetPrize(s string) {
m.prize = &s
}
// Prize returns the value of the "prize" field in the mutation.
func (m *LevelMutation) Prize() (r string, exists bool) {
v := m.prize
if v == nil {
return
}
return *v, true
}
// OldPrize returns the old "prize" field's value of the Level entity.
// If the Level 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 *LevelMutation) OldPrize(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPrize is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPrize requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPrize: %w", err)
}
return oldValue.Prize, nil
}
// ResetPrize resets all changes to the "prize" field.
func (m *LevelMutation) ResetPrize() {
m.prize = nil
}
// SetCreatedAt sets the "createdAt" field.
func (m *LevelMutation) SetCreatedAt(t time.Time) {
m.createdAt = &t
}
// CreatedAt returns the value of the "createdAt" field in the mutation.
func (m *LevelMutation) CreatedAt() (r time.Time, exists bool) {
v := m.createdAt
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "createdAt" field's value of the Level entity.
// If the Level 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 *LevelMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "createdAt" field.
func (m *LevelMutation) ResetCreatedAt() {
m.createdAt = nil
}
// SetOwnerID sets the "owner" edge to the User entity by id.
func (m *LevelMutation) SetOwnerID(id int) {
m.owner = &id
}
// ClearOwner clears the "owner" edge to the User entity.
func (m *LevelMutation) ClearOwner() {
m.clearedowner = true
}
// OwnerCleared reports if the "owner" edge to the User entity was cleared.
func (m *LevelMutation) OwnerCleared() bool {
return m.clearedowner
}
// OwnerID returns the "owner" edge ID in the mutation.
func (m *LevelMutation) OwnerID() (id int, exists bool) {
if m.owner != nil {
return *m.owner, true
}
return
}
// OwnerIDs returns the "owner" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// OwnerID instead. It exists only for internal usage by the builders.
func (m *LevelMutation) OwnerIDs() (ids []int) {
if id := m.owner; id != nil {
ids = append(ids, *id)
}
return
}
// ResetOwner resets all changes to the "owner" edge.
func (m *LevelMutation) ResetOwner() {
m.owner = nil
m.clearedowner = false
}
// AddInvitedPlayerIDs adds the "invitedPlayers" edge to the User entity by ids.
func (m *LevelMutation) AddInvitedPlayerIDs(ids ...int) {
if m.invitedPlayers == nil {
m.invitedPlayers = make(map[int]struct{})
}
for i := range ids {
m.invitedPlayers[ids[i]] = struct{}{}
}
}
// ClearInvitedPlayers clears the "invitedPlayers" edge to the User entity.
func (m *LevelMutation) ClearInvitedPlayers() {
m.clearedinvitedPlayers = true
}
// InvitedPlayersCleared reports if the "invitedPlayers" edge to the User entity was cleared.
func (m *LevelMutation) InvitedPlayersCleared() bool {
return m.clearedinvitedPlayers
}
// RemoveInvitedPlayerIDs removes the "invitedPlayers" edge to the User entity by IDs.
func (m *LevelMutation) RemoveInvitedPlayerIDs(ids ...int) {
if m.removedinvitedPlayers == nil {
m.removedinvitedPlayers = make(map[int]struct{})
}
for i := range ids {
delete(m.invitedPlayers, ids[i])
m.removedinvitedPlayers[ids[i]] = struct{}{}
}
}
// RemovedInvitedPlayers returns the removed IDs of the "invitedPlayers" edge to the User entity.
func (m *LevelMutation) RemovedInvitedPlayersIDs() (ids []int) {
for id := range m.removedinvitedPlayers {
ids = append(ids, id)
}
return
}
// InvitedPlayersIDs returns the "invitedPlayers" edge IDs in the mutation.
func (m *LevelMutation) InvitedPlayersIDs() (ids []int) {
for id := range m.invitedPlayers {
ids = append(ids, id)
}
return
}
// ResetInvitedPlayers resets all changes to the "invitedPlayers" edge.
func (m *LevelMutation) ResetInvitedPlayers() {
m.invitedPlayers = nil
m.clearedinvitedPlayers = false
m.removedinvitedPlayers = nil
}
// Where appends a list predicates to the LevelMutation builder.
func (m *LevelMutation) Where(ps ...predicate.Level) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the LevelMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *LevelMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Level, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *LevelMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *LevelMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Level).
func (m *LevelMutation) 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 *LevelMutation) Fields() []string {
fields := make([]string, 0, 6)
if m.name != nil {
fields = append(fields, level.FieldName)
}
if m.description != nil {
fields = append(fields, level.FieldDescription)
}
if m.visibility != nil {
fields = append(fields, level.FieldVisibility)
}
if m.data != nil {
fields = append(fields, level.FieldData)
}
if m.prize != nil {
fields = append(fields, level.FieldPrize)
}
if m.createdAt != nil {
fields = append(fields, level.FieldCreatedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *LevelMutation) Field(name string) (ent.Value, bool) {
switch name {
case level.FieldName:
return m.Name()
case level.FieldDescription:
return m.Description()
case level.FieldVisibility:
return m.Visibility()
case level.FieldData:
return m.Data()
case level.FieldPrize:
return m.Prize()
case level.FieldCreatedAt:
return m.CreatedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *LevelMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case level.FieldName:
return m.OldName(ctx)
case level.FieldDescription:
return m.OldDescription(ctx)
case level.FieldVisibility:
return m.OldVisibility(ctx)
case level.FieldData:
return m.OldData(ctx)
case level.FieldPrize:
return m.OldPrize(ctx)
case level.FieldCreatedAt:
return m.OldCreatedAt(ctx)
}
return nil, fmt.Errorf("unknown Level 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 *LevelMutation) SetField(name string, value ent.Value) error {
switch name {
case level.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case level.FieldDescription:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDescription(v)
return nil
case level.FieldVisibility:
v, ok := value.(level.Visibility)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetVisibility(v)
return nil
case level.FieldData:
v, ok := value.(schema.LevelData)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetData(v)
return nil
case level.FieldPrize:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPrize(v)
return nil
case level.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
}
return fmt.Errorf("unknown Level field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *LevelMutation) 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 *LevelMutation) 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 *LevelMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Level numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *LevelMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *LevelMutation) 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 *LevelMutation) ClearField(name string) error {
return fmt.Errorf("unknown Level 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 *LevelMutation) ResetField(name string) error {
switch name {
case level.FieldName:
m.ResetName()
return nil
case level.FieldDescription:
m.ResetDescription()
return nil
case level.FieldVisibility:
m.ResetVisibility()
return nil
case level.FieldData:
m.ResetData()
return nil
case level.FieldPrize:
m.ResetPrize()
return nil
case level.FieldCreatedAt:
m.ResetCreatedAt()
return nil
}
return fmt.Errorf("unknown Level field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *LevelMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.owner != nil {
edges = append(edges, level.EdgeOwner)
}
if m.invitedPlayers != nil {
edges = append(edges, level.EdgeInvitedPlayers)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *LevelMutation) AddedIDs(name string) []ent.Value {
switch name {
case level.EdgeOwner:
if id := m.owner; id != nil {
return []ent.Value{*id}
}
case level.EdgeInvitedPlayers:
ids := make([]ent.Value, 0, len(m.invitedPlayers))
for id := range m.invitedPlayers {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *LevelMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
if m.removedinvitedPlayers != nil {
edges = append(edges, level.EdgeInvitedPlayers)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *LevelMutation) RemovedIDs(name string) []ent.Value {
switch name {
case level.EdgeInvitedPlayers:
ids := make([]ent.Value, 0, len(m.removedinvitedPlayers))
for id := range m.removedinvitedPlayers {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *LevelMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.clearedowner {
edges = append(edges, level.EdgeOwner)
}
if m.clearedinvitedPlayers {
edges = append(edges, level.EdgeInvitedPlayers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *LevelMutation) EdgeCleared(name string) bool {
switch name {
case level.EdgeOwner:
return m.clearedowner
case level.EdgeInvitedPlayers:
return m.clearedinvitedPlayers
}
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 *LevelMutation) ClearEdge(name string) error {
switch name {
case level.EdgeOwner:
m.ClearOwner()
return nil
}
return fmt.Errorf("unknown Level 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 *LevelMutation) ResetEdge(name string) error {
switch name {
case level.EdgeOwner:
m.ResetOwner()
return nil
case level.EdgeInvitedPlayers:
m.ResetInvitedPlayers()
return nil
}
return fmt.Errorf("unknown Level edge %s", name)
}
// SettingMutation represents an operation that mutates the Setting nodes in the graph.
type SettingMutation struct {
config
op Op
typ string
id *int
key *string
value *string
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Setting, error)
predicates []predicate.Setting
}
var _ ent.Mutation = (*SettingMutation)(nil)
// settingOption allows management of the mutation configuration using functional options.
type settingOption func(*SettingMutation)
// newSettingMutation creates new mutation for the Setting entity.
func newSettingMutation(c config, op Op, opts ...settingOption) *SettingMutation {
m := &SettingMutation{
config: c,
op: op,
typ: TypeSetting,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSettingID sets the ID field of the mutation.
func withSettingID(id int) settingOption {
return func(m *SettingMutation) {
var (
err error
once sync.Once
value *Setting
)
m.oldValue = func(ctx context.Context) (*Setting, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Setting.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSetting sets the old Setting of the mutation.
func withSetting(node *Setting) settingOption {
return func(m *SettingMutation) {
m.oldValue = func(context.Context) (*Setting, 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 SettingMutation) 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 SettingMutation) 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 *SettingMutation) 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 *SettingMutation) 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().Setting.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetKey sets the "key" field.
func (m *SettingMutation) SetKey(s string) {
m.key = &s
}
// Key returns the value of the "key" field in the mutation.
func (m *SettingMutation) Key() (r string, exists bool) {
v := m.key
if v == nil {
return
}
return *v, true
}
// OldKey returns the old "key" field's value of the Setting entity.
// If the Setting 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 *SettingMutation) OldKey(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldKey is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldKey requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldKey: %w", err)
}
return oldValue.Key, nil
}
// ResetKey resets all changes to the "key" field.
func (m *SettingMutation) ResetKey() {
m.key = nil
}
// SetValue sets the "value" field.
func (m *SettingMutation) SetValue(s string) {
m.value = &s
}
// Value returns the value of the "value" field in the mutation.
func (m *SettingMutation) Value() (r string, exists bool) {
v := m.value
if v == nil {
return
}
return *v, true
}
// OldValue returns the old "value" field's value of the Setting entity.
// If the Setting 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 *SettingMutation) OldValue(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldValue is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldValue requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldValue: %w", err)
}
return oldValue.Value, nil
}
// ResetValue resets all changes to the "value" field.
func (m *SettingMutation) ResetValue() {
m.value = nil
}
// Where appends a list predicates to the SettingMutation builder.
func (m *SettingMutation) Where(ps ...predicate.Setting) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SettingMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SettingMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Setting, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SettingMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SettingMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Setting).
func (m *SettingMutation) 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 *SettingMutation) Fields() []string {
fields := make([]string, 0, 2)
if m.key != nil {
fields = append(fields, setting.FieldKey)
}
if m.value != nil {
fields = append(fields, setting.FieldValue)
}
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 *SettingMutation) Field(name string) (ent.Value, bool) {
switch name {
case setting.FieldKey:
return m.Key()
case setting.FieldValue:
return m.Value()
}
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 *SettingMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case setting.FieldKey:
return m.OldKey(ctx)
case setting.FieldValue:
return m.OldValue(ctx)
}
return nil, fmt.Errorf("unknown Setting 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 *SettingMutation) SetField(name string, value ent.Value) error {
switch name {
case setting.FieldKey:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetKey(v)
return nil
case setting.FieldValue:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetValue(v)
return nil
}
return fmt.Errorf("unknown Setting field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SettingMutation) 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 *SettingMutation) 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 *SettingMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Setting numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SettingMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SettingMutation) 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 *SettingMutation) ClearField(name string) error {
return fmt.Errorf("unknown Setting 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 *SettingMutation) ResetField(name string) error {
switch name {
case setting.FieldKey:
m.ResetKey()
return nil
case setting.FieldValue:
m.ResetValue()
return nil
}
return fmt.Errorf("unknown Setting field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SettingMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SettingMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SettingMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SettingMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SettingMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SettingMutation) EdgeCleared(name string) bool {
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *SettingMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Setting 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 *SettingMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Setting 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
username *string
password *string
clearedFields map[string]struct{}
ownedLevels map[int]struct{}
removedownedLevels map[int]struct{}
clearedownedLevels bool
invitedToLevels map[int]struct{}
removedinvitedToLevels map[int]struct{}
clearedinvitedToLevels 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)
}
}
// SetUsername sets the "username" field.
func (m *UserMutation) SetUsername(s string) {
m.username = &s
}
// Username returns the value of the "username" field in the mutation.
func (m *UserMutation) Username() (r string, exists bool) {
v := m.username
if v == nil {
return
}
return *v, true
}
// OldUsername returns the old "username" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldUsername(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsername is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsername requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsername: %w", err)
}
return oldValue.Username, nil
}
// ResetUsername resets all changes to the "username" field.
func (m *UserMutation) ResetUsername() {
m.username = 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
}
// AddOwnedLevelIDs adds the "ownedLevels" edge to the Level entity by ids.
func (m *UserMutation) AddOwnedLevelIDs(ids ...int) {
if m.ownedLevels == nil {
m.ownedLevels = make(map[int]struct{})
}
for i := range ids {
m.ownedLevels[ids[i]] = struct{}{}
}
}
// ClearOwnedLevels clears the "ownedLevels" edge to the Level entity.
func (m *UserMutation) ClearOwnedLevels() {
m.clearedownedLevels = true
}
// OwnedLevelsCleared reports if the "ownedLevels" edge to the Level entity was cleared.
func (m *UserMutation) OwnedLevelsCleared() bool {
return m.clearedownedLevels
}
// RemoveOwnedLevelIDs removes the "ownedLevels" edge to the Level entity by IDs.
func (m *UserMutation) RemoveOwnedLevelIDs(ids ...int) {
if m.removedownedLevels == nil {
m.removedownedLevels = make(map[int]struct{})
}
for i := range ids {
delete(m.ownedLevels, ids[i])
m.removedownedLevels[ids[i]] = struct{}{}
}
}
// RemovedOwnedLevels returns the removed IDs of the "ownedLevels" edge to the Level entity.
func (m *UserMutation) RemovedOwnedLevelsIDs() (ids []int) {
for id := range m.removedownedLevels {
ids = append(ids, id)
}
return
}
// OwnedLevelsIDs returns the "ownedLevels" edge IDs in the mutation.
func (m *UserMutation) OwnedLevelsIDs() (ids []int) {
for id := range m.ownedLevels {
ids = append(ids, id)
}
return
}
// ResetOwnedLevels resets all changes to the "ownedLevels" edge.
func (m *UserMutation) ResetOwnedLevels() {
m.ownedLevels = nil
m.clearedownedLevels = false
m.removedownedLevels = nil
}
// AddInvitedToLevelIDs adds the "invitedToLevels" edge to the Level entity by ids.
func (m *UserMutation) AddInvitedToLevelIDs(ids ...int) {
if m.invitedToLevels == nil {
m.invitedToLevels = make(map[int]struct{})
}
for i := range ids {
m.invitedToLevels[ids[i]] = struct{}{}
}
}
// ClearInvitedToLevels clears the "invitedToLevels" edge to the Level entity.
func (m *UserMutation) ClearInvitedToLevels() {
m.clearedinvitedToLevels = true
}
// InvitedToLevelsCleared reports if the "invitedToLevels" edge to the Level entity was cleared.
func (m *UserMutation) InvitedToLevelsCleared() bool {
return m.clearedinvitedToLevels
}
// RemoveInvitedToLevelIDs removes the "invitedToLevels" edge to the Level entity by IDs.
func (m *UserMutation) RemoveInvitedToLevelIDs(ids ...int) {
if m.removedinvitedToLevels == nil {
m.removedinvitedToLevels = make(map[int]struct{})
}
for i := range ids {
delete(m.invitedToLevels, ids[i])
m.removedinvitedToLevels[ids[i]] = struct{}{}
}
}
// RemovedInvitedToLevels returns the removed IDs of the "invitedToLevels" edge to the Level entity.
func (m *UserMutation) RemovedInvitedToLevelsIDs() (ids []int) {
for id := range m.removedinvitedToLevels {
ids = append(ids, id)
}
return
}
// InvitedToLevelsIDs returns the "invitedToLevels" edge IDs in the mutation.
func (m *UserMutation) InvitedToLevelsIDs() (ids []int) {
for id := range m.invitedToLevels {
ids = append(ids, id)
}
return
}
// ResetInvitedToLevels resets all changes to the "invitedToLevels" edge.
func (m *UserMutation) ResetInvitedToLevels() {
m.invitedToLevels = nil
m.clearedinvitedToLevels = false
m.removedinvitedToLevels = nil
}
// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.User, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (User).
func (m *UserMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 2)
if m.username != nil {
fields = append(fields, user.FieldUsername)
}
if m.password != nil {
fields = append(fields, user.FieldPassword)
}
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.FieldUsername:
return m.Username()
case user.FieldPassword:
return m.Password()
}
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.FieldUsername:
return m.OldUsername(ctx)
case user.FieldPassword:
return m.OldPassword(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.FieldUsername:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsername(v)
return nil
case user.FieldPassword:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
}
return fmt.Errorf("unknown User field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMutation) AddedFields() []string {
return nil
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown User numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
return fmt.Errorf("unknown User nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error {
switch name {
case user.FieldUsername:
m.ResetUsername()
return nil
case user.FieldPassword:
m.ResetPassword()
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.ownedLevels != nil {
edges = append(edges, user.EdgeOwnedLevels)
}
if m.invitedToLevels != nil {
edges = append(edges, user.EdgeInvitedToLevels)
}
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.EdgeOwnedLevels:
ids := make([]ent.Value, 0, len(m.ownedLevels))
for id := range m.ownedLevels {
ids = append(ids, id)
}
return ids
case user.EdgeInvitedToLevels:
ids := make([]ent.Value, 0, len(m.invitedToLevels))
for id := range m.invitedToLevels {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
if m.removedownedLevels != nil {
edges = append(edges, user.EdgeOwnedLevels)
}
if m.removedinvitedToLevels != nil {
edges = append(edges, user.EdgeInvitedToLevels)
}
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.EdgeOwnedLevels:
ids := make([]ent.Value, 0, len(m.removedownedLevels))
for id := range m.removedownedLevels {
ids = append(ids, id)
}
return ids
case user.EdgeInvitedToLevels:
ids := make([]ent.Value, 0, len(m.removedinvitedToLevels))
for id := range m.removedinvitedToLevels {
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.clearedownedLevels {
edges = append(edges, user.EdgeOwnedLevels)
}
if m.clearedinvitedToLevels {
edges = append(edges, user.EdgeInvitedToLevels)
}
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.EdgeOwnedLevels:
return m.clearedownedLevels
case user.EdgeInvitedToLevels:
return m.clearedinvitedToLevels
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *UserMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown User unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *UserMutation) ResetEdge(name string) error {
switch name {
case user.EdgeOwnedLevels:
m.ResetOwnedLevels()
return nil
case user.EdgeInvitedToLevels:
m.ResetInvitedToLevels()
return nil
}
return fmt.Errorf("unknown User edge %s", name)
}