2951 lines
83 KiB
Go
2951 lines
83 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"sync"
|
|
"thesis/ent/blocks"
|
|
"thesis/ent/key"
|
|
"thesis/ent/predicate"
|
|
"thesis/ent/transactions"
|
|
"thesis/ent/validators"
|
|
"thesis/ent/whitelist"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
)
|
|
|
|
const (
|
|
// Operation types.
|
|
OpCreate = ent.OpCreate
|
|
OpDelete = ent.OpDelete
|
|
OpDeleteOne = ent.OpDeleteOne
|
|
OpUpdate = ent.OpUpdate
|
|
OpUpdateOne = ent.OpUpdateOne
|
|
|
|
// Node types.
|
|
TypeBlocks = "Blocks"
|
|
TypeKey = "Key"
|
|
TypeTransactions = "Transactions"
|
|
TypeValidators = "Validators"
|
|
TypeWhiteList = "WhiteList"
|
|
)
|
|
|
|
// BlocksMutation represents an operation that mutates the Blocks nodes in the graph.
|
|
type BlocksMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
hash *string
|
|
length *int
|
|
addlength *int
|
|
previousHash *string
|
|
clearedFields map[string]struct{}
|
|
_Caster map[int]struct{}
|
|
removed_Caster map[int]struct{}
|
|
cleared_Caster bool
|
|
_MinedTxs map[int]struct{}
|
|
removed_MinedTxs map[int]struct{}
|
|
cleared_MinedTxs bool
|
|
done bool
|
|
oldValue func(context.Context) (*Blocks, error)
|
|
predicates []predicate.Blocks
|
|
}
|
|
|
|
var _ ent.Mutation = (*BlocksMutation)(nil)
|
|
|
|
// blocksOption allows management of the mutation configuration using functional options.
|
|
type blocksOption func(*BlocksMutation)
|
|
|
|
// newBlocksMutation creates new mutation for the Blocks entity.
|
|
func newBlocksMutation(c config, op Op, opts ...blocksOption) *BlocksMutation {
|
|
m := &BlocksMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeBlocks,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withBlocksID sets the ID field of the mutation.
|
|
func withBlocksID(id int) blocksOption {
|
|
return func(m *BlocksMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Blocks
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Blocks, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Blocks.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withBlocks sets the old Blocks of the mutation.
|
|
func withBlocks(node *Blocks) blocksOption {
|
|
return func(m *BlocksMutation) {
|
|
m.oldValue = func(context.Context) (*Blocks, 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 BlocksMutation) 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 BlocksMutation) 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
|
|
}
|
|
|
|
// SetID sets the value of the id field. Note that this
|
|
// operation is only accepted on creation of Blocks entities.
|
|
func (m *BlocksMutation) SetID(id int) {
|
|
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 *BlocksMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *BlocksMutation) 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().Blocks.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetHash sets the "hash" field.
|
|
func (m *BlocksMutation) SetHash(s string) {
|
|
m.hash = &s
|
|
}
|
|
|
|
// Hash returns the value of the "hash" field in the mutation.
|
|
func (m *BlocksMutation) Hash() (r string, exists bool) {
|
|
v := m.hash
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldHash returns the old "hash" field's value of the Blocks entity.
|
|
// If the Blocks 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 *BlocksMutation) OldHash(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldHash is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldHash requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldHash: %w", err)
|
|
}
|
|
return oldValue.Hash, nil
|
|
}
|
|
|
|
// ResetHash resets all changes to the "hash" field.
|
|
func (m *BlocksMutation) ResetHash() {
|
|
m.hash = nil
|
|
}
|
|
|
|
// SetLength sets the "length" field.
|
|
func (m *BlocksMutation) SetLength(i int) {
|
|
m.length = &i
|
|
m.addlength = nil
|
|
}
|
|
|
|
// Length returns the value of the "length" field in the mutation.
|
|
func (m *BlocksMutation) Length() (r int, exists bool) {
|
|
v := m.length
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldLength returns the old "length" field's value of the Blocks entity.
|
|
// If the Blocks 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 *BlocksMutation) OldLength(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldLength is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldLength requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldLength: %w", err)
|
|
}
|
|
return oldValue.Length, nil
|
|
}
|
|
|
|
// AddLength adds i to the "length" field.
|
|
func (m *BlocksMutation) AddLength(i int) {
|
|
if m.addlength != nil {
|
|
*m.addlength += i
|
|
} else {
|
|
m.addlength = &i
|
|
}
|
|
}
|
|
|
|
// AddedLength returns the value that was added to the "length" field in this mutation.
|
|
func (m *BlocksMutation) AddedLength() (r int, exists bool) {
|
|
v := m.addlength
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetLength resets all changes to the "length" field.
|
|
func (m *BlocksMutation) ResetLength() {
|
|
m.length = nil
|
|
m.addlength = nil
|
|
}
|
|
|
|
// SetPreviousHash sets the "previousHash" field.
|
|
func (m *BlocksMutation) SetPreviousHash(s string) {
|
|
m.previousHash = &s
|
|
}
|
|
|
|
// PreviousHash returns the value of the "previousHash" field in the mutation.
|
|
func (m *BlocksMutation) PreviousHash() (r string, exists bool) {
|
|
v := m.previousHash
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldPreviousHash returns the old "previousHash" field's value of the Blocks entity.
|
|
// If the Blocks 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 *BlocksMutation) OldPreviousHash(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldPreviousHash is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldPreviousHash requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldPreviousHash: %w", err)
|
|
}
|
|
return oldValue.PreviousHash, nil
|
|
}
|
|
|
|
// ResetPreviousHash resets all changes to the "previousHash" field.
|
|
func (m *BlocksMutation) ResetPreviousHash() {
|
|
m.previousHash = nil
|
|
}
|
|
|
|
// AddCasterIDs adds the "Caster" edge to the Validators entity by ids.
|
|
func (m *BlocksMutation) AddCasterIDs(ids ...int) {
|
|
if m._Caster == nil {
|
|
m._Caster = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._Caster[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearCaster clears the "Caster" edge to the Validators entity.
|
|
func (m *BlocksMutation) ClearCaster() {
|
|
m.cleared_Caster = true
|
|
}
|
|
|
|
// CasterCleared reports if the "Caster" edge to the Validators entity was cleared.
|
|
func (m *BlocksMutation) CasterCleared() bool {
|
|
return m.cleared_Caster
|
|
}
|
|
|
|
// RemoveCasterIDs removes the "Caster" edge to the Validators entity by IDs.
|
|
func (m *BlocksMutation) RemoveCasterIDs(ids ...int) {
|
|
if m.removed_Caster == nil {
|
|
m.removed_Caster = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._Caster, ids[i])
|
|
m.removed_Caster[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedCaster returns the removed IDs of the "Caster" edge to the Validators entity.
|
|
func (m *BlocksMutation) RemovedCasterIDs() (ids []int) {
|
|
for id := range m.removed_Caster {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// CasterIDs returns the "Caster" edge IDs in the mutation.
|
|
func (m *BlocksMutation) CasterIDs() (ids []int) {
|
|
for id := range m._Caster {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetCaster resets all changes to the "Caster" edge.
|
|
func (m *BlocksMutation) ResetCaster() {
|
|
m._Caster = nil
|
|
m.cleared_Caster = false
|
|
m.removed_Caster = nil
|
|
}
|
|
|
|
// AddMinedTxIDs adds the "MinedTxs" edge to the Transactions entity by ids.
|
|
func (m *BlocksMutation) AddMinedTxIDs(ids ...int) {
|
|
if m._MinedTxs == nil {
|
|
m._MinedTxs = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._MinedTxs[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearMinedTxs clears the "MinedTxs" edge to the Transactions entity.
|
|
func (m *BlocksMutation) ClearMinedTxs() {
|
|
m.cleared_MinedTxs = true
|
|
}
|
|
|
|
// MinedTxsCleared reports if the "MinedTxs" edge to the Transactions entity was cleared.
|
|
func (m *BlocksMutation) MinedTxsCleared() bool {
|
|
return m.cleared_MinedTxs
|
|
}
|
|
|
|
// RemoveMinedTxIDs removes the "MinedTxs" edge to the Transactions entity by IDs.
|
|
func (m *BlocksMutation) RemoveMinedTxIDs(ids ...int) {
|
|
if m.removed_MinedTxs == nil {
|
|
m.removed_MinedTxs = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._MinedTxs, ids[i])
|
|
m.removed_MinedTxs[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedMinedTxs returns the removed IDs of the "MinedTxs" edge to the Transactions entity.
|
|
func (m *BlocksMutation) RemovedMinedTxsIDs() (ids []int) {
|
|
for id := range m.removed_MinedTxs {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// MinedTxsIDs returns the "MinedTxs" edge IDs in the mutation.
|
|
func (m *BlocksMutation) MinedTxsIDs() (ids []int) {
|
|
for id := range m._MinedTxs {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetMinedTxs resets all changes to the "MinedTxs" edge.
|
|
func (m *BlocksMutation) ResetMinedTxs() {
|
|
m._MinedTxs = nil
|
|
m.cleared_MinedTxs = false
|
|
m.removed_MinedTxs = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the BlocksMutation builder.
|
|
func (m *BlocksMutation) Where(ps ...predicate.Blocks) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the BlocksMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *BlocksMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Blocks, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *BlocksMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *BlocksMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Blocks).
|
|
func (m *BlocksMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *BlocksMutation) Fields() []string {
|
|
fields := make([]string, 0, 3)
|
|
if m.hash != nil {
|
|
fields = append(fields, blocks.FieldHash)
|
|
}
|
|
if m.length != nil {
|
|
fields = append(fields, blocks.FieldLength)
|
|
}
|
|
if m.previousHash != nil {
|
|
fields = append(fields, blocks.FieldPreviousHash)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *BlocksMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case blocks.FieldHash:
|
|
return m.Hash()
|
|
case blocks.FieldLength:
|
|
return m.Length()
|
|
case blocks.FieldPreviousHash:
|
|
return m.PreviousHash()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *BlocksMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case blocks.FieldHash:
|
|
return m.OldHash(ctx)
|
|
case blocks.FieldLength:
|
|
return m.OldLength(ctx)
|
|
case blocks.FieldPreviousHash:
|
|
return m.OldPreviousHash(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Blocks field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *BlocksMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case blocks.FieldHash:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetHash(v)
|
|
return nil
|
|
case blocks.FieldLength:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetLength(v)
|
|
return nil
|
|
case blocks.FieldPreviousHash:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetPreviousHash(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blocks field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *BlocksMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.addlength != nil {
|
|
fields = append(fields, blocks.FieldLength)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *BlocksMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case blocks.FieldLength:
|
|
return m.AddedLength()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *BlocksMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case blocks.FieldLength:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddLength(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blocks numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *BlocksMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *BlocksMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *BlocksMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Blocks nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *BlocksMutation) ResetField(name string) error {
|
|
switch name {
|
|
case blocks.FieldHash:
|
|
m.ResetHash()
|
|
return nil
|
|
case blocks.FieldLength:
|
|
m.ResetLength()
|
|
return nil
|
|
case blocks.FieldPreviousHash:
|
|
m.ResetPreviousHash()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blocks field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *BlocksMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m._Caster != nil {
|
|
edges = append(edges, blocks.EdgeCaster)
|
|
}
|
|
if m._MinedTxs != nil {
|
|
edges = append(edges, blocks.EdgeMinedTxs)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *BlocksMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case blocks.EdgeCaster:
|
|
ids := make([]ent.Value, 0, len(m._Caster))
|
|
for id := range m._Caster {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case blocks.EdgeMinedTxs:
|
|
ids := make([]ent.Value, 0, len(m._MinedTxs))
|
|
for id := range m._MinedTxs {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *BlocksMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.removed_Caster != nil {
|
|
edges = append(edges, blocks.EdgeCaster)
|
|
}
|
|
if m.removed_MinedTxs != nil {
|
|
edges = append(edges, blocks.EdgeMinedTxs)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *BlocksMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case blocks.EdgeCaster:
|
|
ids := make([]ent.Value, 0, len(m.removed_Caster))
|
|
for id := range m.removed_Caster {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case blocks.EdgeMinedTxs:
|
|
ids := make([]ent.Value, 0, len(m.removed_MinedTxs))
|
|
for id := range m.removed_MinedTxs {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *BlocksMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.cleared_Caster {
|
|
edges = append(edges, blocks.EdgeCaster)
|
|
}
|
|
if m.cleared_MinedTxs {
|
|
edges = append(edges, blocks.EdgeMinedTxs)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *BlocksMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case blocks.EdgeCaster:
|
|
return m.cleared_Caster
|
|
case blocks.EdgeMinedTxs:
|
|
return m.cleared_MinedTxs
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *BlocksMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Blocks unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *BlocksMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case blocks.EdgeCaster:
|
|
m.ResetCaster()
|
|
return nil
|
|
case blocks.EdgeMinedTxs:
|
|
m.ResetMinedTxs()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Blocks edge %s", name)
|
|
}
|
|
|
|
// KeyMutation represents an operation that mutates the Key nodes in the graph.
|
|
type KeyMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
publicKey *string
|
|
_Owner *string
|
|
trustScore *float64
|
|
addtrustScore *float64
|
|
clearedFields map[string]struct{}
|
|
_Signed map[int]struct{}
|
|
removed_Signed map[int]struct{}
|
|
cleared_Signed bool
|
|
done bool
|
|
oldValue func(context.Context) (*Key, error)
|
|
predicates []predicate.Key
|
|
}
|
|
|
|
var _ ent.Mutation = (*KeyMutation)(nil)
|
|
|
|
// keyOption allows management of the mutation configuration using functional options.
|
|
type keyOption func(*KeyMutation)
|
|
|
|
// newKeyMutation creates new mutation for the Key entity.
|
|
func newKeyMutation(c config, op Op, opts ...keyOption) *KeyMutation {
|
|
m := &KeyMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeKey,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withKeyID sets the ID field of the mutation.
|
|
func withKeyID(id int) keyOption {
|
|
return func(m *KeyMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Key
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Key, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Key.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withKey sets the old Key of the mutation.
|
|
func withKey(node *Key) keyOption {
|
|
return func(m *KeyMutation) {
|
|
m.oldValue = func(context.Context) (*Key, 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 KeyMutation) 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 KeyMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *KeyMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *KeyMutation) 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().Key.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetPublicKey sets the "publicKey" field.
|
|
func (m *KeyMutation) SetPublicKey(s string) {
|
|
m.publicKey = &s
|
|
}
|
|
|
|
// PublicKey returns the value of the "publicKey" field in the mutation.
|
|
func (m *KeyMutation) PublicKey() (r string, exists bool) {
|
|
v := m.publicKey
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldPublicKey returns the old "publicKey" field's value of the Key entity.
|
|
// If the Key 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 *KeyMutation) OldPublicKey(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldPublicKey is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldPublicKey requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldPublicKey: %w", err)
|
|
}
|
|
return oldValue.PublicKey, nil
|
|
}
|
|
|
|
// ResetPublicKey resets all changes to the "publicKey" field.
|
|
func (m *KeyMutation) ResetPublicKey() {
|
|
m.publicKey = nil
|
|
}
|
|
|
|
// SetOwner sets the "Owner" field.
|
|
func (m *KeyMutation) SetOwner(s string) {
|
|
m._Owner = &s
|
|
}
|
|
|
|
// Owner returns the value of the "Owner" field in the mutation.
|
|
func (m *KeyMutation) Owner() (r string, exists bool) {
|
|
v := m._Owner
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldOwner returns the old "Owner" field's value of the Key entity.
|
|
// If the Key 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 *KeyMutation) OldOwner(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldOwner is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldOwner requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldOwner: %w", err)
|
|
}
|
|
return oldValue.Owner, nil
|
|
}
|
|
|
|
// ResetOwner resets all changes to the "Owner" field.
|
|
func (m *KeyMutation) ResetOwner() {
|
|
m._Owner = nil
|
|
}
|
|
|
|
// SetTrustScore sets the "trustScore" field.
|
|
func (m *KeyMutation) SetTrustScore(f float64) {
|
|
m.trustScore = &f
|
|
m.addtrustScore = nil
|
|
}
|
|
|
|
// TrustScore returns the value of the "trustScore" field in the mutation.
|
|
func (m *KeyMutation) TrustScore() (r float64, exists bool) {
|
|
v := m.trustScore
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldTrustScore returns the old "trustScore" field's value of the Key entity.
|
|
// If the Key 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 *KeyMutation) OldTrustScore(ctx context.Context) (v float64, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldTrustScore is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldTrustScore requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldTrustScore: %w", err)
|
|
}
|
|
return oldValue.TrustScore, nil
|
|
}
|
|
|
|
// AddTrustScore adds f to the "trustScore" field.
|
|
func (m *KeyMutation) AddTrustScore(f float64) {
|
|
if m.addtrustScore != nil {
|
|
*m.addtrustScore += f
|
|
} else {
|
|
m.addtrustScore = &f
|
|
}
|
|
}
|
|
|
|
// AddedTrustScore returns the value that was added to the "trustScore" field in this mutation.
|
|
func (m *KeyMutation) AddedTrustScore() (r float64, exists bool) {
|
|
v := m.addtrustScore
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetTrustScore resets all changes to the "trustScore" field.
|
|
func (m *KeyMutation) ResetTrustScore() {
|
|
m.trustScore = nil
|
|
m.addtrustScore = nil
|
|
}
|
|
|
|
// AddSignedIDs adds the "Signed" edge to the Transactions entity by ids.
|
|
func (m *KeyMutation) AddSignedIDs(ids ...int) {
|
|
if m._Signed == nil {
|
|
m._Signed = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._Signed[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearSigned clears the "Signed" edge to the Transactions entity.
|
|
func (m *KeyMutation) ClearSigned() {
|
|
m.cleared_Signed = true
|
|
}
|
|
|
|
// SignedCleared reports if the "Signed" edge to the Transactions entity was cleared.
|
|
func (m *KeyMutation) SignedCleared() bool {
|
|
return m.cleared_Signed
|
|
}
|
|
|
|
// RemoveSignedIDs removes the "Signed" edge to the Transactions entity by IDs.
|
|
func (m *KeyMutation) RemoveSignedIDs(ids ...int) {
|
|
if m.removed_Signed == nil {
|
|
m.removed_Signed = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._Signed, ids[i])
|
|
m.removed_Signed[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedSigned returns the removed IDs of the "Signed" edge to the Transactions entity.
|
|
func (m *KeyMutation) RemovedSignedIDs() (ids []int) {
|
|
for id := range m.removed_Signed {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// SignedIDs returns the "Signed" edge IDs in the mutation.
|
|
func (m *KeyMutation) SignedIDs() (ids []int) {
|
|
for id := range m._Signed {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetSigned resets all changes to the "Signed" edge.
|
|
func (m *KeyMutation) ResetSigned() {
|
|
m._Signed = nil
|
|
m.cleared_Signed = false
|
|
m.removed_Signed = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the KeyMutation builder.
|
|
func (m *KeyMutation) Where(ps ...predicate.Key) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the KeyMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *KeyMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Key, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *KeyMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *KeyMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Key).
|
|
func (m *KeyMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *KeyMutation) Fields() []string {
|
|
fields := make([]string, 0, 3)
|
|
if m.publicKey != nil {
|
|
fields = append(fields, key.FieldPublicKey)
|
|
}
|
|
if m._Owner != nil {
|
|
fields = append(fields, key.FieldOwner)
|
|
}
|
|
if m.trustScore != nil {
|
|
fields = append(fields, key.FieldTrustScore)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *KeyMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case key.FieldPublicKey:
|
|
return m.PublicKey()
|
|
case key.FieldOwner:
|
|
return m.Owner()
|
|
case key.FieldTrustScore:
|
|
return m.TrustScore()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *KeyMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case key.FieldPublicKey:
|
|
return m.OldPublicKey(ctx)
|
|
case key.FieldOwner:
|
|
return m.OldOwner(ctx)
|
|
case key.FieldTrustScore:
|
|
return m.OldTrustScore(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Key field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *KeyMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case key.FieldPublicKey:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetPublicKey(v)
|
|
return nil
|
|
case key.FieldOwner:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetOwner(v)
|
|
return nil
|
|
case key.FieldTrustScore:
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetTrustScore(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Key field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *KeyMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.addtrustScore != nil {
|
|
fields = append(fields, key.FieldTrustScore)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *KeyMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case key.FieldTrustScore:
|
|
return m.AddedTrustScore()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *KeyMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case key.FieldTrustScore:
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddTrustScore(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Key numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *KeyMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *KeyMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *KeyMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Key nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *KeyMutation) ResetField(name string) error {
|
|
switch name {
|
|
case key.FieldPublicKey:
|
|
m.ResetPublicKey()
|
|
return nil
|
|
case key.FieldOwner:
|
|
m.ResetOwner()
|
|
return nil
|
|
case key.FieldTrustScore:
|
|
m.ResetTrustScore()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Key field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *KeyMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m._Signed != nil {
|
|
edges = append(edges, key.EdgeSigned)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *KeyMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case key.EdgeSigned:
|
|
ids := make([]ent.Value, 0, len(m._Signed))
|
|
for id := range m._Signed {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *KeyMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.removed_Signed != nil {
|
|
edges = append(edges, key.EdgeSigned)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *KeyMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case key.EdgeSigned:
|
|
ids := make([]ent.Value, 0, len(m.removed_Signed))
|
|
for id := range m.removed_Signed {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *KeyMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.cleared_Signed {
|
|
edges = append(edges, key.EdgeSigned)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *KeyMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case key.EdgeSigned:
|
|
return m.cleared_Signed
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *KeyMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Key unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *KeyMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case key.EdgeSigned:
|
|
m.ResetSigned()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Key edge %s", name)
|
|
}
|
|
|
|
// TransactionsMutation represents an operation that mutates the Transactions nodes in the graph.
|
|
type TransactionsMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
_type *int
|
|
add_type *int
|
|
timestamp *int
|
|
addtimestamp *int
|
|
comment *string
|
|
content *[]byte
|
|
hash *string
|
|
signature *string
|
|
clearedFields map[string]struct{}
|
|
_Signer map[int]struct{}
|
|
removed_Signer map[int]struct{}
|
|
cleared_Signer bool
|
|
_Block map[int]struct{}
|
|
removed_Block map[int]struct{}
|
|
cleared_Block bool
|
|
done bool
|
|
oldValue func(context.Context) (*Transactions, error)
|
|
predicates []predicate.Transactions
|
|
}
|
|
|
|
var _ ent.Mutation = (*TransactionsMutation)(nil)
|
|
|
|
// transactionsOption allows management of the mutation configuration using functional options.
|
|
type transactionsOption func(*TransactionsMutation)
|
|
|
|
// newTransactionsMutation creates new mutation for the Transactions entity.
|
|
func newTransactionsMutation(c config, op Op, opts ...transactionsOption) *TransactionsMutation {
|
|
m := &TransactionsMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeTransactions,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withTransactionsID sets the ID field of the mutation.
|
|
func withTransactionsID(id int) transactionsOption {
|
|
return func(m *TransactionsMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Transactions
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Transactions, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Transactions.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withTransactions sets the old Transactions of the mutation.
|
|
func withTransactions(node *Transactions) transactionsOption {
|
|
return func(m *TransactionsMutation) {
|
|
m.oldValue = func(context.Context) (*Transactions, 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 TransactionsMutation) 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 TransactionsMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *TransactionsMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *TransactionsMutation) 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().Transactions.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (m *TransactionsMutation) SetType(i int) {
|
|
m._type = &i
|
|
m.add_type = nil
|
|
}
|
|
|
|
// GetType returns the value of the "type" field in the mutation.
|
|
func (m *TransactionsMutation) GetType() (r int, exists bool) {
|
|
v := m._type
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldType returns the old "type" field's value of the Transactions entity.
|
|
// If the Transactions 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 *TransactionsMutation) OldType(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldType is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldType requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldType: %w", err)
|
|
}
|
|
return oldValue.Type, nil
|
|
}
|
|
|
|
// AddType adds i to the "type" field.
|
|
func (m *TransactionsMutation) AddType(i int) {
|
|
if m.add_type != nil {
|
|
*m.add_type += i
|
|
} else {
|
|
m.add_type = &i
|
|
}
|
|
}
|
|
|
|
// AddedType returns the value that was added to the "type" field in this mutation.
|
|
func (m *TransactionsMutation) AddedType() (r int, exists bool) {
|
|
v := m.add_type
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetType resets all changes to the "type" field.
|
|
func (m *TransactionsMutation) ResetType() {
|
|
m._type = nil
|
|
m.add_type = nil
|
|
}
|
|
|
|
// SetTimestamp sets the "timestamp" field.
|
|
func (m *TransactionsMutation) SetTimestamp(i int) {
|
|
m.timestamp = &i
|
|
m.addtimestamp = nil
|
|
}
|
|
|
|
// Timestamp returns the value of the "timestamp" field in the mutation.
|
|
func (m *TransactionsMutation) Timestamp() (r int, exists bool) {
|
|
v := m.timestamp
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldTimestamp returns the old "timestamp" field's value of the Transactions entity.
|
|
// If the Transactions 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 *TransactionsMutation) OldTimestamp(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldTimestamp is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldTimestamp requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldTimestamp: %w", err)
|
|
}
|
|
return oldValue.Timestamp, nil
|
|
}
|
|
|
|
// AddTimestamp adds i to the "timestamp" field.
|
|
func (m *TransactionsMutation) AddTimestamp(i int) {
|
|
if m.addtimestamp != nil {
|
|
*m.addtimestamp += i
|
|
} else {
|
|
m.addtimestamp = &i
|
|
}
|
|
}
|
|
|
|
// AddedTimestamp returns the value that was added to the "timestamp" field in this mutation.
|
|
func (m *TransactionsMutation) AddedTimestamp() (r int, exists bool) {
|
|
v := m.addtimestamp
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetTimestamp resets all changes to the "timestamp" field.
|
|
func (m *TransactionsMutation) ResetTimestamp() {
|
|
m.timestamp = nil
|
|
m.addtimestamp = nil
|
|
}
|
|
|
|
// SetComment sets the "comment" field.
|
|
func (m *TransactionsMutation) SetComment(s string) {
|
|
m.comment = &s
|
|
}
|
|
|
|
// Comment returns the value of the "comment" field in the mutation.
|
|
func (m *TransactionsMutation) Comment() (r string, exists bool) {
|
|
v := m.comment
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldComment returns the old "comment" field's value of the Transactions entity.
|
|
// If the Transactions 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 *TransactionsMutation) OldComment(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldComment is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldComment requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldComment: %w", err)
|
|
}
|
|
return oldValue.Comment, nil
|
|
}
|
|
|
|
// ResetComment resets all changes to the "comment" field.
|
|
func (m *TransactionsMutation) ResetComment() {
|
|
m.comment = nil
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (m *TransactionsMutation) SetContent(b []byte) {
|
|
m.content = &b
|
|
}
|
|
|
|
// Content returns the value of the "content" field in the mutation.
|
|
func (m *TransactionsMutation) Content() (r []byte, exists bool) {
|
|
v := m.content
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldContent returns the old "content" field's value of the Transactions entity.
|
|
// If the Transactions 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 *TransactionsMutation) OldContent(ctx context.Context) (v []byte, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldContent is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldContent requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldContent: %w", err)
|
|
}
|
|
return oldValue.Content, nil
|
|
}
|
|
|
|
// ResetContent resets all changes to the "content" field.
|
|
func (m *TransactionsMutation) ResetContent() {
|
|
m.content = nil
|
|
}
|
|
|
|
// SetHash sets the "hash" field.
|
|
func (m *TransactionsMutation) SetHash(s string) {
|
|
m.hash = &s
|
|
}
|
|
|
|
// Hash returns the value of the "hash" field in the mutation.
|
|
func (m *TransactionsMutation) Hash() (r string, exists bool) {
|
|
v := m.hash
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldHash returns the old "hash" field's value of the Transactions entity.
|
|
// If the Transactions 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 *TransactionsMutation) OldHash(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldHash is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldHash requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldHash: %w", err)
|
|
}
|
|
return oldValue.Hash, nil
|
|
}
|
|
|
|
// ResetHash resets all changes to the "hash" field.
|
|
func (m *TransactionsMutation) ResetHash() {
|
|
m.hash = nil
|
|
}
|
|
|
|
// SetSignature sets the "signature" field.
|
|
func (m *TransactionsMutation) SetSignature(s string) {
|
|
m.signature = &s
|
|
}
|
|
|
|
// Signature returns the value of the "signature" field in the mutation.
|
|
func (m *TransactionsMutation) Signature() (r string, exists bool) {
|
|
v := m.signature
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldSignature returns the old "signature" field's value of the Transactions entity.
|
|
// If the Transactions 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 *TransactionsMutation) OldSignature(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldSignature is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldSignature requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldSignature: %w", err)
|
|
}
|
|
return oldValue.Signature, nil
|
|
}
|
|
|
|
// ResetSignature resets all changes to the "signature" field.
|
|
func (m *TransactionsMutation) ResetSignature() {
|
|
m.signature = nil
|
|
}
|
|
|
|
// AddSignerIDs adds the "Signer" edge to the Key entity by ids.
|
|
func (m *TransactionsMutation) AddSignerIDs(ids ...int) {
|
|
if m._Signer == nil {
|
|
m._Signer = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._Signer[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearSigner clears the "Signer" edge to the Key entity.
|
|
func (m *TransactionsMutation) ClearSigner() {
|
|
m.cleared_Signer = true
|
|
}
|
|
|
|
// SignerCleared reports if the "Signer" edge to the Key entity was cleared.
|
|
func (m *TransactionsMutation) SignerCleared() bool {
|
|
return m.cleared_Signer
|
|
}
|
|
|
|
// RemoveSignerIDs removes the "Signer" edge to the Key entity by IDs.
|
|
func (m *TransactionsMutation) RemoveSignerIDs(ids ...int) {
|
|
if m.removed_Signer == nil {
|
|
m.removed_Signer = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._Signer, ids[i])
|
|
m.removed_Signer[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedSigner returns the removed IDs of the "Signer" edge to the Key entity.
|
|
func (m *TransactionsMutation) RemovedSignerIDs() (ids []int) {
|
|
for id := range m.removed_Signer {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// SignerIDs returns the "Signer" edge IDs in the mutation.
|
|
func (m *TransactionsMutation) SignerIDs() (ids []int) {
|
|
for id := range m._Signer {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetSigner resets all changes to the "Signer" edge.
|
|
func (m *TransactionsMutation) ResetSigner() {
|
|
m._Signer = nil
|
|
m.cleared_Signer = false
|
|
m.removed_Signer = nil
|
|
}
|
|
|
|
// AddBlockIDs adds the "Block" edge to the Blocks entity by ids.
|
|
func (m *TransactionsMutation) AddBlockIDs(ids ...int) {
|
|
if m._Block == nil {
|
|
m._Block = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._Block[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearBlock clears the "Block" edge to the Blocks entity.
|
|
func (m *TransactionsMutation) ClearBlock() {
|
|
m.cleared_Block = true
|
|
}
|
|
|
|
// BlockCleared reports if the "Block" edge to the Blocks entity was cleared.
|
|
func (m *TransactionsMutation) BlockCleared() bool {
|
|
return m.cleared_Block
|
|
}
|
|
|
|
// RemoveBlockIDs removes the "Block" edge to the Blocks entity by IDs.
|
|
func (m *TransactionsMutation) RemoveBlockIDs(ids ...int) {
|
|
if m.removed_Block == nil {
|
|
m.removed_Block = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._Block, ids[i])
|
|
m.removed_Block[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedBlock returns the removed IDs of the "Block" edge to the Blocks entity.
|
|
func (m *TransactionsMutation) RemovedBlockIDs() (ids []int) {
|
|
for id := range m.removed_Block {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// BlockIDs returns the "Block" edge IDs in the mutation.
|
|
func (m *TransactionsMutation) BlockIDs() (ids []int) {
|
|
for id := range m._Block {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetBlock resets all changes to the "Block" edge.
|
|
func (m *TransactionsMutation) ResetBlock() {
|
|
m._Block = nil
|
|
m.cleared_Block = false
|
|
m.removed_Block = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the TransactionsMutation builder.
|
|
func (m *TransactionsMutation) Where(ps ...predicate.Transactions) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the TransactionsMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *TransactionsMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Transactions, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *TransactionsMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *TransactionsMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Transactions).
|
|
func (m *TransactionsMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *TransactionsMutation) Fields() []string {
|
|
fields := make([]string, 0, 6)
|
|
if m._type != nil {
|
|
fields = append(fields, transactions.FieldType)
|
|
}
|
|
if m.timestamp != nil {
|
|
fields = append(fields, transactions.FieldTimestamp)
|
|
}
|
|
if m.comment != nil {
|
|
fields = append(fields, transactions.FieldComment)
|
|
}
|
|
if m.content != nil {
|
|
fields = append(fields, transactions.FieldContent)
|
|
}
|
|
if m.hash != nil {
|
|
fields = append(fields, transactions.FieldHash)
|
|
}
|
|
if m.signature != nil {
|
|
fields = append(fields, transactions.FieldSignature)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *TransactionsMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case transactions.FieldType:
|
|
return m.GetType()
|
|
case transactions.FieldTimestamp:
|
|
return m.Timestamp()
|
|
case transactions.FieldComment:
|
|
return m.Comment()
|
|
case transactions.FieldContent:
|
|
return m.Content()
|
|
case transactions.FieldHash:
|
|
return m.Hash()
|
|
case transactions.FieldSignature:
|
|
return m.Signature()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *TransactionsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case transactions.FieldType:
|
|
return m.OldType(ctx)
|
|
case transactions.FieldTimestamp:
|
|
return m.OldTimestamp(ctx)
|
|
case transactions.FieldComment:
|
|
return m.OldComment(ctx)
|
|
case transactions.FieldContent:
|
|
return m.OldContent(ctx)
|
|
case transactions.FieldHash:
|
|
return m.OldHash(ctx)
|
|
case transactions.FieldSignature:
|
|
return m.OldSignature(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Transactions field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *TransactionsMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case transactions.FieldType:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetType(v)
|
|
return nil
|
|
case transactions.FieldTimestamp:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetTimestamp(v)
|
|
return nil
|
|
case transactions.FieldComment:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetComment(v)
|
|
return nil
|
|
case transactions.FieldContent:
|
|
v, ok := value.([]byte)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetContent(v)
|
|
return nil
|
|
case transactions.FieldHash:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetHash(v)
|
|
return nil
|
|
case transactions.FieldSignature:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetSignature(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Transactions field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *TransactionsMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.add_type != nil {
|
|
fields = append(fields, transactions.FieldType)
|
|
}
|
|
if m.addtimestamp != nil {
|
|
fields = append(fields, transactions.FieldTimestamp)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *TransactionsMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case transactions.FieldType:
|
|
return m.AddedType()
|
|
case transactions.FieldTimestamp:
|
|
return m.AddedTimestamp()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *TransactionsMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case transactions.FieldType:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddType(v)
|
|
return nil
|
|
case transactions.FieldTimestamp:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddTimestamp(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Transactions numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *TransactionsMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *TransactionsMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *TransactionsMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Transactions nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *TransactionsMutation) ResetField(name string) error {
|
|
switch name {
|
|
case transactions.FieldType:
|
|
m.ResetType()
|
|
return nil
|
|
case transactions.FieldTimestamp:
|
|
m.ResetTimestamp()
|
|
return nil
|
|
case transactions.FieldComment:
|
|
m.ResetComment()
|
|
return nil
|
|
case transactions.FieldContent:
|
|
m.ResetContent()
|
|
return nil
|
|
case transactions.FieldHash:
|
|
m.ResetHash()
|
|
return nil
|
|
case transactions.FieldSignature:
|
|
m.ResetSignature()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Transactions field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *TransactionsMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m._Signer != nil {
|
|
edges = append(edges, transactions.EdgeSigner)
|
|
}
|
|
if m._Block != nil {
|
|
edges = append(edges, transactions.EdgeBlock)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *TransactionsMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case transactions.EdgeSigner:
|
|
ids := make([]ent.Value, 0, len(m._Signer))
|
|
for id := range m._Signer {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case transactions.EdgeBlock:
|
|
ids := make([]ent.Value, 0, len(m._Block))
|
|
for id := range m._Block {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *TransactionsMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.removed_Signer != nil {
|
|
edges = append(edges, transactions.EdgeSigner)
|
|
}
|
|
if m.removed_Block != nil {
|
|
edges = append(edges, transactions.EdgeBlock)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *TransactionsMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case transactions.EdgeSigner:
|
|
ids := make([]ent.Value, 0, len(m.removed_Signer))
|
|
for id := range m.removed_Signer {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case transactions.EdgeBlock:
|
|
ids := make([]ent.Value, 0, len(m.removed_Block))
|
|
for id := range m.removed_Block {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *TransactionsMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.cleared_Signer {
|
|
edges = append(edges, transactions.EdgeSigner)
|
|
}
|
|
if m.cleared_Block {
|
|
edges = append(edges, transactions.EdgeBlock)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *TransactionsMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case transactions.EdgeSigner:
|
|
return m.cleared_Signer
|
|
case transactions.EdgeBlock:
|
|
return m.cleared_Block
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *TransactionsMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Transactions unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *TransactionsMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case transactions.EdgeSigner:
|
|
m.ResetSigner()
|
|
return nil
|
|
case transactions.EdgeBlock:
|
|
m.ResetBlock()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Transactions edge %s", name)
|
|
}
|
|
|
|
// ValidatorsMutation represents an operation that mutates the Validators nodes in the graph.
|
|
type ValidatorsMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
facilitator *string
|
|
clearedFields map[string]struct{}
|
|
key map[int]struct{}
|
|
removedkey map[int]struct{}
|
|
clearedkey bool
|
|
done bool
|
|
oldValue func(context.Context) (*Validators, error)
|
|
predicates []predicate.Validators
|
|
}
|
|
|
|
var _ ent.Mutation = (*ValidatorsMutation)(nil)
|
|
|
|
// validatorsOption allows management of the mutation configuration using functional options.
|
|
type validatorsOption func(*ValidatorsMutation)
|
|
|
|
// newValidatorsMutation creates new mutation for the Validators entity.
|
|
func newValidatorsMutation(c config, op Op, opts ...validatorsOption) *ValidatorsMutation {
|
|
m := &ValidatorsMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeValidators,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withValidatorsID sets the ID field of the mutation.
|
|
func withValidatorsID(id int) validatorsOption {
|
|
return func(m *ValidatorsMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Validators
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Validators, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Validators.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withValidators sets the old Validators of the mutation.
|
|
func withValidators(node *Validators) validatorsOption {
|
|
return func(m *ValidatorsMutation) {
|
|
m.oldValue = func(context.Context) (*Validators, 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 ValidatorsMutation) 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 ValidatorsMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *ValidatorsMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *ValidatorsMutation) 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().Validators.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetFacilitator sets the "facilitator" field.
|
|
func (m *ValidatorsMutation) SetFacilitator(s string) {
|
|
m.facilitator = &s
|
|
}
|
|
|
|
// Facilitator returns the value of the "facilitator" field in the mutation.
|
|
func (m *ValidatorsMutation) Facilitator() (r string, exists bool) {
|
|
v := m.facilitator
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldFacilitator returns the old "facilitator" field's value of the Validators entity.
|
|
// If the Validators 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 *ValidatorsMutation) OldFacilitator(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldFacilitator is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldFacilitator requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldFacilitator: %w", err)
|
|
}
|
|
return oldValue.Facilitator, nil
|
|
}
|
|
|
|
// ResetFacilitator resets all changes to the "facilitator" field.
|
|
func (m *ValidatorsMutation) ResetFacilitator() {
|
|
m.facilitator = nil
|
|
}
|
|
|
|
// AddKeyIDs adds the "key" edge to the Key entity by ids.
|
|
func (m *ValidatorsMutation) AddKeyIDs(ids ...int) {
|
|
if m.key == nil {
|
|
m.key = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m.key[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearKey clears the "key" edge to the Key entity.
|
|
func (m *ValidatorsMutation) ClearKey() {
|
|
m.clearedkey = true
|
|
}
|
|
|
|
// KeyCleared reports if the "key" edge to the Key entity was cleared.
|
|
func (m *ValidatorsMutation) KeyCleared() bool {
|
|
return m.clearedkey
|
|
}
|
|
|
|
// RemoveKeyIDs removes the "key" edge to the Key entity by IDs.
|
|
func (m *ValidatorsMutation) RemoveKeyIDs(ids ...int) {
|
|
if m.removedkey == nil {
|
|
m.removedkey = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m.key, ids[i])
|
|
m.removedkey[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedKey returns the removed IDs of the "key" edge to the Key entity.
|
|
func (m *ValidatorsMutation) RemovedKeyIDs() (ids []int) {
|
|
for id := range m.removedkey {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// KeyIDs returns the "key" edge IDs in the mutation.
|
|
func (m *ValidatorsMutation) KeyIDs() (ids []int) {
|
|
for id := range m.key {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetKey resets all changes to the "key" edge.
|
|
func (m *ValidatorsMutation) ResetKey() {
|
|
m.key = nil
|
|
m.clearedkey = false
|
|
m.removedkey = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the ValidatorsMutation builder.
|
|
func (m *ValidatorsMutation) Where(ps ...predicate.Validators) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the ValidatorsMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *ValidatorsMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Validators, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *ValidatorsMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *ValidatorsMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Validators).
|
|
func (m *ValidatorsMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *ValidatorsMutation) Fields() []string {
|
|
fields := make([]string, 0, 1)
|
|
if m.facilitator != nil {
|
|
fields = append(fields, validators.FieldFacilitator)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *ValidatorsMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case validators.FieldFacilitator:
|
|
return m.Facilitator()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *ValidatorsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case validators.FieldFacilitator:
|
|
return m.OldFacilitator(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Validators field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *ValidatorsMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case validators.FieldFacilitator:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetFacilitator(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Validators field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *ValidatorsMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *ValidatorsMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *ValidatorsMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Validators numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *ValidatorsMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *ValidatorsMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *ValidatorsMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Validators nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *ValidatorsMutation) ResetField(name string) error {
|
|
switch name {
|
|
case validators.FieldFacilitator:
|
|
m.ResetFacilitator()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Validators field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *ValidatorsMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.key != nil {
|
|
edges = append(edges, validators.EdgeKey)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *ValidatorsMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case validators.EdgeKey:
|
|
ids := make([]ent.Value, 0, len(m.key))
|
|
for id := range m.key {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *ValidatorsMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.removedkey != nil {
|
|
edges = append(edges, validators.EdgeKey)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *ValidatorsMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case validators.EdgeKey:
|
|
ids := make([]ent.Value, 0, len(m.removedkey))
|
|
for id := range m.removedkey {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *ValidatorsMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.clearedkey {
|
|
edges = append(edges, validators.EdgeKey)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *ValidatorsMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case validators.EdgeKey:
|
|
return m.clearedkey
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *ValidatorsMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Validators unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *ValidatorsMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case validators.EdgeKey:
|
|
m.ResetKey()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Validators edge %s", name)
|
|
}
|
|
|
|
// WhiteListMutation represents an operation that mutates the WhiteList nodes in the graph.
|
|
type WhiteListMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
clearedFields map[string]struct{}
|
|
_Sponsor map[int]struct{}
|
|
removed_Sponsor map[int]struct{}
|
|
cleared_Sponsor bool
|
|
_Account map[int]struct{}
|
|
removed_Account map[int]struct{}
|
|
cleared_Account bool
|
|
done bool
|
|
oldValue func(context.Context) (*WhiteList, error)
|
|
predicates []predicate.WhiteList
|
|
}
|
|
|
|
var _ ent.Mutation = (*WhiteListMutation)(nil)
|
|
|
|
// whitelistOption allows management of the mutation configuration using functional options.
|
|
type whitelistOption func(*WhiteListMutation)
|
|
|
|
// newWhiteListMutation creates new mutation for the WhiteList entity.
|
|
func newWhiteListMutation(c config, op Op, opts ...whitelistOption) *WhiteListMutation {
|
|
m := &WhiteListMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeWhiteList,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withWhiteListID sets the ID field of the mutation.
|
|
func withWhiteListID(id int) whitelistOption {
|
|
return func(m *WhiteListMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *WhiteList
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*WhiteList, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().WhiteList.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withWhiteList sets the old WhiteList of the mutation.
|
|
func withWhiteList(node *WhiteList) whitelistOption {
|
|
return func(m *WhiteListMutation) {
|
|
m.oldValue = func(context.Context) (*WhiteList, 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 WhiteListMutation) 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 WhiteListMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *WhiteListMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *WhiteListMutation) 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().WhiteList.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// AddSponsorIDs adds the "Sponsor" edge to the Validators entity by ids.
|
|
func (m *WhiteListMutation) AddSponsorIDs(ids ...int) {
|
|
if m._Sponsor == nil {
|
|
m._Sponsor = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._Sponsor[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearSponsor clears the "Sponsor" edge to the Validators entity.
|
|
func (m *WhiteListMutation) ClearSponsor() {
|
|
m.cleared_Sponsor = true
|
|
}
|
|
|
|
// SponsorCleared reports if the "Sponsor" edge to the Validators entity was cleared.
|
|
func (m *WhiteListMutation) SponsorCleared() bool {
|
|
return m.cleared_Sponsor
|
|
}
|
|
|
|
// RemoveSponsorIDs removes the "Sponsor" edge to the Validators entity by IDs.
|
|
func (m *WhiteListMutation) RemoveSponsorIDs(ids ...int) {
|
|
if m.removed_Sponsor == nil {
|
|
m.removed_Sponsor = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._Sponsor, ids[i])
|
|
m.removed_Sponsor[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedSponsor returns the removed IDs of the "Sponsor" edge to the Validators entity.
|
|
func (m *WhiteListMutation) RemovedSponsorIDs() (ids []int) {
|
|
for id := range m.removed_Sponsor {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// SponsorIDs returns the "Sponsor" edge IDs in the mutation.
|
|
func (m *WhiteListMutation) SponsorIDs() (ids []int) {
|
|
for id := range m._Sponsor {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetSponsor resets all changes to the "Sponsor" edge.
|
|
func (m *WhiteListMutation) ResetSponsor() {
|
|
m._Sponsor = nil
|
|
m.cleared_Sponsor = false
|
|
m.removed_Sponsor = nil
|
|
}
|
|
|
|
// AddAccountIDs adds the "Account" edge to the Key entity by ids.
|
|
func (m *WhiteListMutation) AddAccountIDs(ids ...int) {
|
|
if m._Account == nil {
|
|
m._Account = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
m._Account[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// ClearAccount clears the "Account" edge to the Key entity.
|
|
func (m *WhiteListMutation) ClearAccount() {
|
|
m.cleared_Account = true
|
|
}
|
|
|
|
// AccountCleared reports if the "Account" edge to the Key entity was cleared.
|
|
func (m *WhiteListMutation) AccountCleared() bool {
|
|
return m.cleared_Account
|
|
}
|
|
|
|
// RemoveAccountIDs removes the "Account" edge to the Key entity by IDs.
|
|
func (m *WhiteListMutation) RemoveAccountIDs(ids ...int) {
|
|
if m.removed_Account == nil {
|
|
m.removed_Account = make(map[int]struct{})
|
|
}
|
|
for i := range ids {
|
|
delete(m._Account, ids[i])
|
|
m.removed_Account[ids[i]] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// RemovedAccount returns the removed IDs of the "Account" edge to the Key entity.
|
|
func (m *WhiteListMutation) RemovedAccountIDs() (ids []int) {
|
|
for id := range m.removed_Account {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// AccountIDs returns the "Account" edge IDs in the mutation.
|
|
func (m *WhiteListMutation) AccountIDs() (ids []int) {
|
|
for id := range m._Account {
|
|
ids = append(ids, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetAccount resets all changes to the "Account" edge.
|
|
func (m *WhiteListMutation) ResetAccount() {
|
|
m._Account = nil
|
|
m.cleared_Account = false
|
|
m.removed_Account = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the WhiteListMutation builder.
|
|
func (m *WhiteListMutation) Where(ps ...predicate.WhiteList) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the WhiteListMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *WhiteListMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.WhiteList, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *WhiteListMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *WhiteListMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (WhiteList).
|
|
func (m *WhiteListMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *WhiteListMutation) Fields() []string {
|
|
fields := make([]string, 0, 0)
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *WhiteListMutation) Field(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *WhiteListMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
return nil, fmt.Errorf("unknown WhiteList field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *WhiteListMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown WhiteList field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *WhiteListMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *WhiteListMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *WhiteListMutation) AddField(name string, value ent.Value) error {
|
|
return fmt.Errorf("unknown WhiteList numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *WhiteListMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *WhiteListMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *WhiteListMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown WhiteList nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *WhiteListMutation) ResetField(name string) error {
|
|
return fmt.Errorf("unknown WhiteList field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *WhiteListMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m._Sponsor != nil {
|
|
edges = append(edges, whitelist.EdgeSponsor)
|
|
}
|
|
if m._Account != nil {
|
|
edges = append(edges, whitelist.EdgeAccount)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *WhiteListMutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case whitelist.EdgeSponsor:
|
|
ids := make([]ent.Value, 0, len(m._Sponsor))
|
|
for id := range m._Sponsor {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case whitelist.EdgeAccount:
|
|
ids := make([]ent.Value, 0, len(m._Account))
|
|
for id := range m._Account {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *WhiteListMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.removed_Sponsor != nil {
|
|
edges = append(edges, whitelist.EdgeSponsor)
|
|
}
|
|
if m.removed_Account != nil {
|
|
edges = append(edges, whitelist.EdgeAccount)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *WhiteListMutation) RemovedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case whitelist.EdgeSponsor:
|
|
ids := make([]ent.Value, 0, len(m.removed_Sponsor))
|
|
for id := range m.removed_Sponsor {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
case whitelist.EdgeAccount:
|
|
ids := make([]ent.Value, 0, len(m.removed_Account))
|
|
for id := range m.removed_Account {
|
|
ids = append(ids, id)
|
|
}
|
|
return ids
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *WhiteListMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 2)
|
|
if m.cleared_Sponsor {
|
|
edges = append(edges, whitelist.EdgeSponsor)
|
|
}
|
|
if m.cleared_Account {
|
|
edges = append(edges, whitelist.EdgeAccount)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *WhiteListMutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case whitelist.EdgeSponsor:
|
|
return m.cleared_Sponsor
|
|
case whitelist.EdgeAccount:
|
|
return m.cleared_Account
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *WhiteListMutation) ClearEdge(name string) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown WhiteList unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *WhiteListMutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case whitelist.EdgeSponsor:
|
|
m.ResetSponsor()
|
|
return nil
|
|
case whitelist.EdgeAccount:
|
|
m.ResetAccount()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown WhiteList edge %s", name)
|
|
}
|