Files
upstream-mirror 4b3ad0b611
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped
snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:12:36 +05:00

2311 lines
73 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 ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"time"
"entgo.io/ent"
"entgo.io/ent/entc/integration/edgeschema/ent/attachedfile"
"entgo.io/ent/entc/integration/edgeschema/ent/file"
"entgo.io/ent/entc/integration/edgeschema/ent/friendship"
"entgo.io/ent/entc/integration/edgeschema/ent/group"
"entgo.io/ent/entc/integration/edgeschema/ent/grouptag"
"entgo.io/ent/entc/integration/edgeschema/ent/process"
"entgo.io/ent/entc/integration/edgeschema/ent/relationship"
"entgo.io/ent/entc/integration/edgeschema/ent/relationshipinfo"
"entgo.io/ent/entc/integration/edgeschema/ent/role"
"entgo.io/ent/entc/integration/edgeschema/ent/roleuser"
"entgo.io/ent/entc/integration/edgeschema/ent/tag"
"entgo.io/ent/entc/integration/edgeschema/ent/tweet"
"entgo.io/ent/entc/integration/edgeschema/ent/tweetlike"
"entgo.io/ent/entc/integration/edgeschema/ent/tweettag"
"entgo.io/ent/entc/integration/edgeschema/ent/user"
"entgo.io/ent/entc/integration/edgeschema/ent/usergroup"
"entgo.io/ent/entc/integration/edgeschema/ent/usertweet"
"github.com/google/uuid"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeAttachedFile = "AttachedFile"
TypeFile = "File"
TypeFriendship = "Friendship"
TypeGroup = "Group"
TypeGroupTag = "GroupTag"
TypeProcess = "Process"
TypeRelationship = "Relationship"
TypeRelationshipInfo = "RelationshipInfo"
TypeRole = "Role"
TypeRoleUser = "RoleUser"
TypeTag = "Tag"
TypeTweet = "Tweet"
TypeTweetLike = "TweetLike"
TypeTweetTag = "TweetTag"
TypeUser = "User"
TypeUserGroup = "UserGroup"
TypeUserTweet = "UserTweet"
)
// AttachedFileMutation represents an operation that mutates the AttachedFile nodes in the graph.
type AttachedFileMutation struct {
attachedfile.Mutation
config
id *int
done bool
oldValue func(context.Context) (*AttachedFile, error)
}
var _ ent.Mutation = (*AttachedFileMutation)(nil)
// attachedfileOption allows management of the mutation configuration using functional options.
type attachedfileOption func(*AttachedFileMutation)
// newAttachedFileMutation creates new mutation for the AttachedFile entity.
func newAttachedFileMutation(c config, op Op, opts ...attachedfileOption) *AttachedFileMutation {
m := &AttachedFileMutation{
Mutation: *attachedfile.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *AttachedFileMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withAttachedFileID sets the ID field of the mutation.
func withAttachedFileID(id int) attachedfileOption {
return func(m *AttachedFileMutation) {
var (
err error
once sync.Once
value *AttachedFile
)
m.oldValue = func(ctx context.Context) (*AttachedFile, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().AttachedFile.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withAttachedFile sets the old AttachedFile of the mutation.
func withAttachedFile(node *AttachedFile) attachedfileOption {
return func(m *AttachedFileMutation) {
m.oldValue = func(context.Context) (*AttachedFile, 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 AttachedFileMutation) 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 AttachedFileMutation) 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
}
// 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 *AttachedFileMutation) 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().AttachedFile.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldAttachTime returns the old "attach_time" field's value of the AttachedFile entity.
// If the AttachedFile 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 *AttachedFileMutation) OldAttachTime(ctx context.Context) (v time.Time, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldAttachTime is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldAttachTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAttachTime: %w", err)
}
return oldValue.AttachTime, nil
}
// OldFID returns the old "f_id" field's value of the AttachedFile entity.
// If the AttachedFile 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 *AttachedFileMutation) OldFID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldFID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldFID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFID: %w", err)
}
return oldValue.FID, nil
}
// OldProcID returns the old "proc_id" field's value of the AttachedFile entity.
// If the AttachedFile 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 *AttachedFileMutation) OldProcID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldProcID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldProcID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldProcID: %w", err)
}
return oldValue.ProcID, nil
}
// 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 *AttachedFileMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case attachedfile.FieldAttachTime:
return m.OldAttachTime(ctx)
case attachedfile.FieldFID:
return m.OldFID(ctx)
case attachedfile.FieldProcID:
return m.OldProcID(ctx)
}
return nil, fmt.Errorf("unknown AttachedFile field %s", name)
}
// FileMutation represents an operation that mutates the File nodes in the graph.
type FileMutation struct {
file.Mutation
config
id *int
done bool
oldValue func(context.Context) (*File, error)
}
var _ ent.Mutation = (*FileMutation)(nil)
// fileOption allows management of the mutation configuration using functional options.
type fileOption func(*FileMutation)
// newFileMutation creates new mutation for the File entity.
func newFileMutation(c config, op Op, opts ...fileOption) *FileMutation {
m := &FileMutation{
Mutation: *file.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *FileMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withFileID sets the ID field of the mutation.
func withFileID(id int) fileOption {
return func(m *FileMutation) {
var (
err error
once sync.Once
value *File
)
m.oldValue = func(ctx context.Context) (*File, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().File.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withFile sets the old File of the mutation.
func withFile(node *File) fileOption {
return func(m *FileMutation) {
m.oldValue = func(context.Context) (*File, 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 FileMutation) 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 FileMutation) 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
}
// 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 *FileMutation) 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().File.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldName returns the old "name" field's value of the File entity.
// If the File 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 *FileMutation) 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 _, exists := m.ID(); !exists || 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
}
// 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 *FileMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case file.FieldName:
return m.OldName(ctx)
}
return nil, fmt.Errorf("unknown File field %s", name)
}
// FriendshipMutation represents an operation that mutates the Friendship nodes in the graph.
type FriendshipMutation struct {
friendship.Mutation
config
id *int
done bool
oldValue func(context.Context) (*Friendship, error)
}
var _ ent.Mutation = (*FriendshipMutation)(nil)
// friendshipOption allows management of the mutation configuration using functional options.
type friendshipOption func(*FriendshipMutation)
// newFriendshipMutation creates new mutation for the Friendship entity.
func newFriendshipMutation(c config, op Op, opts ...friendshipOption) *FriendshipMutation {
m := &FriendshipMutation{
Mutation: *friendship.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *FriendshipMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withFriendshipID sets the ID field of the mutation.
func withFriendshipID(id int) friendshipOption {
return func(m *FriendshipMutation) {
var (
err error
once sync.Once
value *Friendship
)
m.oldValue = func(ctx context.Context) (*Friendship, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Friendship.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withFriendship sets the old Friendship of the mutation.
func withFriendship(node *Friendship) friendshipOption {
return func(m *FriendshipMutation) {
m.oldValue = func(context.Context) (*Friendship, 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 FriendshipMutation) 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 FriendshipMutation) 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
}
// 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 *FriendshipMutation) 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().Friendship.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldWeight returns the old "weight" field's value of the Friendship entity.
// If the Friendship 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 *FriendshipMutation) OldWeight(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldWeight is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldWeight requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldWeight: %w", err)
}
return oldValue.Weight, nil
}
// OldCreatedAt returns the old "created_at" field's value of the Friendship entity.
// If the Friendship 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 *FriendshipMutation) 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 _, exists := m.ID(); !exists || 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
}
// OldUserID returns the old "user_id" field's value of the Friendship entity.
// If the Friendship 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 *FriendshipMutation) OldUserID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// OldFriendID returns the old "friend_id" field's value of the Friendship entity.
// If the Friendship 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 *FriendshipMutation) OldFriendID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldFriendID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldFriendID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFriendID: %w", err)
}
return oldValue.FriendID, nil
}
// 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 *FriendshipMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case friendship.FieldWeight:
return m.OldWeight(ctx)
case friendship.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case friendship.FieldUserID:
return m.OldUserID(ctx)
case friendship.FieldFriendID:
return m.OldFriendID(ctx)
}
return nil, fmt.Errorf("unknown Friendship field %s", name)
}
// GroupMutation represents an operation that mutates the Group nodes in the graph.
type GroupMutation struct {
group.Mutation
config
id *int
done bool
oldValue func(context.Context) (*Group, error)
}
var _ ent.Mutation = (*GroupMutation)(nil)
// groupOption allows management of the mutation configuration using functional options.
type groupOption func(*GroupMutation)
// newGroupMutation creates new mutation for the Group entity.
func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation {
m := &GroupMutation{
Mutation: *group.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *GroupMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// 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 = errors.New("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, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// 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 *GroupMutation) 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().Group.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldName returns the old "name" field's value of the Group entity.
// If the Group 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 *GroupMutation) 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 _, exists := m.ID(); !exists || 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
}
// 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 *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case group.FieldName:
return m.OldName(ctx)
}
return nil, fmt.Errorf("unknown Group field %s", name)
}
// GroupTagMutation represents an operation that mutates the GroupTag nodes in the graph.
type GroupTagMutation struct {
grouptag.Mutation
config
id *int
done bool
oldValue func(context.Context) (*GroupTag, error)
}
var _ ent.Mutation = (*GroupTagMutation)(nil)
// grouptagOption allows management of the mutation configuration using functional options.
type grouptagOption func(*GroupTagMutation)
// newGroupTagMutation creates new mutation for the GroupTag entity.
func newGroupTagMutation(c config, op Op, opts ...grouptagOption) *GroupTagMutation {
m := &GroupTagMutation{
Mutation: *grouptag.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *GroupTagMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withGroupTagID sets the ID field of the mutation.
func withGroupTagID(id int) grouptagOption {
return func(m *GroupTagMutation) {
var (
err error
once sync.Once
value *GroupTag
)
m.oldValue = func(ctx context.Context) (*GroupTag, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().GroupTag.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withGroupTag sets the old GroupTag of the mutation.
func withGroupTag(node *GroupTag) grouptagOption {
return func(m *GroupTagMutation) {
m.oldValue = func(context.Context) (*GroupTag, 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 GroupTagMutation) 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 GroupTagMutation) 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
}
// 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 *GroupTagMutation) 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().GroupTag.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldTagID returns the old "tag_id" field's value of the GroupTag entity.
// If the GroupTag 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 *GroupTagMutation) OldTagID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldTagID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldTagID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTagID: %w", err)
}
return oldValue.TagID, nil
}
// OldGroupID returns the old "group_id" field's value of the GroupTag entity.
// If the GroupTag 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 *GroupTagMutation) OldGroupID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldGroupID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
}
return oldValue.GroupID, nil
}
// 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 *GroupTagMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case grouptag.FieldTagID:
return m.OldTagID(ctx)
case grouptag.FieldGroupID:
return m.OldGroupID(ctx)
}
return nil, fmt.Errorf("unknown GroupTag field %s", name)
}
// ProcessMutation represents an operation that mutates the Process nodes in the graph.
type ProcessMutation struct {
process.Mutation
config
id *int
done bool
oldValue func(context.Context) (*Process, error)
}
var _ ent.Mutation = (*ProcessMutation)(nil)
// processOption allows management of the mutation configuration using functional options.
type processOption func(*ProcessMutation)
// newProcessMutation creates new mutation for the Process entity.
func newProcessMutation(c config, op Op, opts ...processOption) *ProcessMutation {
m := &ProcessMutation{
Mutation: *process.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *ProcessMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withProcessID sets the ID field of the mutation.
func withProcessID(id int) processOption {
return func(m *ProcessMutation) {
var (
err error
once sync.Once
value *Process
)
m.oldValue = func(ctx context.Context) (*Process, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Process.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withProcess sets the old Process of the mutation.
func withProcess(node *Process) processOption {
return func(m *ProcessMutation) {
m.oldValue = func(context.Context) (*Process, 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 ProcessMutation) 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 ProcessMutation) 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
}
// 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 *ProcessMutation) 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().Process.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// 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 *ProcessMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
return nil, fmt.Errorf("unknown Process field %s", name)
}
// RelationshipMutation represents an operation that mutates the Relationship nodes in the graph.
type RelationshipMutation struct {
relationship.Mutation
config
done bool
oldValue func(context.Context) (*Relationship, error)
}
var _ ent.Mutation = (*RelationshipMutation)(nil)
// relationshipOption allows management of the mutation configuration using functional options.
type relationshipOption func(*RelationshipMutation)
// newRelationshipMutation creates new mutation for the Relationship entity.
func newRelationshipMutation(c config, op Op, opts ...relationshipOption) *RelationshipMutation {
m := &RelationshipMutation{
Mutation: *relationship.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 RelationshipMutation) 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 RelationshipMutation) 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
}
// 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 *RelationshipMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
return nil, errors.New("edge schema Relationship does not support getting old values")
}
// RelationshipInfoMutation represents an operation that mutates the RelationshipInfo nodes in the graph.
type RelationshipInfoMutation struct {
relationshipinfo.Mutation
config
id *int
done bool
oldValue func(context.Context) (*RelationshipInfo, error)
}
var _ ent.Mutation = (*RelationshipInfoMutation)(nil)
// relationshipinfoOption allows management of the mutation configuration using functional options.
type relationshipinfoOption func(*RelationshipInfoMutation)
// newRelationshipInfoMutation creates new mutation for the RelationshipInfo entity.
func newRelationshipInfoMutation(c config, op Op, opts ...relationshipinfoOption) *RelationshipInfoMutation {
m := &RelationshipInfoMutation{
Mutation: *relationshipinfo.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *RelationshipInfoMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withRelationshipInfoID sets the ID field of the mutation.
func withRelationshipInfoID(id int) relationshipinfoOption {
return func(m *RelationshipInfoMutation) {
var (
err error
once sync.Once
value *RelationshipInfo
)
m.oldValue = func(ctx context.Context) (*RelationshipInfo, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().RelationshipInfo.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withRelationshipInfo sets the old RelationshipInfo of the mutation.
func withRelationshipInfo(node *RelationshipInfo) relationshipinfoOption {
return func(m *RelationshipInfoMutation) {
m.oldValue = func(context.Context) (*RelationshipInfo, 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 RelationshipInfoMutation) 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 RelationshipInfoMutation) 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
}
// 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 *RelationshipInfoMutation) 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().RelationshipInfo.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldText returns the old "text" field's value of the RelationshipInfo entity.
// If the RelationshipInfo 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 *RelationshipInfoMutation) OldText(ctx context.Context) (v string, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldText is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldText requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldText: %w", err)
}
return oldValue.Text, nil
}
// 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 *RelationshipInfoMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case relationshipinfo.FieldText:
return m.OldText(ctx)
}
return nil, fmt.Errorf("unknown RelationshipInfo field %s", name)
}
// RoleMutation represents an operation that mutates the Role nodes in the graph.
type RoleMutation struct {
role.Mutation
config
id *int
done bool
oldValue func(context.Context) (*Role, error)
}
var _ ent.Mutation = (*RoleMutation)(nil)
// roleOption allows management of the mutation configuration using functional options.
type roleOption func(*RoleMutation)
// newRoleMutation creates new mutation for the Role entity.
func newRoleMutation(c config, op Op, opts ...roleOption) *RoleMutation {
m := &RoleMutation{
Mutation: *role.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *RoleMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withRoleID sets the ID field of the mutation.
func withRoleID(id int) roleOption {
return func(m *RoleMutation) {
var (
err error
once sync.Once
value *Role
)
m.oldValue = func(ctx context.Context) (*Role, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Role.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withRole sets the old Role of the mutation.
func withRole(node *Role) roleOption {
return func(m *RoleMutation) {
m.oldValue = func(context.Context) (*Role, 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 RoleMutation) 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 RoleMutation) 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
}
// 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 *RoleMutation) 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().Role.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldName returns the old "name" field's value of the Role entity.
// If the Role 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 *RoleMutation) 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 _, exists := m.ID(); !exists || 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
}
// OldCreatedAt returns the old "created_at" field's value of the Role entity.
// If the Role 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 *RoleMutation) 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 _, exists := m.ID(); !exists || 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
}
// 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 *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case role.FieldName:
return m.OldName(ctx)
case role.FieldCreatedAt:
return m.OldCreatedAt(ctx)
}
return nil, fmt.Errorf("unknown Role field %s", name)
}
// RoleUserMutation represents an operation that mutates the RoleUser nodes in the graph.
type RoleUserMutation struct {
roleuser.Mutation
config
done bool
oldValue func(context.Context) (*RoleUser, error)
}
var _ ent.Mutation = (*RoleUserMutation)(nil)
// roleuserOption allows management of the mutation configuration using functional options.
type roleuserOption func(*RoleUserMutation)
// newRoleUserMutation creates new mutation for the RoleUser entity.
func newRoleUserMutation(c config, op Op, opts ...roleuserOption) *RoleUserMutation {
m := &RoleUserMutation{
Mutation: *roleuser.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 RoleUserMutation) 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 RoleUserMutation) 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
}
// 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 *RoleUserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
return nil, errors.New("edge schema RoleUser does not support getting old values")
}
// TagMutation represents an operation that mutates the Tag nodes in the graph.
type TagMutation struct {
tag.Mutation
config
id *int
done bool
oldValue func(context.Context) (*Tag, error)
}
var _ ent.Mutation = (*TagMutation)(nil)
// tagOption allows management of the mutation configuration using functional options.
type tagOption func(*TagMutation)
// newTagMutation creates new mutation for the Tag entity.
func newTagMutation(c config, op Op, opts ...tagOption) *TagMutation {
m := &TagMutation{
Mutation: *tag.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *TagMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withTagID sets the ID field of the mutation.
func withTagID(id int) tagOption {
return func(m *TagMutation) {
var (
err error
once sync.Once
value *Tag
)
m.oldValue = func(ctx context.Context) (*Tag, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Tag.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withTag sets the old Tag of the mutation.
func withTag(node *Tag) tagOption {
return func(m *TagMutation) {
m.oldValue = func(context.Context) (*Tag, 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 TagMutation) 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 TagMutation) 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
}
// 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 *TagMutation) 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().Tag.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldValue returns the old "value" field's value of the Tag entity.
// If the Tag 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 *TagMutation) 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 _, exists := m.ID(); !exists || 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
}
// 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 *TagMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case tag.FieldValue:
return m.OldValue(ctx)
}
return nil, fmt.Errorf("unknown Tag field %s", name)
}
// TweetMutation represents an operation that mutates the Tweet nodes in the graph.
type TweetMutation struct {
tweet.Mutation
config
id *int
done bool
oldValue func(context.Context) (*Tweet, error)
}
var _ ent.Mutation = (*TweetMutation)(nil)
// tweetOption allows management of the mutation configuration using functional options.
type tweetOption func(*TweetMutation)
// newTweetMutation creates new mutation for the Tweet entity.
func newTweetMutation(c config, op Op, opts ...tweetOption) *TweetMutation {
m := &TweetMutation{
Mutation: *tweet.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *TweetMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withTweetID sets the ID field of the mutation.
func withTweetID(id int) tweetOption {
return func(m *TweetMutation) {
var (
err error
once sync.Once
value *Tweet
)
m.oldValue = func(ctx context.Context) (*Tweet, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Tweet.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withTweet sets the old Tweet of the mutation.
func withTweet(node *Tweet) tweetOption {
return func(m *TweetMutation) {
m.oldValue = func(context.Context) (*Tweet, 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 TweetMutation) 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 TweetMutation) 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
}
// 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 *TweetMutation) 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().Tweet.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldText returns the old "text" field's value of the Tweet entity.
// If the Tweet 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 *TweetMutation) OldText(ctx context.Context) (v string, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldText is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldText requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldText: %w", err)
}
return oldValue.Text, nil
}
// 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 *TweetMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case tweet.FieldText:
return m.OldText(ctx)
}
return nil, fmt.Errorf("unknown Tweet field %s", name)
}
// TweetLikeMutation represents an operation that mutates the TweetLike nodes in the graph.
type TweetLikeMutation struct {
tweetlike.Mutation
config
done bool
oldValue func(context.Context) (*TweetLike, error)
}
var _ ent.Mutation = (*TweetLikeMutation)(nil)
// tweetlikeOption allows management of the mutation configuration using functional options.
type tweetlikeOption func(*TweetLikeMutation)
// newTweetLikeMutation creates new mutation for the TweetLike entity.
func newTweetLikeMutation(c config, op Op, opts ...tweetlikeOption) *TweetLikeMutation {
m := &TweetLikeMutation{
Mutation: *tweetlike.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 TweetLikeMutation) 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 TweetLikeMutation) 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
}
// 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 *TweetLikeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
return nil, errors.New("edge schema TweetLike does not support getting old values")
}
// TweetTagMutation represents an operation that mutates the TweetTag nodes in the graph.
type TweetTagMutation struct {
tweettag.Mutation
config
id *uuid.UUID
done bool
oldValue func(context.Context) (*TweetTag, error)
}
var _ ent.Mutation = (*TweetTagMutation)(nil)
// tweettagOption allows management of the mutation configuration using functional options.
type tweettagOption func(*TweetTagMutation)
// newTweetTagMutation creates new mutation for the TweetTag entity.
func newTweetTagMutation(c config, op Op, opts ...tweettagOption) *TweetTagMutation {
m := &TweetTagMutation{
Mutation: *tweettag.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of TweetTag entities.
func (m *TweetTagMutation) SetID(id uuid.UUID) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *TweetTagMutation) ID() (id uuid.UUID, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withTweetTagID sets the ID field of the mutation.
func withTweetTagID(id uuid.UUID) tweettagOption {
return func(m *TweetTagMutation) {
var (
err error
once sync.Once
value *TweetTag
)
m.oldValue = func(ctx context.Context) (*TweetTag, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().TweetTag.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withTweetTag sets the old TweetTag of the mutation.
func withTweetTag(node *TweetTag) tweettagOption {
return func(m *TweetTagMutation) {
m.oldValue = func(context.Context) (*TweetTag, 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 TweetTagMutation) 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 TweetTagMutation) 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
}
// 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 *TweetTagMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
switch {
case m.Op().Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []uuid.UUID{id}, nil
}
fallthrough
case m.Op().Is(OpUpdate | OpDelete):
return m.Client().TweetTag.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldAddedAt returns the old "added_at" field's value of the TweetTag entity.
// If the TweetTag 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 *TweetTagMutation) OldAddedAt(ctx context.Context) (v time.Time, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldAddedAt is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldAddedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAddedAt: %w", err)
}
return oldValue.AddedAt, nil
}
// OldTagID returns the old "tag_id" field's value of the TweetTag entity.
// If the TweetTag 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 *TweetTagMutation) OldTagID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldTagID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldTagID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTagID: %w", err)
}
return oldValue.TagID, nil
}
// OldTweetID returns the old "tweet_id" field's value of the TweetTag entity.
// If the TweetTag 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 *TweetTagMutation) OldTweetID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldTweetID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldTweetID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTweetID: %w", err)
}
return oldValue.TweetID, nil
}
// 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 *TweetTagMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case tweettag.FieldAddedAt:
return m.OldAddedAt(ctx)
case tweettag.FieldTagID:
return m.OldTagID(ctx)
case tweettag.FieldTweetID:
return m.OldTweetID(ctx)
}
return nil, fmt.Errorf("unknown TweetTag field %s", name)
}
// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
user.Mutation
config
id *int
done bool
oldValue func(context.Context) (*User, error)
}
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{
Mutation: *user.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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
}
// 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
}
// 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())
}
}
// OldName returns the old "name" 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) 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 _, exists := m.ID(); !exists || 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
}
// 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.FieldName:
return m.OldName(ctx)
}
return nil, fmt.Errorf("unknown User field %s", name)
}
// UserGroupMutation represents an operation that mutates the UserGroup nodes in the graph.
type UserGroupMutation struct {
usergroup.Mutation
config
id *int
done bool
oldValue func(context.Context) (*UserGroup, error)
}
var _ ent.Mutation = (*UserGroupMutation)(nil)
// usergroupOption allows management of the mutation configuration using functional options.
type usergroupOption func(*UserGroupMutation)
// newUserGroupMutation creates new mutation for the UserGroup entity.
func newUserGroupMutation(c config, op Op, opts ...usergroupOption) *UserGroupMutation {
m := &UserGroupMutation{
Mutation: *usergroup.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *UserGroupMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withUserGroupID sets the ID field of the mutation.
func withUserGroupID(id int) usergroupOption {
return func(m *UserGroupMutation) {
var (
err error
once sync.Once
value *UserGroup
)
m.oldValue = func(ctx context.Context) (*UserGroup, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserGroup.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserGroup sets the old UserGroup of the mutation.
func withUserGroup(node *UserGroup) usergroupOption {
return func(m *UserGroupMutation) {
m.oldValue = func(context.Context) (*UserGroup, 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 UserGroupMutation) 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 UserGroupMutation) 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
}
// 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 *UserGroupMutation) 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().UserGroup.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldJoinedAt returns the old "joined_at" field's value of the UserGroup entity.
// If the UserGroup 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 *UserGroupMutation) OldJoinedAt(ctx context.Context) (v time.Time, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldJoinedAt is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldJoinedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldJoinedAt: %w", err)
}
return oldValue.JoinedAt, nil
}
// OldUserID returns the old "user_id" field's value of the UserGroup entity.
// If the UserGroup 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 *UserGroupMutation) OldUserID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// OldGroupID returns the old "group_id" field's value of the UserGroup entity.
// If the UserGroup 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 *UserGroupMutation) OldGroupID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldGroupID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
}
return oldValue.GroupID, nil
}
// 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 *UserGroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case usergroup.FieldJoinedAt:
return m.OldJoinedAt(ctx)
case usergroup.FieldUserID:
return m.OldUserID(ctx)
case usergroup.FieldGroupID:
return m.OldGroupID(ctx)
}
return nil, fmt.Errorf("unknown UserGroup field %s", name)
}
// UserTweetMutation represents an operation that mutates the UserTweet nodes in the graph.
type UserTweetMutation struct {
usertweet.Mutation
config
id *int
done bool
oldValue func(context.Context) (*UserTweet, error)
}
var _ ent.Mutation = (*UserTweetMutation)(nil)
// usertweetOption allows management of the mutation configuration using functional options.
type usertweetOption func(*UserTweetMutation)
// newUserTweetMutation creates new mutation for the UserTweet entity.
func newUserTweetMutation(c config, op Op, opts ...usertweetOption) *UserTweetMutation {
m := &UserTweetMutation{
Mutation: *usertweet.NewMutation(op),
config: c,
}
for _, opt := range opts {
opt(m)
}
return m
}
// 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 *UserTweetMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// withUserTweetID sets the ID field of the mutation.
func withUserTweetID(id int) usertweetOption {
return func(m *UserTweetMutation) {
var (
err error
once sync.Once
value *UserTweet
)
m.oldValue = func(ctx context.Context) (*UserTweet, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UserTweet.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUserTweet sets the old UserTweet of the mutation.
func withUserTweet(node *UserTweet) usertweetOption {
return func(m *UserTweetMutation) {
m.oldValue = func(context.Context) (*UserTweet, 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 UserTweetMutation) 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 UserTweetMutation) 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
}
// 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 *UserTweetMutation) 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().UserTweet.Query().Where(m.Predicates()...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
}
}
// OldCreatedAt returns the old "created_at" field's value of the UserTweet entity.
// If the UserTweet 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 *UserTweetMutation) 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 _, exists := m.ID(); !exists || 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
}
// OldUserID returns the old "user_id" field's value of the UserTweet entity.
// If the UserTweet 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 *UserTweetMutation) OldUserID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// OldTweetID returns the old "tweet_id" field's value of the UserTweet entity.
// If the UserTweet 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 *UserTweetMutation) OldTweetID(ctx context.Context) (v int, err error) {
if !m.Op().Is(OpUpdateOne) {
return v, errors.New("OldTweetID is only allowed on UpdateOne operations")
}
if _, exists := m.ID(); !exists || m.oldValue == nil {
return v, errors.New("OldTweetID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTweetID: %w", err)
}
return oldValue.TweetID, nil
}
// 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 *UserTweetMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case usertweet.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case usertweet.FieldUserID:
return m.OldUserID(ctx)
case usertweet.FieldTweetID:
return m.OldTweetID(ctx)
}
return nil, fmt.Errorf("unknown UserTweet field %s", name)
}