frankenapi/ent/support_update.go
2022-09-08 09:18:04 +02:00

402 lines
10 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"
"github.com/FrankenBotDev/FrankenAPI/ent/predicate"
"github.com/FrankenBotDev/FrankenAPI/ent/support"
)
// SupportUpdate is the builder for updating Support entities.
type SupportUpdate struct {
config
hooks []Hook
mutation *SupportMutation
}
// Where appends a list predicates to the SupportUpdate builder.
func (su *SupportUpdate) Where(ps ...predicate.Support) *SupportUpdate {
su.mutation.Where(ps...)
return su
}
// SetRefid sets the "refid" field.
func (su *SupportUpdate) SetRefid(s string) *SupportUpdate {
su.mutation.SetRefid(s)
return su
}
// SetServerid sets the "serverid" field.
func (su *SupportUpdate) SetServerid(s string) *SupportUpdate {
su.mutation.SetServerid(s)
return su
}
// SetCreator sets the "creator" field.
func (su *SupportUpdate) SetCreator(s string) *SupportUpdate {
su.mutation.SetCreator(s)
return su
}
// SetStatus sets the "status" field.
func (su *SupportUpdate) SetStatus(s string) *SupportUpdate {
su.mutation.SetStatus(s)
return su
}
// SetTitle sets the "title" field.
func (su *SupportUpdate) SetTitle(s string) *SupportUpdate {
su.mutation.SetTitle(s)
return su
}
// SetDescription sets the "description" field.
func (su *SupportUpdate) SetDescription(s string) *SupportUpdate {
su.mutation.SetDescription(s)
return su
}
// Mutation returns the SupportMutation object of the builder.
func (su *SupportUpdate) Mutation() *SupportMutation {
return su.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (su *SupportUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(su.hooks) == 0 {
affected, err = su.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*SupportMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
su.mutation = mutation
affected, err = su.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(su.hooks) - 1; i >= 0; i-- {
if su.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = su.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, su.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (su *SupportUpdate) SaveX(ctx context.Context) int {
affected, err := su.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (su *SupportUpdate) Exec(ctx context.Context) error {
_, err := su.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (su *SupportUpdate) ExecX(ctx context.Context) {
if err := su.Exec(ctx); err != nil {
panic(err)
}
}
func (su *SupportUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: support.Table,
Columns: support.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: support.FieldID,
},
},
}
if ps := su.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := su.mutation.Refid(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldRefid,
})
}
if value, ok := su.mutation.Serverid(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldServerid,
})
}
if value, ok := su.mutation.Creator(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldCreator,
})
}
if value, ok := su.mutation.Status(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldStatus,
})
}
if value, ok := su.mutation.Title(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldTitle,
})
}
if value, ok := su.mutation.Description(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldDescription,
})
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{support.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
return n, nil
}
// SupportUpdateOne is the builder for updating a single Support entity.
type SupportUpdateOne struct {
config
fields []string
hooks []Hook
mutation *SupportMutation
}
// SetRefid sets the "refid" field.
func (suo *SupportUpdateOne) SetRefid(s string) *SupportUpdateOne {
suo.mutation.SetRefid(s)
return suo
}
// SetServerid sets the "serverid" field.
func (suo *SupportUpdateOne) SetServerid(s string) *SupportUpdateOne {
suo.mutation.SetServerid(s)
return suo
}
// SetCreator sets the "creator" field.
func (suo *SupportUpdateOne) SetCreator(s string) *SupportUpdateOne {
suo.mutation.SetCreator(s)
return suo
}
// SetStatus sets the "status" field.
func (suo *SupportUpdateOne) SetStatus(s string) *SupportUpdateOne {
suo.mutation.SetStatus(s)
return suo
}
// SetTitle sets the "title" field.
func (suo *SupportUpdateOne) SetTitle(s string) *SupportUpdateOne {
suo.mutation.SetTitle(s)
return suo
}
// SetDescription sets the "description" field.
func (suo *SupportUpdateOne) SetDescription(s string) *SupportUpdateOne {
suo.mutation.SetDescription(s)
return suo
}
// Mutation returns the SupportMutation object of the builder.
func (suo *SupportUpdateOne) Mutation() *SupportMutation {
return suo.mutation
}
// 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 *SupportUpdateOne) Select(field string, fields ...string) *SupportUpdateOne {
suo.fields = append([]string{field}, fields...)
return suo
}
// Save executes the query and returns the updated Support entity.
func (suo *SupportUpdateOne) Save(ctx context.Context) (*Support, error) {
var (
err error
node *Support
)
if len(suo.hooks) == 0 {
node, err = suo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*SupportMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
suo.mutation = mutation
node, err = suo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(suo.hooks) - 1; i >= 0; i-- {
if suo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = suo.hooks[i](mut)
}
v, err := mut.Mutate(ctx, suo.mutation)
if err != nil {
return nil, err
}
nv, ok := v.(*Support)
if !ok {
return nil, fmt.Errorf("unexpected node type %T returned from SupportMutation", v)
}
node = nv
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (suo *SupportUpdateOne) SaveX(ctx context.Context) *Support {
node, err := suo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (suo *SupportUpdateOne) Exec(ctx context.Context) error {
_, err := suo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (suo *SupportUpdateOne) ExecX(ctx context.Context) {
if err := suo.Exec(ctx); err != nil {
panic(err)
}
}
func (suo *SupportUpdateOne) sqlSave(ctx context.Context) (_node *Support, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: support.Table,
Columns: support.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: support.FieldID,
},
},
}
id, ok := suo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Support.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, support.FieldID)
for _, f := range fields {
if !support.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != support.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)
}
}
}
if value, ok := suo.mutation.Refid(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldRefid,
})
}
if value, ok := suo.mutation.Serverid(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldServerid,
})
}
if value, ok := suo.mutation.Creator(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldCreator,
})
}
if value, ok := suo.mutation.Status(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldStatus,
})
}
if value, ok := suo.mutation.Title(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldTitle,
})
}
if value, ok := suo.mutation.Description(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: support.FieldDescription,
})
}
_node = &Support{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{support.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
return _node, nil
}