zkt24/z2/backend/ent/blocks_update.go
2024-04-25 13:51:47 +02:00

624 lines
18 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"thesis/ent/blocks"
"thesis/ent/predicate"
"thesis/ent/transactions"
"thesis/ent/validators"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// BlocksUpdate is the builder for updating Blocks entities.
type BlocksUpdate struct {
config
hooks []Hook
mutation *BlocksMutation
}
// Where appends a list predicates to the BlocksUpdate builder.
func (bu *BlocksUpdate) Where(ps ...predicate.Blocks) *BlocksUpdate {
bu.mutation.Where(ps...)
return bu
}
// SetHash sets the "hash" field.
func (bu *BlocksUpdate) SetHash(s string) *BlocksUpdate {
bu.mutation.SetHash(s)
return bu
}
// SetNillableHash sets the "hash" field if the given value is not nil.
func (bu *BlocksUpdate) SetNillableHash(s *string) *BlocksUpdate {
if s != nil {
bu.SetHash(*s)
}
return bu
}
// SetLength sets the "length" field.
func (bu *BlocksUpdate) SetLength(i int) *BlocksUpdate {
bu.mutation.ResetLength()
bu.mutation.SetLength(i)
return bu
}
// SetNillableLength sets the "length" field if the given value is not nil.
func (bu *BlocksUpdate) SetNillableLength(i *int) *BlocksUpdate {
if i != nil {
bu.SetLength(*i)
}
return bu
}
// AddLength adds i to the "length" field.
func (bu *BlocksUpdate) AddLength(i int) *BlocksUpdate {
bu.mutation.AddLength(i)
return bu
}
// SetPreviousHash sets the "previousHash" field.
func (bu *BlocksUpdate) SetPreviousHash(s string) *BlocksUpdate {
bu.mutation.SetPreviousHash(s)
return bu
}
// SetNillablePreviousHash sets the "previousHash" field if the given value is not nil.
func (bu *BlocksUpdate) SetNillablePreviousHash(s *string) *BlocksUpdate {
if s != nil {
bu.SetPreviousHash(*s)
}
return bu
}
// AddCasterIDs adds the "Caster" edge to the Validators entity by IDs.
func (bu *BlocksUpdate) AddCasterIDs(ids ...int) *BlocksUpdate {
bu.mutation.AddCasterIDs(ids...)
return bu
}
// AddCaster adds the "Caster" edges to the Validators entity.
func (bu *BlocksUpdate) AddCaster(v ...*Validators) *BlocksUpdate {
ids := make([]int, len(v))
for i := range v {
ids[i] = v[i].ID
}
return bu.AddCasterIDs(ids...)
}
// AddMinedTxIDs adds the "MinedTxs" edge to the Transactions entity by IDs.
func (bu *BlocksUpdate) AddMinedTxIDs(ids ...int) *BlocksUpdate {
bu.mutation.AddMinedTxIDs(ids...)
return bu
}
// AddMinedTxs adds the "MinedTxs" edges to the Transactions entity.
func (bu *BlocksUpdate) AddMinedTxs(t ...*Transactions) *BlocksUpdate {
ids := make([]int, len(t))
for i := range t {
ids[i] = t[i].ID
}
return bu.AddMinedTxIDs(ids...)
}
// Mutation returns the BlocksMutation object of the builder.
func (bu *BlocksUpdate) Mutation() *BlocksMutation {
return bu.mutation
}
// ClearCaster clears all "Caster" edges to the Validators entity.
func (bu *BlocksUpdate) ClearCaster() *BlocksUpdate {
bu.mutation.ClearCaster()
return bu
}
// RemoveCasterIDs removes the "Caster" edge to Validators entities by IDs.
func (bu *BlocksUpdate) RemoveCasterIDs(ids ...int) *BlocksUpdate {
bu.mutation.RemoveCasterIDs(ids...)
return bu
}
// RemoveCaster removes "Caster" edges to Validators entities.
func (bu *BlocksUpdate) RemoveCaster(v ...*Validators) *BlocksUpdate {
ids := make([]int, len(v))
for i := range v {
ids[i] = v[i].ID
}
return bu.RemoveCasterIDs(ids...)
}
// ClearMinedTxs clears all "MinedTxs" edges to the Transactions entity.
func (bu *BlocksUpdate) ClearMinedTxs() *BlocksUpdate {
bu.mutation.ClearMinedTxs()
return bu
}
// RemoveMinedTxIDs removes the "MinedTxs" edge to Transactions entities by IDs.
func (bu *BlocksUpdate) RemoveMinedTxIDs(ids ...int) *BlocksUpdate {
bu.mutation.RemoveMinedTxIDs(ids...)
return bu
}
// RemoveMinedTxs removes "MinedTxs" edges to Transactions entities.
func (bu *BlocksUpdate) RemoveMinedTxs(t ...*Transactions) *BlocksUpdate {
ids := make([]int, len(t))
for i := range t {
ids[i] = t[i].ID
}
return bu.RemoveMinedTxIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (bu *BlocksUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, bu.sqlSave, bu.mutation, bu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (bu *BlocksUpdate) SaveX(ctx context.Context) int {
affected, err := bu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (bu *BlocksUpdate) Exec(ctx context.Context) error {
_, err := bu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (bu *BlocksUpdate) ExecX(ctx context.Context) {
if err := bu.Exec(ctx); err != nil {
panic(err)
}
}
func (bu *BlocksUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(blocks.Table, blocks.Columns, sqlgraph.NewFieldSpec(blocks.FieldID, field.TypeInt))
if ps := bu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := bu.mutation.Hash(); ok {
_spec.SetField(blocks.FieldHash, field.TypeString, value)
}
if value, ok := bu.mutation.Length(); ok {
_spec.SetField(blocks.FieldLength, field.TypeInt, value)
}
if value, ok := bu.mutation.AddedLength(); ok {
_spec.AddField(blocks.FieldLength, field.TypeInt, value)
}
if value, ok := bu.mutation.PreviousHash(); ok {
_spec.SetField(blocks.FieldPreviousHash, field.TypeString, value)
}
if bu.mutation.CasterCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: blocks.CasterTable,
Columns: []string{blocks.CasterColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := bu.mutation.RemovedCasterIDs(); len(nodes) > 0 && !bu.mutation.CasterCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: blocks.CasterTable,
Columns: []string{blocks.CasterColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := bu.mutation.CasterIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: blocks.CasterTable,
Columns: []string{blocks.CasterColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if bu.mutation.MinedTxsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: blocks.MinedTxsTable,
Columns: blocks.MinedTxsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(transactions.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := bu.mutation.RemovedMinedTxsIDs(); len(nodes) > 0 && !bu.mutation.MinedTxsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: blocks.MinedTxsTable,
Columns: blocks.MinedTxsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(transactions.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := bu.mutation.MinedTxsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: blocks.MinedTxsTable,
Columns: blocks.MinedTxsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(transactions.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{blocks.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
bu.mutation.done = true
return n, nil
}
// BlocksUpdateOne is the builder for updating a single Blocks entity.
type BlocksUpdateOne struct {
config
fields []string
hooks []Hook
mutation *BlocksMutation
}
// SetHash sets the "hash" field.
func (buo *BlocksUpdateOne) SetHash(s string) *BlocksUpdateOne {
buo.mutation.SetHash(s)
return buo
}
// SetNillableHash sets the "hash" field if the given value is not nil.
func (buo *BlocksUpdateOne) SetNillableHash(s *string) *BlocksUpdateOne {
if s != nil {
buo.SetHash(*s)
}
return buo
}
// SetLength sets the "length" field.
func (buo *BlocksUpdateOne) SetLength(i int) *BlocksUpdateOne {
buo.mutation.ResetLength()
buo.mutation.SetLength(i)
return buo
}
// SetNillableLength sets the "length" field if the given value is not nil.
func (buo *BlocksUpdateOne) SetNillableLength(i *int) *BlocksUpdateOne {
if i != nil {
buo.SetLength(*i)
}
return buo
}
// AddLength adds i to the "length" field.
func (buo *BlocksUpdateOne) AddLength(i int) *BlocksUpdateOne {
buo.mutation.AddLength(i)
return buo
}
// SetPreviousHash sets the "previousHash" field.
func (buo *BlocksUpdateOne) SetPreviousHash(s string) *BlocksUpdateOne {
buo.mutation.SetPreviousHash(s)
return buo
}
// SetNillablePreviousHash sets the "previousHash" field if the given value is not nil.
func (buo *BlocksUpdateOne) SetNillablePreviousHash(s *string) *BlocksUpdateOne {
if s != nil {
buo.SetPreviousHash(*s)
}
return buo
}
// AddCasterIDs adds the "Caster" edge to the Validators entity by IDs.
func (buo *BlocksUpdateOne) AddCasterIDs(ids ...int) *BlocksUpdateOne {
buo.mutation.AddCasterIDs(ids...)
return buo
}
// AddCaster adds the "Caster" edges to the Validators entity.
func (buo *BlocksUpdateOne) AddCaster(v ...*Validators) *BlocksUpdateOne {
ids := make([]int, len(v))
for i := range v {
ids[i] = v[i].ID
}
return buo.AddCasterIDs(ids...)
}
// AddMinedTxIDs adds the "MinedTxs" edge to the Transactions entity by IDs.
func (buo *BlocksUpdateOne) AddMinedTxIDs(ids ...int) *BlocksUpdateOne {
buo.mutation.AddMinedTxIDs(ids...)
return buo
}
// AddMinedTxs adds the "MinedTxs" edges to the Transactions entity.
func (buo *BlocksUpdateOne) AddMinedTxs(t ...*Transactions) *BlocksUpdateOne {
ids := make([]int, len(t))
for i := range t {
ids[i] = t[i].ID
}
return buo.AddMinedTxIDs(ids...)
}
// Mutation returns the BlocksMutation object of the builder.
func (buo *BlocksUpdateOne) Mutation() *BlocksMutation {
return buo.mutation
}
// ClearCaster clears all "Caster" edges to the Validators entity.
func (buo *BlocksUpdateOne) ClearCaster() *BlocksUpdateOne {
buo.mutation.ClearCaster()
return buo
}
// RemoveCasterIDs removes the "Caster" edge to Validators entities by IDs.
func (buo *BlocksUpdateOne) RemoveCasterIDs(ids ...int) *BlocksUpdateOne {
buo.mutation.RemoveCasterIDs(ids...)
return buo
}
// RemoveCaster removes "Caster" edges to Validators entities.
func (buo *BlocksUpdateOne) RemoveCaster(v ...*Validators) *BlocksUpdateOne {
ids := make([]int, len(v))
for i := range v {
ids[i] = v[i].ID
}
return buo.RemoveCasterIDs(ids...)
}
// ClearMinedTxs clears all "MinedTxs" edges to the Transactions entity.
func (buo *BlocksUpdateOne) ClearMinedTxs() *BlocksUpdateOne {
buo.mutation.ClearMinedTxs()
return buo
}
// RemoveMinedTxIDs removes the "MinedTxs" edge to Transactions entities by IDs.
func (buo *BlocksUpdateOne) RemoveMinedTxIDs(ids ...int) *BlocksUpdateOne {
buo.mutation.RemoveMinedTxIDs(ids...)
return buo
}
// RemoveMinedTxs removes "MinedTxs" edges to Transactions entities.
func (buo *BlocksUpdateOne) RemoveMinedTxs(t ...*Transactions) *BlocksUpdateOne {
ids := make([]int, len(t))
for i := range t {
ids[i] = t[i].ID
}
return buo.RemoveMinedTxIDs(ids...)
}
// Where appends a list predicates to the BlocksUpdate builder.
func (buo *BlocksUpdateOne) Where(ps ...predicate.Blocks) *BlocksUpdateOne {
buo.mutation.Where(ps...)
return buo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (buo *BlocksUpdateOne) Select(field string, fields ...string) *BlocksUpdateOne {
buo.fields = append([]string{field}, fields...)
return buo
}
// Save executes the query and returns the updated Blocks entity.
func (buo *BlocksUpdateOne) Save(ctx context.Context) (*Blocks, error) {
return withHooks(ctx, buo.sqlSave, buo.mutation, buo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (buo *BlocksUpdateOne) SaveX(ctx context.Context) *Blocks {
node, err := buo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (buo *BlocksUpdateOne) Exec(ctx context.Context) error {
_, err := buo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (buo *BlocksUpdateOne) ExecX(ctx context.Context) {
if err := buo.Exec(ctx); err != nil {
panic(err)
}
}
func (buo *BlocksUpdateOne) sqlSave(ctx context.Context) (_node *Blocks, err error) {
_spec := sqlgraph.NewUpdateSpec(blocks.Table, blocks.Columns, sqlgraph.NewFieldSpec(blocks.FieldID, field.TypeInt))
id, ok := buo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Blocks.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := buo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, blocks.FieldID)
for _, f := range fields {
if !blocks.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != blocks.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := buo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := buo.mutation.Hash(); ok {
_spec.SetField(blocks.FieldHash, field.TypeString, value)
}
if value, ok := buo.mutation.Length(); ok {
_spec.SetField(blocks.FieldLength, field.TypeInt, value)
}
if value, ok := buo.mutation.AddedLength(); ok {
_spec.AddField(blocks.FieldLength, field.TypeInt, value)
}
if value, ok := buo.mutation.PreviousHash(); ok {
_spec.SetField(blocks.FieldPreviousHash, field.TypeString, value)
}
if buo.mutation.CasterCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: blocks.CasterTable,
Columns: []string{blocks.CasterColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := buo.mutation.RemovedCasterIDs(); len(nodes) > 0 && !buo.mutation.CasterCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: blocks.CasterTable,
Columns: []string{blocks.CasterColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := buo.mutation.CasterIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: blocks.CasterTable,
Columns: []string{blocks.CasterColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if buo.mutation.MinedTxsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: blocks.MinedTxsTable,
Columns: blocks.MinedTxsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(transactions.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := buo.mutation.RemovedMinedTxsIDs(); len(nodes) > 0 && !buo.mutation.MinedTxsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: blocks.MinedTxsTable,
Columns: blocks.MinedTxsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(transactions.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := buo.mutation.MinedTxsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: blocks.MinedTxsTable,
Columns: blocks.MinedTxsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(transactions.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Blocks{config: buo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{blocks.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
buo.mutation.done = true
return _node, nil
}