mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen/mutation: add IDs method for mutations
This commit is contained in:
committed by
Ariel Mashraki
parent
e8e4401d27
commit
caa673826a
@@ -8,6 +8,7 @@ package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
@@ -99,7 +100,7 @@ func withBlobID(id uuid.UUID) blobOption {
|
||||
m.oldValue = func(ctx context.Context) (*Blob, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = fmt.Errorf("querying old values post mutation is not allowed")
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Blob.Get(ctx, id)
|
||||
}
|
||||
@@ -132,7 +133,7 @@ func (m BlobMutation) Client() *Client {
|
||||
// it returns an error otherwise.
|
||||
func (m BlobMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -154,6 +155,25 @@ func (m *BlobMutation) ID() (id uuid.UUID, 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 *BlobMutation) 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().Blob.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetUUID sets the "uuid" field.
|
||||
func (m *BlobMutation) SetUUID(u uuid.UUID) {
|
||||
m.uuid = &u
|
||||
@@ -173,10 +193,10 @@ func (m *BlobMutation) UUID() (r uuid.UUID, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *BlobMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldUUID is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldUUID requires an ID field in the mutation")
|
||||
return v, errors.New("OldUUID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -210,10 +230,10 @@ func (m *BlobMutation) Count() (r int, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *BlobMutation) OldCount(ctx context.Context) (v int, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldCount is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldCount is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldCount requires an ID field in the mutation")
|
||||
return v, errors.New("OldCount requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -638,7 +658,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)
|
||||
}
|
||||
@@ -671,7 +691,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("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -693,6 +713,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)
|
||||
}
|
||||
}
|
||||
|
||||
// SetBeforeID sets the "before_id" field.
|
||||
func (m *CarMutation) SetBeforeID(f float64) {
|
||||
m.before_id = &f
|
||||
@@ -713,10 +752,10 @@ func (m *CarMutation) BeforeID() (r float64, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *CarMutation) OldBeforeID(ctx context.Context) (v float64, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldBeforeID is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldBeforeID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldBeforeID requires an ID field in the mutation")
|
||||
return v, errors.New("OldBeforeID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -783,10 +822,10 @@ func (m *CarMutation) AfterID() (r float64, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *CarMutation) OldAfterID(ctx context.Context) (v float64, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldAfterID is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldAfterID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldAfterID requires an ID field in the mutation")
|
||||
return v, errors.New("OldAfterID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -852,10 +891,10 @@ func (m *CarMutation) Model() (r string, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *CarMutation) OldModel(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldModel is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldModel is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldModel requires an ID field in the mutation")
|
||||
return v, errors.New("OldModel requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -1223,7 +1262,7 @@ func withDeviceID(id schema.ID) deviceOption {
|
||||
m.oldValue = func(ctx context.Context) (*Device, 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().Device.Get(ctx, id)
|
||||
}
|
||||
@@ -1256,7 +1295,7 @@ func (m DeviceMutation) Client() *Client {
|
||||
// it returns an error otherwise.
|
||||
func (m DeviceMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -1278,6 +1317,25 @@ func (m *DeviceMutation) ID() (id schema.ID, 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 *DeviceMutation) IDs(ctx context.Context) ([]schema.ID, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []schema.ID{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Device.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetActiveSessionID sets the "active_session" edge to the Session entity by id.
|
||||
func (m *DeviceMutation) SetActiveSessionID(id schema.ID) {
|
||||
m.active_session = &id
|
||||
@@ -1612,7 +1670,7 @@ func withDocID(id schema.DocID) docOption {
|
||||
m.oldValue = func(ctx context.Context) (*Doc, 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().Doc.Get(ctx, id)
|
||||
}
|
||||
@@ -1645,7 +1703,7 @@ func (m DocMutation) Client() *Client {
|
||||
// it returns an error otherwise.
|
||||
func (m DocMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -1667,6 +1725,25 @@ func (m *DocMutation) ID() (id schema.DocID, 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 *DocMutation) IDs(ctx context.Context) ([]schema.DocID, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []schema.DocID{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Doc.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (m *DocMutation) SetText(s string) {
|
||||
m.text = &s
|
||||
@@ -1686,10 +1763,10 @@ func (m *DocMutation) Text() (r string, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *DocMutation) 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 {
|
||||
@@ -2081,7 +2158,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)
|
||||
}
|
||||
@@ -2114,7 +2191,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("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -2136,6 +2213,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)
|
||||
}
|
||||
}
|
||||
|
||||
// AddUserIDs adds the "users" edge to the User entity by ids.
|
||||
func (m *GroupMutation) AddUserIDs(ids ...int) {
|
||||
if m.users == nil {
|
||||
@@ -2409,7 +2505,7 @@ func withMixinIDID(id uuid.UUID) mixinidOption {
|
||||
m.oldValue = func(ctx context.Context) (*MixinID, 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().MixinID.Get(ctx, id)
|
||||
}
|
||||
@@ -2442,7 +2538,7 @@ func (m MixinIDMutation) Client() *Client {
|
||||
// it returns an error otherwise.
|
||||
func (m MixinIDMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -2464,6 +2560,25 @@ func (m *MixinIDMutation) ID() (id uuid.UUID, 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 *MixinIDMutation) 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().MixinID.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetSomeField sets the "some_field" field.
|
||||
func (m *MixinIDMutation) SetSomeField(s string) {
|
||||
m.some_field = &s
|
||||
@@ -2483,10 +2598,10 @@ func (m *MixinIDMutation) SomeField() (r string, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *MixinIDMutation) OldSomeField(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldSomeField is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldSomeField is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldSomeField requires an ID field in the mutation")
|
||||
return v, errors.New("OldSomeField requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -2519,10 +2634,10 @@ func (m *MixinIDMutation) MixinField() (r string, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *MixinIDMutation) OldMixinField(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, fmt.Errorf("OldMixinField is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldMixinField is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, fmt.Errorf("OldMixinField requires an ID field in the mutation")
|
||||
return v, errors.New("OldMixinField requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
@@ -2765,7 +2880,7 @@ func withNoteID(id schema.NoteID) noteOption {
|
||||
m.oldValue = func(ctx context.Context) (*Note, 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().Note.Get(ctx, id)
|
||||
}
|
||||
@@ -2798,7 +2913,7 @@ func (m NoteMutation) Client() *Client {
|
||||
// it returns an error otherwise.
|
||||
func (m NoteMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -2820,6 +2935,25 @@ func (m *NoteMutation) ID() (id schema.NoteID, 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 *NoteMutation) IDs(ctx context.Context) ([]schema.NoteID, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []schema.NoteID{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Note.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (m *NoteMutation) SetText(s string) {
|
||||
m.text = &s
|
||||
@@ -2839,10 +2973,10 @@ func (m *NoteMutation) Text() (r string, exists bool) {
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NoteMutation) 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 {
|
||||
@@ -3241,7 +3375,7 @@ func withPetID(id string) 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)
|
||||
}
|
||||
@@ -3274,7 +3408,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("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -3296,6 +3430,25 @@ func (m *PetMutation) ID() (id string, 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) ([]string, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []string{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
|
||||
@@ -3763,7 +3916,7 @@ func withSessionID(id schema.ID) sessionOption {
|
||||
m.oldValue = func(ctx context.Context) (*Session, 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().Session.Get(ctx, id)
|
||||
}
|
||||
@@ -3796,7 +3949,7 @@ func (m SessionMutation) Client() *Client {
|
||||
// it returns an error otherwise.
|
||||
func (m SessionMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, fmt.Errorf("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -3818,6 +3971,25 @@ func (m *SessionMutation) ID() (id schema.ID, 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 *SessionMutation) IDs(ctx context.Context) ([]schema.ID, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []schema.ID{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Session.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetDeviceID sets the "device" edge to the Device entity by id.
|
||||
func (m *SessionMutation) SetDeviceID(id schema.ID) {
|
||||
m.device = &id
|
||||
@@ -4077,7 +4249,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)
|
||||
}
|
||||
@@ -4110,7 +4282,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("ent: mutation is not running in a transaction")
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
@@ -4132,6 +4304,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)
|
||||
}
|
||||
}
|
||||
|
||||
// AddGroupIDs adds the "groups" edge to the Group entity by ids.
|
||||
func (m *UserMutation) AddGroupIDs(ids ...int) {
|
||||
if m.groups == nil {
|
||||
|
||||
Reference in New Issue
Block a user