176 lines
4.8 KiB
Go
176 lines
4.8 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
|
"git.dotya.ml/mirre-mt/pcmt/ent/setup"
|
|
)
|
|
|
|
// SetupUpdate is the builder for updating Setup entities.
|
|
type SetupUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *SetupMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the SetupUpdate builder.
|
|
func (su *SetupUpdate) Where(ps ...predicate.Setup) *SetupUpdate {
|
|
su.mutation.Where(ps...)
|
|
return su
|
|
}
|
|
|
|
// Mutation returns the SetupMutation object of the builder.
|
|
func (su *SetupUpdate) Mutation() *SetupMutation {
|
|
return su.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (su *SetupUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (su *SetupUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := su.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (su *SetupUpdate) Exec(ctx context.Context) error {
|
|
_, err := su.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (su *SetupUpdate) ExecX(ctx context.Context) {
|
|
if err := su.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (su *SetupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(setup.Table, setup.Columns, sqlgraph.NewFieldSpec(setup.FieldID, field.TypeUUID))
|
|
if ps := su.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{setup.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
su.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// SetupUpdateOne is the builder for updating a single Setup entity.
|
|
type SetupUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *SetupMutation
|
|
}
|
|
|
|
// Mutation returns the SetupMutation object of the builder.
|
|
func (suo *SetupUpdateOne) Mutation() *SetupMutation {
|
|
return suo.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the SetupUpdate builder.
|
|
func (suo *SetupUpdateOne) Where(ps ...predicate.Setup) *SetupUpdateOne {
|
|
suo.mutation.Where(ps...)
|
|
return suo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (suo *SetupUpdateOne) Select(field string, fields ...string) *SetupUpdateOne {
|
|
suo.fields = append([]string{field}, fields...)
|
|
return suo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Setup entity.
|
|
func (suo *SetupUpdateOne) Save(ctx context.Context) (*Setup, error) {
|
|
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (suo *SetupUpdateOne) SaveX(ctx context.Context) *Setup {
|
|
node, err := suo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (suo *SetupUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := suo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (suo *SetupUpdateOne) ExecX(ctx context.Context) {
|
|
if err := suo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (suo *SetupUpdateOne) sqlSave(ctx context.Context) (_node *Setup, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(setup.Table, setup.Columns, sqlgraph.NewFieldSpec(setup.FieldID, field.TypeUUID))
|
|
id, ok := suo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Setup.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := suo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, setup.FieldID)
|
|
for _, f := range fields {
|
|
if !setup.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != setup.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := suo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
_node = &Setup{config: suo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{setup.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
suo.mutation.done = true
|
|
return _node, nil
|
|
}
|