zkt24/z2/backend/ent/validators_update.go

399 lines
11 KiB
Go
Raw Normal View History

2024-04-25 11:51:47 +00:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"thesis/ent/key"
"thesis/ent/predicate"
"thesis/ent/validators"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ValidatorsUpdate is the builder for updating Validators entities.
type ValidatorsUpdate struct {
config
hooks []Hook
mutation *ValidatorsMutation
}
// Where appends a list predicates to the ValidatorsUpdate builder.
func (vu *ValidatorsUpdate) Where(ps ...predicate.Validators) *ValidatorsUpdate {
vu.mutation.Where(ps...)
return vu
}
// SetFacilitator sets the "facilitator" field.
func (vu *ValidatorsUpdate) SetFacilitator(s string) *ValidatorsUpdate {
vu.mutation.SetFacilitator(s)
return vu
}
// SetNillableFacilitator sets the "facilitator" field if the given value is not nil.
func (vu *ValidatorsUpdate) SetNillableFacilitator(s *string) *ValidatorsUpdate {
if s != nil {
vu.SetFacilitator(*s)
}
return vu
}
// AddKeyIDs adds the "key" edge to the Key entity by IDs.
func (vu *ValidatorsUpdate) AddKeyIDs(ids ...int) *ValidatorsUpdate {
vu.mutation.AddKeyIDs(ids...)
return vu
}
// AddKey adds the "key" edges to the Key entity.
func (vu *ValidatorsUpdate) AddKey(k ...*Key) *ValidatorsUpdate {
ids := make([]int, len(k))
for i := range k {
ids[i] = k[i].ID
}
return vu.AddKeyIDs(ids...)
}
// Mutation returns the ValidatorsMutation object of the builder.
func (vu *ValidatorsUpdate) Mutation() *ValidatorsMutation {
return vu.mutation
}
// ClearKey clears all "key" edges to the Key entity.
func (vu *ValidatorsUpdate) ClearKey() *ValidatorsUpdate {
vu.mutation.ClearKey()
return vu
}
// RemoveKeyIDs removes the "key" edge to Key entities by IDs.
func (vu *ValidatorsUpdate) RemoveKeyIDs(ids ...int) *ValidatorsUpdate {
vu.mutation.RemoveKeyIDs(ids...)
return vu
}
// RemoveKey removes "key" edges to Key entities.
func (vu *ValidatorsUpdate) RemoveKey(k ...*Key) *ValidatorsUpdate {
ids := make([]int, len(k))
for i := range k {
ids[i] = k[i].ID
}
return vu.RemoveKeyIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (vu *ValidatorsUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, vu.sqlSave, vu.mutation, vu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (vu *ValidatorsUpdate) SaveX(ctx context.Context) int {
affected, err := vu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (vu *ValidatorsUpdate) Exec(ctx context.Context) error {
_, err := vu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (vu *ValidatorsUpdate) ExecX(ctx context.Context) {
if err := vu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (vu *ValidatorsUpdate) check() error {
if v, ok := vu.mutation.Facilitator(); ok {
if err := validators.FacilitatorValidator(v); err != nil {
return &ValidationError{Name: "facilitator", err: fmt.Errorf(`ent: validator failed for field "Validators.facilitator": %w`, err)}
}
}
return nil
}
func (vu *ValidatorsUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := vu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(validators.Table, validators.Columns, sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt))
if ps := vu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := vu.mutation.Facilitator(); ok {
_spec.SetField(validators.FieldFacilitator, field.TypeString, value)
}
if vu.mutation.KeyCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: validators.KeyTable,
Columns: []string{validators.KeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := vu.mutation.RemovedKeyIDs(); len(nodes) > 0 && !vu.mutation.KeyCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: validators.KeyTable,
Columns: []string{validators.KeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(key.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 := vu.mutation.KeyIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: validators.KeyTable,
Columns: []string{validators.KeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(key.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, vu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{validators.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
vu.mutation.done = true
return n, nil
}
// ValidatorsUpdateOne is the builder for updating a single Validators entity.
type ValidatorsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ValidatorsMutation
}
// SetFacilitator sets the "facilitator" field.
func (vuo *ValidatorsUpdateOne) SetFacilitator(s string) *ValidatorsUpdateOne {
vuo.mutation.SetFacilitator(s)
return vuo
}
// SetNillableFacilitator sets the "facilitator" field if the given value is not nil.
func (vuo *ValidatorsUpdateOne) SetNillableFacilitator(s *string) *ValidatorsUpdateOne {
if s != nil {
vuo.SetFacilitator(*s)
}
return vuo
}
// AddKeyIDs adds the "key" edge to the Key entity by IDs.
func (vuo *ValidatorsUpdateOne) AddKeyIDs(ids ...int) *ValidatorsUpdateOne {
vuo.mutation.AddKeyIDs(ids...)
return vuo
}
// AddKey adds the "key" edges to the Key entity.
func (vuo *ValidatorsUpdateOne) AddKey(k ...*Key) *ValidatorsUpdateOne {
ids := make([]int, len(k))
for i := range k {
ids[i] = k[i].ID
}
return vuo.AddKeyIDs(ids...)
}
// Mutation returns the ValidatorsMutation object of the builder.
func (vuo *ValidatorsUpdateOne) Mutation() *ValidatorsMutation {
return vuo.mutation
}
// ClearKey clears all "key" edges to the Key entity.
func (vuo *ValidatorsUpdateOne) ClearKey() *ValidatorsUpdateOne {
vuo.mutation.ClearKey()
return vuo
}
// RemoveKeyIDs removes the "key" edge to Key entities by IDs.
func (vuo *ValidatorsUpdateOne) RemoveKeyIDs(ids ...int) *ValidatorsUpdateOne {
vuo.mutation.RemoveKeyIDs(ids...)
return vuo
}
// RemoveKey removes "key" edges to Key entities.
func (vuo *ValidatorsUpdateOne) RemoveKey(k ...*Key) *ValidatorsUpdateOne {
ids := make([]int, len(k))
for i := range k {
ids[i] = k[i].ID
}
return vuo.RemoveKeyIDs(ids...)
}
// Where appends a list predicates to the ValidatorsUpdate builder.
func (vuo *ValidatorsUpdateOne) Where(ps ...predicate.Validators) *ValidatorsUpdateOne {
vuo.mutation.Where(ps...)
return vuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (vuo *ValidatorsUpdateOne) Select(field string, fields ...string) *ValidatorsUpdateOne {
vuo.fields = append([]string{field}, fields...)
return vuo
}
// Save executes the query and returns the updated Validators entity.
func (vuo *ValidatorsUpdateOne) Save(ctx context.Context) (*Validators, error) {
return withHooks(ctx, vuo.sqlSave, vuo.mutation, vuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (vuo *ValidatorsUpdateOne) SaveX(ctx context.Context) *Validators {
node, err := vuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (vuo *ValidatorsUpdateOne) Exec(ctx context.Context) error {
_, err := vuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (vuo *ValidatorsUpdateOne) ExecX(ctx context.Context) {
if err := vuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (vuo *ValidatorsUpdateOne) check() error {
if v, ok := vuo.mutation.Facilitator(); ok {
if err := validators.FacilitatorValidator(v); err != nil {
return &ValidationError{Name: "facilitator", err: fmt.Errorf(`ent: validator failed for field "Validators.facilitator": %w`, err)}
}
}
return nil
}
func (vuo *ValidatorsUpdateOne) sqlSave(ctx context.Context) (_node *Validators, err error) {
if err := vuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(validators.Table, validators.Columns, sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt))
id, ok := vuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Validators.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := vuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, validators.FieldID)
for _, f := range fields {
if !validators.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != validators.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := vuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := vuo.mutation.Facilitator(); ok {
_spec.SetField(validators.FieldFacilitator, field.TypeString, value)
}
if vuo.mutation.KeyCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: validators.KeyTable,
Columns: []string{validators.KeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := vuo.mutation.RemovedKeyIDs(); len(nodes) > 0 && !vuo.mutation.KeyCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: validators.KeyTable,
Columns: []string{validators.KeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(key.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 := vuo.mutation.KeyIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: validators.KeyTable,
Columns: []string{validators.KeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Validators{config: vuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, vuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{validators.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
vuo.mutation.done = true
return _node, nil
}