entc/gen/mutation: add IDs method for mutations

This commit is contained in:
Ariel Mashraki
2021-11-03 14:46:54 +02:00
committed by Ariel Mashraki
parent e8e4401d27
commit caa673826a
33 changed files with 2958 additions and 929 deletions

View File

@@ -8,6 +8,7 @@ package entv1
import (
"context"
"errors"
"fmt"
"sync"
@@ -79,7 +80,7 @@ func withCarID(id int) carOption {
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")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Car.Get(ctx, id)
}
@@ -112,7 +113,7 @@ func (m CarMutation) Client() *Client {
// it returns an error otherwise.
func (m CarMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv1: mutation is not running in a transaction")
return nil, errors.New("entv1: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -128,6 +129,25 @@ func (m *CarMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *CarMutation) 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().Car.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetOwnerID sets the "owner" edge to the User entity by id.
func (m *CarMutation) SetOwnerID(id int) {
m.owner = &id
@@ -393,7 +413,7 @@ func withConversionID(id int) conversionOption {
m.oldValue = func(ctx context.Context) (*Conversion, error) {
once.Do(func() {
if m.done {
err = fmt.Errorf("querying old values post mutation is not allowed")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Conversion.Get(ctx, id)
}
@@ -426,7 +446,7 @@ func (m ConversionMutation) Client() *Client {
// it returns an error otherwise.
func (m ConversionMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv1: mutation is not running in a transaction")
return nil, errors.New("entv1: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -442,6 +462,25 @@ func (m *ConversionMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *ConversionMutation) 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().Conversion.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetName sets the "name" field.
func (m *ConversionMutation) SetName(s string) {
m.name = &s
@@ -461,10 +500,10 @@ func (m *ConversionMutation) Name() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldName requires an ID field in the mutation")
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -511,10 +550,10 @@ func (m *ConversionMutation) Int8ToString() (r int8, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt8ToString(ctx context.Context) (v int8, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt8ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt8ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt8ToString requires an ID field in the mutation")
return v, errors.New("OldInt8ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -581,10 +620,10 @@ func (m *ConversionMutation) Uint8ToString() (r uint8, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint8ToString(ctx context.Context) (v uint8, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint8ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint8ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint8ToString requires an ID field in the mutation")
return v, errors.New("OldUint8ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -651,10 +690,10 @@ func (m *ConversionMutation) Int16ToString() (r int16, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt16ToString(ctx context.Context) (v int16, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt16ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt16ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt16ToString requires an ID field in the mutation")
return v, errors.New("OldInt16ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -721,10 +760,10 @@ func (m *ConversionMutation) Uint16ToString() (r uint16, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint16ToString(ctx context.Context) (v uint16, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint16ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint16ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint16ToString requires an ID field in the mutation")
return v, errors.New("OldUint16ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -791,10 +830,10 @@ func (m *ConversionMutation) Int32ToString() (r int32, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt32ToString(ctx context.Context) (v int32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt32ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt32ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt32ToString requires an ID field in the mutation")
return v, errors.New("OldInt32ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -861,10 +900,10 @@ func (m *ConversionMutation) Uint32ToString() (r uint32, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint32ToString(ctx context.Context) (v uint32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint32ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint32ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint32ToString requires an ID field in the mutation")
return v, errors.New("OldUint32ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -931,10 +970,10 @@ func (m *ConversionMutation) Int64ToString() (r int64, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt64ToString(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt64ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt64ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt64ToString requires an ID field in the mutation")
return v, errors.New("OldInt64ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1001,10 +1040,10 @@ func (m *ConversionMutation) Uint64ToString() (r uint64, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint64ToString(ctx context.Context) (v uint64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint64ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint64ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint64ToString requires an ID field in the mutation")
return v, errors.New("OldUint64ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1550,7 +1589,7 @@ func withCustomTypeID(id int) customtypeOption {
m.oldValue = func(ctx context.Context) (*CustomType, error) {
once.Do(func() {
if m.done {
err = fmt.Errorf("querying old values post mutation is not allowed")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CustomType.Get(ctx, id)
}
@@ -1583,7 +1622,7 @@ func (m CustomTypeMutation) Client() *Client {
// it returns an error otherwise.
func (m CustomTypeMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv1: mutation is not running in a transaction")
return nil, errors.New("entv1: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -1599,6 +1638,25 @@ func (m *CustomTypeMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *CustomTypeMutation) 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().CustomType.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCustom sets the "custom" field.
func (m *CustomTypeMutation) SetCustom(s string) {
m.custom = &s
@@ -1618,10 +1676,10 @@ func (m *CustomTypeMutation) Custom() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *CustomTypeMutation) OldCustom(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldCustom is only allowed on UpdateOne operations")
return v, errors.New("OldCustom is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldCustom requires an ID field in the mutation")
return v, errors.New("OldCustom requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1883,7 +1941,7 @@ func withUserID(id int) userOption {
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")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().User.Get(ctx, id)
}
@@ -1916,7 +1974,7 @@ func (m UserMutation) Client() *Client {
// it returns an error otherwise.
func (m UserMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv1: mutation is not running in a transaction")
return nil, errors.New("entv1: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -1938,6 +1996,25 @@ func (m *UserMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetAge sets the "age" field.
func (m *UserMutation) SetAge(i int32) {
m.age = &i
@@ -1958,10 +2035,10 @@ func (m *UserMutation) Age() (r int32, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldAge(ctx context.Context) (v int32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldAge is only allowed on UpdateOne operations")
return v, errors.New("OldAge is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldAge requires an ID field in the mutation")
return v, errors.New("OldAge requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2013,10 +2090,10 @@ func (m *UserMutation) Name() (r string, exists bool) {
// 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, fmt.Errorf("OldName is only allowed on UpdateOne operations")
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldName requires an ID field in the mutation")
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2049,10 +2126,10 @@ func (m *UserMutation) Description() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldDescription(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations")
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldDescription requires an ID field in the mutation")
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2098,10 +2175,10 @@ func (m *UserMutation) Nickname() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldNickname(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldNickname is only allowed on UpdateOne operations")
return v, errors.New("OldNickname is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldNickname requires an ID field in the mutation")
return v, errors.New("OldNickname requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2134,10 +2211,10 @@ func (m *UserMutation) Address() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldAddress(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldAddress is only allowed on UpdateOne operations")
return v, errors.New("OldAddress is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldAddress requires an ID field in the mutation")
return v, errors.New("OldAddress requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2183,10 +2260,10 @@ func (m *UserMutation) Renamed() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldRenamed(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldRenamed is only allowed on UpdateOne operations")
return v, errors.New("OldRenamed is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldRenamed requires an ID field in the mutation")
return v, errors.New("OldRenamed requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2232,10 +2309,10 @@ func (m *UserMutation) Blob() (r []byte, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBlob(ctx context.Context) (v []byte, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldBlob is only allowed on UpdateOne operations")
return v, errors.New("OldBlob is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldBlob requires an ID field in the mutation")
return v, errors.New("OldBlob requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2281,10 +2358,10 @@ func (m *UserMutation) State() (r user.State, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldState(ctx context.Context) (v user.State, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldState is only allowed on UpdateOne operations")
return v, errors.New("OldState is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldState requires an ID field in the mutation")
return v, errors.New("OldState requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2330,10 +2407,10 @@ func (m *UserMutation) Status() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldStatus(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations")
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldStatus requires an ID field in the mutation")
return v, errors.New("OldStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2379,10 +2456,10 @@ func (m *UserMutation) Workplace() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldWorkplace(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldWorkplace is only allowed on UpdateOne operations")
return v, errors.New("OldWorkplace is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldWorkplace requires an ID field in the mutation")
return v, errors.New("OldWorkplace requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {

View File

@@ -8,6 +8,7 @@ package entv2
import (
"context"
"errors"
"fmt"
"sync"
"time"
@@ -85,7 +86,7 @@ func withCarID(id int) carOption {
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")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Car.Get(ctx, id)
}
@@ -118,7 +119,7 @@ func (m CarMutation) Client() *Client {
// it returns an error otherwise.
func (m CarMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -134,6 +135,25 @@ func (m *CarMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *CarMutation) 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().Car.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetOwnerID sets the "owner" edge to the User entity by id.
func (m *CarMutation) SetOwnerID(id int) {
m.owner = &id
@@ -391,7 +411,7 @@ func withConversionID(id int) conversionOption {
m.oldValue = func(ctx context.Context) (*Conversion, error) {
once.Do(func() {
if m.done {
err = fmt.Errorf("querying old values post mutation is not allowed")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Conversion.Get(ctx, id)
}
@@ -424,7 +444,7 @@ func (m ConversionMutation) Client() *Client {
// it returns an error otherwise.
func (m ConversionMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -440,6 +460,25 @@ func (m *ConversionMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *ConversionMutation) 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().Conversion.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetName sets the "name" field.
func (m *ConversionMutation) SetName(s string) {
m.name = &s
@@ -459,10 +498,10 @@ func (m *ConversionMutation) Name() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldName requires an ID field in the mutation")
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -508,10 +547,10 @@ func (m *ConversionMutation) Int8ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt8ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt8ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt8ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt8ToString requires an ID field in the mutation")
return v, errors.New("OldInt8ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -557,10 +596,10 @@ func (m *ConversionMutation) Uint8ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint8ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint8ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint8ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint8ToString requires an ID field in the mutation")
return v, errors.New("OldUint8ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -606,10 +645,10 @@ func (m *ConversionMutation) Int16ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt16ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt16ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt16ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt16ToString requires an ID field in the mutation")
return v, errors.New("OldInt16ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -655,10 +694,10 @@ func (m *ConversionMutation) Uint16ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint16ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint16ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint16ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint16ToString requires an ID field in the mutation")
return v, errors.New("OldUint16ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -704,10 +743,10 @@ func (m *ConversionMutation) Int32ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt32ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt32ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt32ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt32ToString requires an ID field in the mutation")
return v, errors.New("OldInt32ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -753,10 +792,10 @@ func (m *ConversionMutation) Uint32ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint32ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint32ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint32ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint32ToString requires an ID field in the mutation")
return v, errors.New("OldUint32ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -802,10 +841,10 @@ func (m *ConversionMutation) Int64ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldInt64ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldInt64ToString is only allowed on UpdateOne operations")
return v, errors.New("OldInt64ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldInt64ToString requires an ID field in the mutation")
return v, errors.New("OldInt64ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -851,10 +890,10 @@ func (m *ConversionMutation) Uint64ToString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ConversionMutation) OldUint64ToString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldUint64ToString is only allowed on UpdateOne operations")
return v, errors.New("OldUint64ToString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldUint64ToString requires an ID field in the mutation")
return v, errors.New("OldUint64ToString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1281,7 +1320,7 @@ func withCustomTypeID(id int) customtypeOption {
m.oldValue = func(ctx context.Context) (*CustomType, error) {
once.Do(func() {
if m.done {
err = fmt.Errorf("querying old values post mutation is not allowed")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CustomType.Get(ctx, id)
}
@@ -1314,7 +1353,7 @@ func (m CustomTypeMutation) Client() *Client {
// it returns an error otherwise.
func (m CustomTypeMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -1330,6 +1369,25 @@ func (m *CustomTypeMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *CustomTypeMutation) 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().CustomType.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCustom sets the "custom" field.
func (m *CustomTypeMutation) SetCustom(s string) {
m.custom = &s
@@ -1349,10 +1407,10 @@ func (m *CustomTypeMutation) Custom() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *CustomTypeMutation) OldCustom(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldCustom is only allowed on UpdateOne operations")
return v, errors.New("OldCustom is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldCustom requires an ID field in the mutation")
return v, errors.New("OldCustom requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1594,7 +1652,7 @@ func withGroupID(id int) groupOption {
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")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Group.Get(ctx, id)
}
@@ -1627,7 +1685,7 @@ func (m GroupMutation) Client() *Client {
// it returns an error otherwise.
func (m GroupMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -1643,6 +1701,25 @@ func (m *GroupMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *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)
}
}
// Where appends a list predicates to the GroupMutation builder.
func (m *GroupMutation) Where(ps ...predicate.Group) {
m.predicates = append(m.predicates, ps...)
@@ -1827,7 +1904,7 @@ func withMediaID(id int) mediaOption {
m.oldValue = func(ctx context.Context) (*Media, error) {
once.Do(func() {
if m.done {
err = fmt.Errorf("querying old values post mutation is not allowed")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Media.Get(ctx, id)
}
@@ -1860,7 +1937,7 @@ func (m MediaMutation) Client() *Client {
// it returns an error otherwise.
func (m MediaMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -1876,6 +1953,25 @@ func (m *MediaMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *MediaMutation) 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().Media.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetSource sets the "source" field.
func (m *MediaMutation) SetSource(s string) {
m.source = &s
@@ -1895,10 +1991,10 @@ func (m *MediaMutation) Source() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MediaMutation) OldSource(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldSource is only allowed on UpdateOne operations")
return v, errors.New("OldSource is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldSource requires an ID field in the mutation")
return v, errors.New("OldSource requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1944,10 +2040,10 @@ func (m *MediaMutation) SourceURI() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MediaMutation) OldSourceURI(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldSourceURI is only allowed on UpdateOne operations")
return v, errors.New("OldSourceURI is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldSourceURI requires an ID field in the mutation")
return v, errors.New("OldSourceURI requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -1993,10 +2089,10 @@ func (m *MediaMutation) Text() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MediaMutation) OldText(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldText is only allowed on UpdateOne operations")
return v, errors.New("OldText is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldText requires an ID field in the mutation")
return v, errors.New("OldText requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2286,7 +2382,7 @@ func withPetID(id int) petOption {
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")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Pet.Get(ctx, id)
}
@@ -2319,7 +2415,7 @@ func (m PetMutation) Client() *Client {
// it returns an error otherwise.
func (m PetMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -2335,6 +2431,25 @@ func (m *PetMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PetMutation) 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().Pet.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetOwnerID sets the "owner" edge to the User entity by id.
func (m *PetMutation) SetOwnerID(id int) {
m.owner = &id
@@ -2607,7 +2722,7 @@ func withUserID(id int) userOption {
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")
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().User.Get(ctx, id)
}
@@ -2640,7 +2755,7 @@ func (m UserMutation) Client() *Client {
// it returns an error otherwise.
func (m UserMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, fmt.Errorf("entv2: mutation is not running in a transaction")
return nil, errors.New("entv2: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
@@ -2662,6 +2777,25 @@ func (m *UserMutation) ID() (id int, exists bool) {
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetMixedString sets the "mixed_string" field.
func (m *UserMutation) SetMixedString(s string) {
m.mixed_string = &s
@@ -2681,10 +2815,10 @@ func (m *UserMutation) MixedString() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldMixedString(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldMixedString is only allowed on UpdateOne operations")
return v, errors.New("OldMixedString is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldMixedString requires an ID field in the mutation")
return v, errors.New("OldMixedString requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2717,10 +2851,10 @@ func (m *UserMutation) MixedEnum() (r user.MixedEnum, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldMixedEnum(ctx context.Context) (v user.MixedEnum, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldMixedEnum is only allowed on UpdateOne operations")
return v, errors.New("OldMixedEnum is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldMixedEnum requires an ID field in the mutation")
return v, errors.New("OldMixedEnum requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2754,10 +2888,10 @@ func (m *UserMutation) Age() (r int, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldAge(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldAge is only allowed on UpdateOne operations")
return v, errors.New("OldAge is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldAge requires an ID field in the mutation")
return v, errors.New("OldAge requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2809,10 +2943,10 @@ func (m *UserMutation) Name() (r string, exists bool) {
// 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, fmt.Errorf("OldName is only allowed on UpdateOne operations")
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldName requires an ID field in the mutation")
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2845,10 +2979,10 @@ func (m *UserMutation) Description() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldDescription(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations")
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldDescription requires an ID field in the mutation")
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2894,10 +3028,10 @@ func (m *UserMutation) Nickname() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldNickname(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldNickname is only allowed on UpdateOne operations")
return v, errors.New("OldNickname is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldNickname requires an ID field in the mutation")
return v, errors.New("OldNickname requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2930,10 +3064,10 @@ func (m *UserMutation) Phone() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldPhone(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldPhone is only allowed on UpdateOne operations")
return v, errors.New("OldPhone is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldPhone requires an ID field in the mutation")
return v, errors.New("OldPhone requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -2966,10 +3100,10 @@ func (m *UserMutation) Buffer() (r []byte, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBuffer(ctx context.Context) (v []byte, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldBuffer is only allowed on UpdateOne operations")
return v, errors.New("OldBuffer is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldBuffer requires an ID field in the mutation")
return v, errors.New("OldBuffer requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3015,10 +3149,10 @@ func (m *UserMutation) Title() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldTitle(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldTitle is only allowed on UpdateOne operations")
return v, errors.New("OldTitle is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldTitle requires an ID field in the mutation")
return v, errors.New("OldTitle requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3051,10 +3185,10 @@ func (m *UserMutation) NewName() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldNewName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldNewName is only allowed on UpdateOne operations")
return v, errors.New("OldNewName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldNewName requires an ID field in the mutation")
return v, errors.New("OldNewName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3100,10 +3234,10 @@ func (m *UserMutation) Blob() (r []byte, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBlob(ctx context.Context) (v []byte, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldBlob is only allowed on UpdateOne operations")
return v, errors.New("OldBlob is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldBlob requires an ID field in the mutation")
return v, errors.New("OldBlob requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3149,10 +3283,10 @@ func (m *UserMutation) State() (r user.State, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldState(ctx context.Context) (v user.State, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldState is only allowed on UpdateOne operations")
return v, errors.New("OldState is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldState requires an ID field in the mutation")
return v, errors.New("OldState requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3198,10 +3332,10 @@ func (m *UserMutation) Status() (r user.Status, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldStatus(ctx context.Context) (v user.Status, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations")
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldStatus requires an ID field in the mutation")
return v, errors.New("OldStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3247,10 +3381,10 @@ func (m *UserMutation) Workplace() (r string, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldWorkplace(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldWorkplace is only allowed on UpdateOne operations")
return v, errors.New("OldWorkplace is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldWorkplace requires an ID field in the mutation")
return v, errors.New("OldWorkplace requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
@@ -3296,10 +3430,10 @@ func (m *UserMutation) CreatedAt() (r time.Time, exists bool) {
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {