mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
2367 lines
61 KiB
Go
2367 lines
61 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"github.com/facebookincubator/ent/entc/integration/customid/ent/blob"
|
|
"github.com/facebookincubator/ent/entc/integration/customid/ent/car"
|
|
"github.com/facebookincubator/ent/entc/integration/customid/ent/group"
|
|
"github.com/facebookincubator/ent/entc/integration/customid/ent/pet"
|
|
"github.com/facebookincubator/ent/entc/integration/customid/ent/user"
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/facebookincubator/ent"
|
|
)
|
|
|
|
const (
|
|
// Operation types.
|
|
OpCreate = ent.OpCreate
|
|
OpDelete = ent.OpDelete
|
|
OpDeleteOne = ent.OpDeleteOne
|
|
OpUpdate = ent.OpUpdate
|
|
OpUpdateOne = ent.OpUpdateOne
|
|
|
|
// Node types.
|
|
TypeBlob = "Blob"
|
|
TypeCar = "Car"
|
|
TypeGroup = "Group"
|
|
TypePet = "Pet"
|
|
TypeUser = "User"
|
|
)
|
|
|
|
// BlobMutation represents an operation that mutate the Blobs
|
|
// nodes in the graph.
|
|
type BlobMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *uuid.UUID
|
|
uuid *uuid.UUID
|
|
clearedFields map[string]struct{}
|
|
parent *uuid.UUID
|
|
clearedparent bool
|
|
links map[uuid.UUID]struct{}
|
|
removedlinks map[uuid.UUID]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*Blob, error)
|
|
}
|
|
|
|
var _ ent.Mutation = (*BlobMutation)(nil)
|
|
|
|
// blobOption allows to manage the mutation configuration using functional options.
|
|
type blobOption func(*BlobMutation)
|
|
|
|
// newBlobMutation creates new mutation for $n.Name.
|
|
func newBlobMutation(c config, op Op, opts ...blobOption) *BlobMutation {
|
|
m := &BlobMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeBlob,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withBlobID sets the id field of the mutation.
|
|
func withBlobID(id uuid.UUID) blobOption {
|
|
return func(m *BlobMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Blob
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Blob, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = fmt.Errorf("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Blob.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withBlob sets the old Blob of the mutation.
|
|
func withBlob(node *Blob) blobOption {
|
|
return func(m *BlobMutation) {
|
|
m.oldValue = func(context.Context) (*Blob, 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 BlobMutation) 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 BlobMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// SetID sets the value of the id field. Note that, this
|
|
// operation is accepted only on Blob creation.
|
|
func (m *BlobMutation) SetID(id uuid.UUID) {
|
|
m.id = &id
|
|
}
|
|
|
|
// ID returns the id value in the mutation. Note that, the id
|
|
// is available only if it was provided to the builder.
|
|
func (m *BlobMutation) ID() (id uuid.UUID, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// SetUUID sets the uuid field.
|
|
func (m *BlobMutation) SetUUID(u uuid.UUID) {
|
|
m.uuid = &u
|
|
}
|
|
|
|
// UUID returns the uuid value in the mutation.
|
|
func (m *BlobMutation) UUID() (r uuid.UUID, exists bool) {
|
|
v := m.uuid
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldUUID returns the old uuid value of the Blob.
|
|
// If the Blob 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 database query fails.
|
|
func (m *BlobMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, fmt.Errorf("OldUUID is allowed only on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, fmt.Errorf("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 reset all changes of the "uuid" field.
|
|
func (m *BlobMutation) ResetUUID() {
|
|
m.uuid = nil
|
|
}
|
|
|
|
// SetParentID sets the parent edge to Blob by id.
|
|
func (m *BlobMutation) SetParentID(id uuid.UUID) {
|
|
m.parent = &id
|
|
}
|
|
|
|
// ClearParent clears the parent edge to Blob.
|
|
func (m *BlobMutation) ClearParent() {
|
|
m.clearedparent = true
|
|
}
|
|
|
|
// ParentCleared returns if the edge parent was cleared.
|
|
func (m *BlobMutation) ParentCleared() bool {
|
|
return m.clearedparent
|
|
}
|
|
|
|
// ParentID returns the parent id in the mutation.
|
|
func (m *BlobMutation) ParentID() (id uuid.UUID, exists bool) {
|
|
if m.parent != nil {
|
|
return *m.parent, true
|
|
}
|
|
return
|
|
}
|
|
|
|
// ParentIDs returns the parent ids in the mutation.
|
|
// Note that ids always returns len(ids) <= 1 for unique edges, and you should use
|
|
// ParentID instead. It exists only for internal usage by the builders.
|
|
func (m *BlobMutation) ParentIDs() (ids []uuid.UUID) {
|
|
if id := m.parent; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetParent reset all changes of the "parent" edge.
|
|
func (m *BlobMutation) ResetParent() {
|
|
m.parent = nil
|
|
m.clearedparent = false
|
|
}
|
|
|
|
// AddLinkIDs adds the links edge to Blob by ids.
|
|
func (m *BlobMutation) AddLinkIDs(ids ...uuid.UUID) {
|
|
if m.links == nil {
|
|
m.links = make(map[uuid.UUID]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.links[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemoveLinkIDs removes the links edge to Blob by ids.
|
|
func (m *BlobMutation) RemoveLinkIDs(ids ...uuid.UUID) {
|
|
if m.removedlinks == nil {
|
|
m.removedlinks = make(map[uuid.UUID]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedlinks[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedLinks returns the removed ids of links.
|
|
func (m *BlobMutation) RemovedLinksIDs() (ids []uuid.UUID) {
|
|
for id := range m.removedlinks {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// LinksIDs returns the links ids in the mutation.
|
|
func (m *BlobMutation) LinksIDs() (ids []uuid.UUID) {
|
|
for id := range m.links {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetLinks reset all changes of the "links" edge.
|
|
func (m *BlobMutation) ResetLinks() {
|
|
m.links = nil
|
|
m.removedlinks = nil
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *BlobMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Blob).
|
|
func (m *BlobMutation) 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 in/decremented, call AddedFields().
|
|
func (m *BlobMutation) Fields() []string {
|
|
fields := make([]string, 0, 1)
|
|
if m.uuid != nil {
|
|
fields = append(fields, blob.FieldUUID)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name.
|
|
// The second boolean value indicates that this field was
|
|
// not set, or was not define in the schema.
|
|
func (m *BlobMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case blob.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 was failed.
|
|
func (m *BlobMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case blob.FieldUUID:
|
|
return m.OldUUID(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Blob field %s", name)
|
|
}
|
|
|
|
// SetField sets the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *BlobMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case blob.FieldUUID:
|
|
v, ok := value.(uuid.UUID)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetUUID(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blob field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented
|
|
// or decremented during this mutation.
|
|
func (m *BlobMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was in/decremented
|
|
// from a field with the given name. The second value indicates
|
|
// that this field was not set, or was not define in the schema.
|
|
func (m *BlobMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *BlobMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Blob numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared
|
|
// during this mutation.
|
|
func (m *BlobMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicates if this field was
|
|
// cleared in this mutation.
|
|
func (m *BlobMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value for the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *BlobMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Blob nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation regarding the
|
|
// given field name. It returns an error if the field is not
|
|
// defined in the schema.
|
|
func (m *BlobMutation) ResetField(name string) error {
|
|
switch name {
|
|
case blob.FieldUUID:
|
|
m.ResetUUID()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blob field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this
|
|
// mutation.
|
|
func (m *BlobMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.parent != nil {
|
|
edges = append(edges, blob.EdgeParent)
|
|
}
|
|
if m.links != nil {
|
|
edges = append(edges, blob.EdgeLinks)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all ids (to other nodes) that were added for
|
|
// the given edge name.
|
|
func (m *BlobMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case blob.EdgeParent:
|
|
if id := m.parent; id != nil {
|
|
return []ent.Value{*id}
|
|
}
|
|
case blob.EdgeLinks:
|
|
ids := make([]ent.Value, 0, len(m.links))
|
|
for id := range m.links {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this
|
|
// mutation.
|
|
func (m *BlobMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.removedlinks != nil {
|
|
edges = append(edges, blob.EdgeLinks)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all ids (to other nodes) that were removed for
|
|
// the given edge name.
|
|
func (m *BlobMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case blob.EdgeLinks:
|
|
ids := make([]ent.Value, 0, len(m.removedlinks))
|
|
for id := range m.removedlinks {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this
|
|
// mutation.
|
|
func (m *BlobMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.clearedparent {
|
|
edges = append(edges, blob.EdgeParent)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean indicates if this edge was
|
|
// cleared in this mutation.
|
|
func (m *BlobMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case blob.EdgeParent:
|
|
return m.clearedparent
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value for the given name. It returns an
|
|
// error if the edge name is not defined in the schema.
|
|
func (m *BlobMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
case blob.EdgeParent:
|
|
m.ClearParent()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blob unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes in the mutation regarding the
|
|
// given edge name. It returns an error if the edge is not
|
|
// defined in the schema.
|
|
func (m *BlobMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case blob.EdgeParent:
|
|
m.ResetParent()
|
|
return nil
|
|
case blob.EdgeLinks:
|
|
m.ResetLinks()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blob edge %s", name)
|
|
}
|
|
|
|
// CarMutation represents an operation that mutate the Cars
|
|
// nodes in the graph.
|
|
type CarMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
before_id *float64
|
|
addbefore_id *float64
|
|
after_id *float64
|
|
addafter_id *float64
|
|
model *string
|
|
clearedFields map[string]struct{}
|
|
owner *string
|
|
clearedowner bool
|
|
done bool
|
|
oldValue func(context.Context) (*Car, error)
|
|
}
|
|
|
|
var _ ent.Mutation = (*CarMutation)(nil)
|
|
|
|
// carOption allows to manage the mutation configuration using functional options.
|
|
type carOption func(*CarMutation)
|
|
|
|
// newCarMutation creates new mutation for $n.Name.
|
|
func newCarMutation(c config, op Op, opts ...carOption) *CarMutation {
|
|
m := &CarMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeCar,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withCarID sets the id field of the mutation.
|
|
func withCarID(id int) carOption {
|
|
return func(m *CarMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Car
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Car, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = fmt.Errorf("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Car.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withCar sets the old Car of the mutation.
|
|
func withCar(node *Car) carOption {
|
|
return func(m *CarMutation) {
|
|
m.oldValue = func(context.Context) (*Car, 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 CarMutation) 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 CarMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// SetID sets the value of the id field. Note that, this
|
|
// operation is accepted only on Car creation.
|
|
func (m *CarMutation) SetID(id int) {
|
|
m.id = &id
|
|
}
|
|
|
|
// ID returns the id value in the mutation. Note that, the id
|
|
// is available only if it was provided to the builder.
|
|
func (m *CarMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// SetBeforeID sets the before_id field.
|
|
func (m *CarMutation) SetBeforeID(f float64) {
|
|
m.before_id = &f
|
|
m.addbefore_id = nil
|
|
}
|
|
|
|
// BeforeID returns the before_id value in the mutation.
|
|
func (m *CarMutation) BeforeID() (r float64, exists bool) {
|
|
v := m.before_id
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldBeforeID returns the old before_id value of the Car.
|
|
// If the Car 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 database query fails.
|
|
func (m *CarMutation) OldBeforeID(ctx context.Context) (v float64, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, fmt.Errorf("OldBeforeID is allowed only on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, fmt.Errorf("OldBeforeID requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldBeforeID: %w", err)
|
|
}
|
|
return oldValue.BeforeID, nil
|
|
}
|
|
|
|
// AddBeforeID adds f to before_id.
|
|
func (m *CarMutation) AddBeforeID(f float64) {
|
|
if m.addbefore_id != nil {
|
|
*m.addbefore_id += f
|
|
} else {
|
|
m.addbefore_id = &f
|
|
}
|
|
}
|
|
|
|
// AddedBeforeID returns the value that was added to the before_id field in this mutation.
|
|
func (m *CarMutation) AddedBeforeID() (r float64, exists bool) {
|
|
v := m.addbefore_id
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ClearBeforeID clears the value of before_id.
|
|
func (m *CarMutation) ClearBeforeID() {
|
|
m.before_id = nil
|
|
m.addbefore_id = nil
|
|
m.clearedFields[car.FieldBeforeID] = struct{}{}
|
|
}
|
|
|
|
// BeforeIDCleared returns if the field before_id was cleared in this mutation.
|
|
func (m *CarMutation) BeforeIDCleared() bool {
|
|
_, ok := m.clearedFields[car.FieldBeforeID]
|
|
return ok
|
|
}
|
|
|
|
// ResetBeforeID reset all changes of the "before_id" field.
|
|
func (m *CarMutation) ResetBeforeID() {
|
|
m.before_id = nil
|
|
m.addbefore_id = nil
|
|
delete(m.clearedFields, car.FieldBeforeID)
|
|
}
|
|
|
|
// SetAfterID sets the after_id field.
|
|
func (m *CarMutation) SetAfterID(f float64) {
|
|
m.after_id = &f
|
|
m.addafter_id = nil
|
|
}
|
|
|
|
// AfterID returns the after_id value in the mutation.
|
|
func (m *CarMutation) AfterID() (r float64, exists bool) {
|
|
v := m.after_id
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldAfterID returns the old after_id value of the Car.
|
|
// If the Car 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 database query fails.
|
|
func (m *CarMutation) OldAfterID(ctx context.Context) (v float64, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, fmt.Errorf("OldAfterID is allowed only on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, fmt.Errorf("OldAfterID requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldAfterID: %w", err)
|
|
}
|
|
return oldValue.AfterID, nil
|
|
}
|
|
|
|
// AddAfterID adds f to after_id.
|
|
func (m *CarMutation) AddAfterID(f float64) {
|
|
if m.addafter_id != nil {
|
|
*m.addafter_id += f
|
|
} else {
|
|
m.addafter_id = &f
|
|
}
|
|
}
|
|
|
|
// AddedAfterID returns the value that was added to the after_id field in this mutation.
|
|
func (m *CarMutation) AddedAfterID() (r float64, exists bool) {
|
|
v := m.addafter_id
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ClearAfterID clears the value of after_id.
|
|
func (m *CarMutation) ClearAfterID() {
|
|
m.after_id = nil
|
|
m.addafter_id = nil
|
|
m.clearedFields[car.FieldAfterID] = struct{}{}
|
|
}
|
|
|
|
// AfterIDCleared returns if the field after_id was cleared in this mutation.
|
|
func (m *CarMutation) AfterIDCleared() bool {
|
|
_, ok := m.clearedFields[car.FieldAfterID]
|
|
return ok
|
|
}
|
|
|
|
// ResetAfterID reset all changes of the "after_id" field.
|
|
func (m *CarMutation) ResetAfterID() {
|
|
m.after_id = nil
|
|
m.addafter_id = nil
|
|
delete(m.clearedFields, car.FieldAfterID)
|
|
}
|
|
|
|
// SetModel sets the model field.
|
|
func (m *CarMutation) SetModel(s string) {
|
|
m.model = &s
|
|
}
|
|
|
|
// Model returns the model value in the mutation.
|
|
func (m *CarMutation) Model() (r string, exists bool) {
|
|
v := m.model
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldModel returns the old model value of the Car.
|
|
// If the Car 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 database query fails.
|
|
func (m *CarMutation) OldModel(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, fmt.Errorf("OldModel is allowed only on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, fmt.Errorf("OldModel requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldModel: %w", err)
|
|
}
|
|
return oldValue.Model, nil
|
|
}
|
|
|
|
// ResetModel reset all changes of the "model" field.
|
|
func (m *CarMutation) ResetModel() {
|
|
m.model = nil
|
|
}
|
|
|
|
// SetOwnerID sets the owner edge to Pet by id.
|
|
func (m *CarMutation) SetOwnerID(id string) {
|
|
m.owner = &id
|
|
}
|
|
|
|
// ClearOwner clears the owner edge to Pet.
|
|
func (m *CarMutation) ClearOwner() {
|
|
m.clearedowner = true
|
|
}
|
|
|
|
// OwnerCleared returns if the edge owner was cleared.
|
|
func (m *CarMutation) OwnerCleared() bool {
|
|
return m.clearedowner
|
|
}
|
|
|
|
// OwnerID returns the owner id in the mutation.
|
|
func (m *CarMutation) OwnerID() (id string, exists bool) {
|
|
if m.owner != nil {
|
|
return *m.owner, true
|
|
}
|
|
return
|
|
}
|
|
|
|
// OwnerIDs returns the owner 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 *CarMutation) OwnerIDs() (ids []string) {
|
|
if id := m.owner; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetOwner reset all changes of the "owner" edge.
|
|
func (m *CarMutation) ResetOwner() {
|
|
m.owner = nil
|
|
m.clearedowner = false
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *CarMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Car).
|
|
func (m *CarMutation) 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 in/decremented, call AddedFields().
|
|
func (m *CarMutation) Fields() []string {
|
|
fields := make([]string, 0, 3)
|
|
if m.before_id != nil {
|
|
fields = append(fields, car.FieldBeforeID)
|
|
}
|
|
if m.after_id != nil {
|
|
fields = append(fields, car.FieldAfterID)
|
|
}
|
|
if m.model != nil {
|
|
fields = append(fields, car.FieldModel)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name.
|
|
// The second boolean value indicates that this field was
|
|
// not set, or was not define in the schema.
|
|
func (m *CarMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
return m.BeforeID()
|
|
case car.FieldAfterID:
|
|
return m.AfterID()
|
|
case car.FieldModel:
|
|
return m.Model()
|
|
}
|
|
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 was failed.
|
|
func (m *CarMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
return m.OldBeforeID(ctx)
|
|
case car.FieldAfterID:
|
|
return m.OldAfterID(ctx)
|
|
case car.FieldModel:
|
|
return m.OldModel(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Car field %s", name)
|
|
}
|
|
|
|
// SetField sets the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *CarMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetBeforeID(v)
|
|
return nil
|
|
case car.FieldAfterID:
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetAfterID(v)
|
|
return nil
|
|
case car.FieldModel:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetModel(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Car field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented
|
|
// or decremented during this mutation.
|
|
func (m *CarMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.addbefore_id != nil {
|
|
fields = append(fields, car.FieldBeforeID)
|
|
}
|
|
if m.addafter_id != nil {
|
|
fields = append(fields, car.FieldAfterID)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// AddedField returns the numeric value that was in/decremented
|
|
// from a field with the given name. The second value indicates
|
|
// that this field was not set, or was not define in the schema.
|
|
func (m *CarMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
return m.AddedBeforeID()
|
|
case car.FieldAfterID:
|
|
return m.AddedAfterID()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *CarMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddBeforeID(v)
|
|
return nil
|
|
case car.FieldAfterID:
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddAfterID(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Car numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared
|
|
// during this mutation.
|
|
func (m *CarMutation) ClearedFields() []string {
|
|
var fields []string
|
|
if m.FieldCleared(car.FieldBeforeID) {
|
|
fields = append(fields, car.FieldBeforeID)
|
|
}
|
|
if m.FieldCleared(car.FieldAfterID) {
|
|
fields = append(fields, car.FieldAfterID)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicates if this field was
|
|
// cleared in this mutation.
|
|
func (m *CarMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value for the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *CarMutation) ClearField(name string) error {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
m.ClearBeforeID()
|
|
return nil
|
|
case car.FieldAfterID:
|
|
m.ClearAfterID()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Car nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation regarding the
|
|
// given field name. It returns an error if the field is not
|
|
// defined in the schema.
|
|
func (m *CarMutation) ResetField(name string) error {
|
|
switch name {
|
|
case car.FieldBeforeID:
|
|
m.ResetBeforeID()
|
|
return nil
|
|
case car.FieldAfterID:
|
|
m.ResetAfterID()
|
|
return nil
|
|
case car.FieldModel:
|
|
m.ResetModel()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Car field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this
|
|
// mutation.
|
|
func (m *CarMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.owner != nil {
|
|
edges = append(edges, car.EdgeOwner)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all ids (to other nodes) that were added for
|
|
// the given edge name.
|
|
func (m *CarMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case car.EdgeOwner:
|
|
if id := m.owner; id != nil {
|
|
return []ent.Value{*id}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this
|
|
// mutation.
|
|
func (m *CarMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all ids (to other nodes) that were removed for
|
|
// the given edge name.
|
|
func (m *CarMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this
|
|
// mutation.
|
|
func (m *CarMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.clearedowner {
|
|
edges = append(edges, car.EdgeOwner)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean indicates if this edge was
|
|
// cleared in this mutation.
|
|
func (m *CarMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case car.EdgeOwner:
|
|
return m.clearedowner
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value for the given name. It returns an
|
|
// error if the edge name is not defined in the schema.
|
|
func (m *CarMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
case car.EdgeOwner:
|
|
m.ClearOwner()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Car unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes in the mutation regarding the
|
|
// given edge name. It returns an error if the edge is not
|
|
// defined in the schema.
|
|
func (m *CarMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case car.EdgeOwner:
|
|
m.ResetOwner()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Car edge %s", name)
|
|
}
|
|
|
|
// GroupMutation represents an operation that mutate the Groups
|
|
// nodes in the graph.
|
|
type GroupMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
clearedFields map[string]struct{}
|
|
users map[int]struct{}
|
|
removedusers map[int]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*Group, error)
|
|
}
|
|
|
|
var _ ent.Mutation = (*GroupMutation)(nil)
|
|
|
|
// groupOption allows to manage the mutation configuration using functional options.
|
|
type groupOption func(*GroupMutation)
|
|
|
|
// newGroupMutation creates new mutation for $n.Name.
|
|
func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation {
|
|
m := &GroupMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeGroup,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withGroupID sets the id field of the mutation.
|
|
func withGroupID(id int) groupOption {
|
|
return func(m *GroupMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Group
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Group, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = fmt.Errorf("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Group.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withGroup sets the old Group of the mutation.
|
|
func withGroup(node *Group) groupOption {
|
|
return func(m *GroupMutation) {
|
|
m.oldValue = func(context.Context) (*Group, 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 GroupMutation) 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 GroupMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// SetID sets the value of the id field. Note that, this
|
|
// operation is accepted only on Group creation.
|
|
func (m *GroupMutation) SetID(id int) {
|
|
m.id = &id
|
|
}
|
|
|
|
// ID returns the id value in the mutation. Note that, the id
|
|
// is available only if it was provided to the builder.
|
|
func (m *GroupMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// AddUserIDs adds the users edge to User by ids.
|
|
func (m *GroupMutation) AddUserIDs(ids ...int) {
|
|
if m.users == nil {
|
|
m.users = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.users[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemoveUserIDs removes the users edge to User by ids.
|
|
func (m *GroupMutation) RemoveUserIDs(ids ...int) {
|
|
if m.removedusers == nil {
|
|
m.removedusers = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedusers[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedUsers returns the removed ids of users.
|
|
func (m *GroupMutation) RemovedUsersIDs() (ids []int) {
|
|
for id := range m.removedusers {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// UsersIDs returns the users ids in the mutation.
|
|
func (m *GroupMutation) UsersIDs() (ids []int) {
|
|
for id := range m.users {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetUsers reset all changes of the "users" edge.
|
|
func (m *GroupMutation) ResetUsers() {
|
|
m.users = nil
|
|
m.removedusers = nil
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *GroupMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Group).
|
|
func (m *GroupMutation) 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 in/decremented, call AddedFields().
|
|
func (m *GroupMutation) Fields() []string {
|
|
fields := make([]string, 0, 0)
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name.
|
|
// The second boolean value indicates that this field was
|
|
// not set, or was not define in the schema.
|
|
func (m *GroupMutation) Field(name string) (ent.Value, bool) {
|
|
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 was failed.
|
|
func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
return nil, fmt.Errorf("unknown Group field %s", name)
|
|
}
|
|
|
|
// SetField sets the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *GroupMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Group field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented
|
|
// or decremented during this mutation.
|
|
func (m *GroupMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was in/decremented
|
|
// from a field with the given name. The second value indicates
|
|
// that this field was not set, or was not define in the schema.
|
|
func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *GroupMutation) AddField(name string, value ent.Value) error {
|
|
return fmt.Errorf("unknown Group numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared
|
|
// during this mutation.
|
|
func (m *GroupMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicates if this field was
|
|
// cleared in this mutation.
|
|
func (m *GroupMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value for the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *GroupMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Group nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation regarding the
|
|
// given field name. It returns an error if the field is not
|
|
// defined in the schema.
|
|
func (m *GroupMutation) ResetField(name string) error {
|
|
return fmt.Errorf("unknown Group field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this
|
|
// mutation.
|
|
func (m *GroupMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.users != nil {
|
|
edges = append(edges, group.EdgeUsers)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all ids (to other nodes) that were added for
|
|
// the given edge name.
|
|
func (m *GroupMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case group.EdgeUsers:
|
|
ids := make([]ent.Value, 0, len(m.users))
|
|
for id := range m.users {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this
|
|
// mutation.
|
|
func (m *GroupMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.removedusers != nil {
|
|
edges = append(edges, group.EdgeUsers)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all ids (to other nodes) that were removed for
|
|
// the given edge name.
|
|
func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case group.EdgeUsers:
|
|
ids := make([]ent.Value, 0, len(m.removedusers))
|
|
for id := range m.removedusers {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this
|
|
// mutation.
|
|
func (m *GroupMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean indicates if this edge was
|
|
// cleared in this mutation.
|
|
func (m *GroupMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value for the given name. It returns an
|
|
// error if the edge name is not defined in the schema.
|
|
func (m *GroupMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Group unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes in the mutation regarding the
|
|
// given edge name. It returns an error if the edge is not
|
|
// defined in the schema.
|
|
func (m *GroupMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case group.EdgeUsers:
|
|
m.ResetUsers()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Group edge %s", name)
|
|
}
|
|
|
|
// PetMutation represents an operation that mutate the Pets
|
|
// nodes in the graph.
|
|
type PetMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *string
|
|
clearedFields map[string]struct{}
|
|
owner *int
|
|
clearedowner bool
|
|
cars map[int]struct{}
|
|
removedcars map[int]struct{}
|
|
friends map[string]struct{}
|
|
removedfriends map[string]struct{}
|
|
best_friend *string
|
|
clearedbest_friend bool
|
|
done bool
|
|
oldValue func(context.Context) (*Pet, error)
|
|
}
|
|
|
|
var _ ent.Mutation = (*PetMutation)(nil)
|
|
|
|
// petOption allows to manage the mutation configuration using functional options.
|
|
type petOption func(*PetMutation)
|
|
|
|
// newPetMutation creates new mutation for $n.Name.
|
|
func newPetMutation(c config, op Op, opts ...petOption) *PetMutation {
|
|
m := &PetMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypePet,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withPetID sets the id field of the mutation.
|
|
func withPetID(id string) petOption {
|
|
return func(m *PetMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Pet
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Pet, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = fmt.Errorf("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Pet.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withPet sets the old Pet of the mutation.
|
|
func withPet(node *Pet) petOption {
|
|
return func(m *PetMutation) {
|
|
m.oldValue = func(context.Context) (*Pet, 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 PetMutation) 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 PetMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// SetID sets the value of the id field. Note that, this
|
|
// operation is accepted only on Pet creation.
|
|
func (m *PetMutation) SetID(id string) {
|
|
m.id = &id
|
|
}
|
|
|
|
// ID returns the id value in the mutation. Note that, the id
|
|
// is available only if it was provided to the builder.
|
|
func (m *PetMutation) ID() (id string, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// SetOwnerID sets the owner edge to User by id.
|
|
func (m *PetMutation) SetOwnerID(id int) {
|
|
m.owner = &id
|
|
}
|
|
|
|
// ClearOwner clears the owner edge to User.
|
|
func (m *PetMutation) ClearOwner() {
|
|
m.clearedowner = true
|
|
}
|
|
|
|
// OwnerCleared returns if the edge owner was cleared.
|
|
func (m *PetMutation) OwnerCleared() bool {
|
|
return m.clearedowner
|
|
}
|
|
|
|
// OwnerID returns the owner id in the mutation.
|
|
func (m *PetMutation) OwnerID() (id int, exists bool) {
|
|
if m.owner != nil {
|
|
return *m.owner, true
|
|
}
|
|
return
|
|
}
|
|
|
|
// OwnerIDs returns the owner 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 *PetMutation) OwnerIDs() (ids []int) {
|
|
if id := m.owner; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetOwner reset all changes of the "owner" edge.
|
|
func (m *PetMutation) ResetOwner() {
|
|
m.owner = nil
|
|
m.clearedowner = false
|
|
}
|
|
|
|
// AddCarIDs adds the cars edge to Car by ids.
|
|
func (m *PetMutation) AddCarIDs(ids ...int) {
|
|
if m.cars == nil {
|
|
m.cars = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.cars[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemoveCarIDs removes the cars edge to Car by ids.
|
|
func (m *PetMutation) RemoveCarIDs(ids ...int) {
|
|
if m.removedcars == nil {
|
|
m.removedcars = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedcars[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedCars returns the removed ids of cars.
|
|
func (m *PetMutation) RemovedCarsIDs() (ids []int) {
|
|
for id := range m.removedcars {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// CarsIDs returns the cars ids in the mutation.
|
|
func (m *PetMutation) CarsIDs() (ids []int) {
|
|
for id := range m.cars {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetCars reset all changes of the "cars" edge.
|
|
func (m *PetMutation) ResetCars() {
|
|
m.cars = nil
|
|
m.removedcars = nil
|
|
}
|
|
|
|
// AddFriendIDs adds the friends edge to Pet by ids.
|
|
func (m *PetMutation) AddFriendIDs(ids ...string) {
|
|
if m.friends == nil {
|
|
m.friends = make(map[string]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.friends[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemoveFriendIDs removes the friends edge to Pet by ids.
|
|
func (m *PetMutation) RemoveFriendIDs(ids ...string) {
|
|
if m.removedfriends == nil {
|
|
m.removedfriends = make(map[string]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedfriends[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedFriends returns the removed ids of friends.
|
|
func (m *PetMutation) RemovedFriendsIDs() (ids []string) {
|
|
for id := range m.removedfriends {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// FriendsIDs returns the friends ids in the mutation.
|
|
func (m *PetMutation) FriendsIDs() (ids []string) {
|
|
for id := range m.friends {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetFriends reset all changes of the "friends" edge.
|
|
func (m *PetMutation) ResetFriends() {
|
|
m.friends = nil
|
|
m.removedfriends = nil
|
|
}
|
|
|
|
// SetBestFriendID sets the best_friend edge to Pet by id.
|
|
func (m *PetMutation) SetBestFriendID(id string) {
|
|
m.best_friend = &id
|
|
}
|
|
|
|
// ClearBestFriend clears the best_friend edge to Pet.
|
|
func (m *PetMutation) ClearBestFriend() {
|
|
m.clearedbest_friend = true
|
|
}
|
|
|
|
// BestFriendCleared returns if the edge best_friend was cleared.
|
|
func (m *PetMutation) BestFriendCleared() bool {
|
|
return m.clearedbest_friend
|
|
}
|
|
|
|
// BestFriendID returns the best_friend id in the mutation.
|
|
func (m *PetMutation) BestFriendID() (id string, exists bool) {
|
|
if m.best_friend != nil {
|
|
return *m.best_friend, true
|
|
}
|
|
return
|
|
}
|
|
|
|
// BestFriendIDs returns the best_friend ids in the mutation.
|
|
// Note that ids always returns len(ids) <= 1 for unique edges, and you should use
|
|
// BestFriendID instead. It exists only for internal usage by the builders.
|
|
func (m *PetMutation) BestFriendIDs() (ids []string) {
|
|
if id := m.best_friend; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetBestFriend reset all changes of the "best_friend" edge.
|
|
func (m *PetMutation) ResetBestFriend() {
|
|
m.best_friend = nil
|
|
m.clearedbest_friend = false
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *PetMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Pet).
|
|
func (m *PetMutation) 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 in/decremented, call AddedFields().
|
|
func (m *PetMutation) Fields() []string {
|
|
fields := make([]string, 0, 0)
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name.
|
|
// The second boolean value indicates that this field was
|
|
// not set, or was not define in the schema.
|
|
func (m *PetMutation) Field(name string) (ent.Value, bool) {
|
|
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 was failed.
|
|
func (m *PetMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
return nil, fmt.Errorf("unknown Pet field %s", name)
|
|
}
|
|
|
|
// SetField sets the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *PetMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Pet field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented
|
|
// or decremented during this mutation.
|
|
func (m *PetMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was in/decremented
|
|
// from a field with the given name. The second value indicates
|
|
// that this field was not set, or was not define in the schema.
|
|
func (m *PetMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *PetMutation) AddField(name string, value ent.Value) error {
|
|
return fmt.Errorf("unknown Pet numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared
|
|
// during this mutation.
|
|
func (m *PetMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicates if this field was
|
|
// cleared in this mutation.
|
|
func (m *PetMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value for the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *PetMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Pet nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation regarding the
|
|
// given field name. It returns an error if the field is not
|
|
// defined in the schema.
|
|
func (m *PetMutation) ResetField(name string) error {
|
|
return fmt.Errorf("unknown Pet field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this
|
|
// mutation.
|
|
func (m *PetMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 4)
|
|
if m.owner != nil {
|
|
edges = append(edges, pet.EdgeOwner)
|
|
}
|
|
if m.cars != nil {
|
|
edges = append(edges, pet.EdgeCars)
|
|
}
|
|
if m.friends != nil {
|
|
edges = append(edges, pet.EdgeFriends)
|
|
}
|
|
if m.best_friend != nil {
|
|
edges = append(edges, pet.EdgeBestFriend)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all ids (to other nodes) that were added for
|
|
// the given edge name.
|
|
func (m *PetMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case pet.EdgeOwner:
|
|
if id := m.owner; id != nil {
|
|
return []ent.Value{*id}
|
|
}
|
|
case pet.EdgeCars:
|
|
ids := make([]ent.Value, 0, len(m.cars))
|
|
for id := range m.cars {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case pet.EdgeFriends:
|
|
ids := make([]ent.Value, 0, len(m.friends))
|
|
for id := range m.friends {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case pet.EdgeBestFriend:
|
|
if id := m.best_friend; id != nil {
|
|
return []ent.Value{*id}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this
|
|
// mutation.
|
|
func (m *PetMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 4)
|
|
if m.removedcars != nil {
|
|
edges = append(edges, pet.EdgeCars)
|
|
}
|
|
if m.removedfriends != nil {
|
|
edges = append(edges, pet.EdgeFriends)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all ids (to other nodes) that were removed for
|
|
// the given edge name.
|
|
func (m *PetMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case pet.EdgeCars:
|
|
ids := make([]ent.Value, 0, len(m.removedcars))
|
|
for id := range m.removedcars {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case pet.EdgeFriends:
|
|
ids := make([]ent.Value, 0, len(m.removedfriends))
|
|
for id := range m.removedfriends {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this
|
|
// mutation.
|
|
func (m *PetMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 4)
|
|
if m.clearedowner {
|
|
edges = append(edges, pet.EdgeOwner)
|
|
}
|
|
if m.clearedbest_friend {
|
|
edges = append(edges, pet.EdgeBestFriend)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean indicates if this edge was
|
|
// cleared in this mutation.
|
|
func (m *PetMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case pet.EdgeOwner:
|
|
return m.clearedowner
|
|
case pet.EdgeBestFriend:
|
|
return m.clearedbest_friend
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value for the given name. It returns an
|
|
// error if the edge name is not defined in the schema.
|
|
func (m *PetMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
case pet.EdgeOwner:
|
|
m.ClearOwner()
|
|
return nil
|
|
case pet.EdgeBestFriend:
|
|
m.ClearBestFriend()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Pet unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes in the mutation regarding the
|
|
// given edge name. It returns an error if the edge is not
|
|
// defined in the schema.
|
|
func (m *PetMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case pet.EdgeOwner:
|
|
m.ResetOwner()
|
|
return nil
|
|
case pet.EdgeCars:
|
|
m.ResetCars()
|
|
return nil
|
|
case pet.EdgeFriends:
|
|
m.ResetFriends()
|
|
return nil
|
|
case pet.EdgeBestFriend:
|
|
m.ResetBestFriend()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Pet edge %s", name)
|
|
}
|
|
|
|
// UserMutation represents an operation that mutate the Users
|
|
// nodes in the graph.
|
|
type UserMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
clearedFields map[string]struct{}
|
|
groups map[int]struct{}
|
|
removedgroups map[int]struct{}
|
|
parent *int
|
|
clearedparent bool
|
|
children map[int]struct{}
|
|
removedchildren map[int]struct{}
|
|
pets map[string]struct{}
|
|
removedpets map[string]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*User, error)
|
|
}
|
|
|
|
var _ ent.Mutation = (*UserMutation)(nil)
|
|
|
|
// userOption allows to manage the mutation configuration using functional options.
|
|
type userOption func(*UserMutation)
|
|
|
|
// newUserMutation creates new mutation for $n.Name.
|
|
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 = fmt.Errorf("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, fmt.Errorf("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// SetID sets the value of the id field. Note that, this
|
|
// operation is accepted only on User creation.
|
|
func (m *UserMutation) SetID(id int) {
|
|
m.id = &id
|
|
}
|
|
|
|
// ID returns the id value in the mutation. Note that, the id
|
|
// is available only if it was provided to the builder.
|
|
func (m *UserMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// AddGroupIDs adds the groups edge to Group by ids.
|
|
func (m *UserMutation) AddGroupIDs(ids ...int) {
|
|
if m.groups == nil {
|
|
m.groups = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.groups[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemoveGroupIDs removes the groups edge to Group by ids.
|
|
func (m *UserMutation) RemoveGroupIDs(ids ...int) {
|
|
if m.removedgroups == nil {
|
|
m.removedgroups = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedgroups[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedGroups returns the removed ids of groups.
|
|
func (m *UserMutation) RemovedGroupsIDs() (ids []int) {
|
|
for id := range m.removedgroups {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// GroupsIDs returns the groups ids in the mutation.
|
|
func (m *UserMutation) GroupsIDs() (ids []int) {
|
|
for id := range m.groups {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetGroups reset all changes of the "groups" edge.
|
|
func (m *UserMutation) ResetGroups() {
|
|
m.groups = nil
|
|
m.removedgroups = nil
|
|
}
|
|
|
|
// SetParentID sets the parent edge to User by id.
|
|
func (m *UserMutation) SetParentID(id int) {
|
|
m.parent = &id
|
|
}
|
|
|
|
// ClearParent clears the parent edge to User.
|
|
func (m *UserMutation) ClearParent() {
|
|
m.clearedparent = true
|
|
}
|
|
|
|
// ParentCleared returns if the edge parent was cleared.
|
|
func (m *UserMutation) ParentCleared() bool {
|
|
return m.clearedparent
|
|
}
|
|
|
|
// ParentID returns the parent id in the mutation.
|
|
func (m *UserMutation) ParentID() (id int, exists bool) {
|
|
if m.parent != nil {
|
|
return *m.parent, true
|
|
}
|
|
return
|
|
}
|
|
|
|
// ParentIDs returns the parent ids in the mutation.
|
|
// Note that ids always returns len(ids) <= 1 for unique edges, and you should use
|
|
// ParentID instead. It exists only for internal usage by the builders.
|
|
func (m *UserMutation) ParentIDs() (ids []int) {
|
|
if id := m.parent; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetParent reset all changes of the "parent" edge.
|
|
func (m *UserMutation) ResetParent() {
|
|
m.parent = nil
|
|
m.clearedparent = false
|
|
}
|
|
|
|
// AddChildIDs adds the children edge to User by ids.
|
|
func (m *UserMutation) AddChildIDs(ids ...int) {
|
|
if m.children == nil {
|
|
m.children = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.children[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemoveChildIDs removes the children edge to User by ids.
|
|
func (m *UserMutation) RemoveChildIDs(ids ...int) {
|
|
if m.removedchildren == nil {
|
|
m.removedchildren = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedchildren[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedChildren returns the removed ids of children.
|
|
func (m *UserMutation) RemovedChildrenIDs() (ids []int) {
|
|
for id := range m.removedchildren {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ChildrenIDs returns the children ids in the mutation.
|
|
func (m *UserMutation) ChildrenIDs() (ids []int) {
|
|
for id := range m.children {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetChildren reset all changes of the "children" edge.
|
|
func (m *UserMutation) ResetChildren() {
|
|
m.children = nil
|
|
m.removedchildren = nil
|
|
}
|
|
|
|
// AddPetIDs adds the pets edge to Pet by ids.
|
|
func (m *UserMutation) AddPetIDs(ids ...string) {
|
|
if m.pets == nil {
|
|
m.pets = make(map[string]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.pets[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovePetIDs removes the pets edge to Pet by ids.
|
|
func (m *UserMutation) RemovePetIDs(ids ...string) {
|
|
if m.removedpets == nil {
|
|
m.removedpets = make(map[string]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.removedpets[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedPets returns the removed ids of pets.
|
|
func (m *UserMutation) RemovedPetsIDs() (ids []string) {
|
|
for id := range m.removedpets {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// PetsIDs returns the pets ids in the mutation.
|
|
func (m *UserMutation) PetsIDs() (ids []string) {
|
|
for id := range m.pets {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetPets reset all changes of the "pets" edge.
|
|
func (m *UserMutation) ResetPets() {
|
|
m.pets = nil
|
|
m.removedpets = nil
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *UserMutation) Op() Op {
|
|
return m.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 in/decremented, call AddedFields().
|
|
func (m *UserMutation) Fields() []string {
|
|
fields := make([]string, 0, 0)
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name.
|
|
// The second boolean value indicates that this field was
|
|
// not set, or was not define in the schema.
|
|
func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
|
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 was failed.
|
|
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
return nil, fmt.Errorf("unknown User field %s", name)
|
|
}
|
|
|
|
// SetField sets the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *UserMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown User field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented
|
|
// or decremented during this mutation.
|
|
func (m *UserMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was in/decremented
|
|
// from a field with the given name. The second value indicates
|
|
// that this field was not set, or was not define in the schema.
|
|
func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value for the given name. It returns an
|
|
// error if the field is not defined in the schema, or if the
|
|
// type mismatch the field type.
|
|
func (m *UserMutation) AddField(name string, value ent.Value) error {
|
|
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 indicates if this field was
|
|
// cleared in this mutation.
|
|
func (m *UserMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value for 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 regarding the
|
|
// given field name. It returns an error if the field is not
|
|
// defined in the schema.
|
|
func (m *UserMutation) ResetField(name string) error {
|
|
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, 4)
|
|
if m.groups != nil {
|
|
edges = append(edges, user.EdgeGroups)
|
|
}
|
|
if m.parent != nil {
|
|
edges = append(edges, user.EdgeParent)
|
|
}
|
|
if m.children != nil {
|
|
edges = append(edges, user.EdgeChildren)
|
|
}
|
|
if m.pets != nil {
|
|
edges = append(edges, user.EdgePets)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all ids (to other nodes) that were added for
|
|
// the given edge name.
|
|
func (m *UserMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case user.EdgeGroups:
|
|
ids := make([]ent.Value, 0, len(m.groups))
|
|
for id := range m.groups {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case user.EdgeParent:
|
|
if id := m.parent; id != nil {
|
|
return []ent.Value{*id}
|
|
}
|
|
case user.EdgeChildren:
|
|
ids := make([]ent.Value, 0, len(m.children))
|
|
for id := range m.children {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case user.EdgePets:
|
|
ids := make([]ent.Value, 0, len(m.pets))
|
|
for id := range m.pets {
|
|
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, 4)
|
|
if m.removedgroups != nil {
|
|
edges = append(edges, user.EdgeGroups)
|
|
}
|
|
if m.removedchildren != nil {
|
|
edges = append(edges, user.EdgeChildren)
|
|
}
|
|
if m.removedpets != nil {
|
|
edges = append(edges, user.EdgePets)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all ids (to other nodes) that were removed for
|
|
// the given edge name.
|
|
func (m *UserMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case user.EdgeGroups:
|
|
ids := make([]ent.Value, 0, len(m.removedgroups))
|
|
for id := range m.removedgroups {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case user.EdgeChildren:
|
|
ids := make([]ent.Value, 0, len(m.removedchildren))
|
|
for id := range m.removedchildren {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case user.EdgePets:
|
|
ids := make([]ent.Value, 0, len(m.removedpets))
|
|
for id := range m.removedpets {
|
|
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, 4)
|
|
if m.clearedparent {
|
|
edges = append(edges, user.EdgeParent)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean indicates if this edge was
|
|
// cleared in this mutation.
|
|
func (m *UserMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case user.EdgeParent:
|
|
return m.clearedparent
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value for the given name. It returns an
|
|
// error if the edge name is not defined in the schema.
|
|
func (m *UserMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
case user.EdgeParent:
|
|
m.ClearParent()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown User unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes in the mutation regarding the
|
|
// given edge name. It returns an error if the edge is not
|
|
// defined in the schema.
|
|
func (m *UserMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case user.EdgeGroups:
|
|
m.ResetGroups()
|
|
return nil
|
|
case user.EdgeParent:
|
|
m.ResetParent()
|
|
return nil
|
|
case user.EdgeChildren:
|
|
m.ResetChildren()
|
|
return nil
|
|
case user.EdgePets:
|
|
m.ResetPets()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown User edge %s", name)
|
|
}
|