428 lines
11 KiB
Go
428 lines
11 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/warns"
|
|
)
|
|
|
|
// WarnsUpdate is the builder for updating Warns entities.
|
|
type WarnsUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *WarnsMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the WarnsUpdate builder.
|
|
func (wu *WarnsUpdate) Where(ps ...predicate.Warns) *WarnsUpdate {
|
|
wu.mutation.Where(ps...)
|
|
return wu
|
|
}
|
|
|
|
// SetEmitter sets the "emitter" field.
|
|
func (wu *WarnsUpdate) SetEmitter(s string) *WarnsUpdate {
|
|
wu.mutation.SetEmitter(s)
|
|
return wu
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (wu *WarnsUpdate) SetServerid(s string) *WarnsUpdate {
|
|
wu.mutation.SetServerid(s)
|
|
return wu
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (wu *WarnsUpdate) SetTarget(s string) *WarnsUpdate {
|
|
wu.mutation.SetTarget(s)
|
|
return wu
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (wu *WarnsUpdate) SetType(s string) *WarnsUpdate {
|
|
wu.mutation.SetType(s)
|
|
return wu
|
|
}
|
|
|
|
// SetDuration sets the "duration" field.
|
|
func (wu *WarnsUpdate) SetDuration(s string) *WarnsUpdate {
|
|
wu.mutation.SetDuration(s)
|
|
return wu
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (wu *WarnsUpdate) SetReason(s string) *WarnsUpdate {
|
|
wu.mutation.SetReason(s)
|
|
return wu
|
|
}
|
|
|
|
// SetRefid sets the "refid" field.
|
|
func (wu *WarnsUpdate) SetRefid(s string) *WarnsUpdate {
|
|
wu.mutation.SetRefid(s)
|
|
return wu
|
|
}
|
|
|
|
// Mutation returns the WarnsMutation object of the builder.
|
|
func (wu *WarnsUpdate) Mutation() *WarnsMutation {
|
|
return wu.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (wu *WarnsUpdate) Save(ctx context.Context) (int, error) {
|
|
var (
|
|
err error
|
|
affected int
|
|
)
|
|
if len(wu.hooks) == 0 {
|
|
affected, err = wu.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*WarnsMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
wu.mutation = mutation
|
|
affected, err = wu.sqlSave(ctx)
|
|
mutation.done = true
|
|
return affected, err
|
|
})
|
|
for i := len(wu.hooks) - 1; i >= 0; i-- {
|
|
if wu.hooks[i] == nil {
|
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = wu.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, wu.mutation); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
return affected, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wu *WarnsUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := wu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wu *WarnsUpdate) Exec(ctx context.Context) error {
|
|
_, err := wu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wu *WarnsUpdate) ExecX(ctx context.Context) {
|
|
if err := wu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (wu *WarnsUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: warns.Table,
|
|
Columns: warns.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: warns.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := wu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := wu.mutation.Emitter(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldEmitter,
|
|
})
|
|
}
|
|
if value, ok := wu.mutation.Serverid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldServerid,
|
|
})
|
|
}
|
|
if value, ok := wu.mutation.Target(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldTarget,
|
|
})
|
|
}
|
|
if value, ok := wu.mutation.GetType(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldType,
|
|
})
|
|
}
|
|
if value, ok := wu.mutation.Duration(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldDuration,
|
|
})
|
|
}
|
|
if value, ok := wu.mutation.Reason(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldReason,
|
|
})
|
|
}
|
|
if value, ok := wu.mutation.Refid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldRefid,
|
|
})
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{warns.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
return n, nil
|
|
}
|
|
|
|
// WarnsUpdateOne is the builder for updating a single Warns entity.
|
|
type WarnsUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *WarnsMutation
|
|
}
|
|
|
|
// SetEmitter sets the "emitter" field.
|
|
func (wuo *WarnsUpdateOne) SetEmitter(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetEmitter(s)
|
|
return wuo
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (wuo *WarnsUpdateOne) SetServerid(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetServerid(s)
|
|
return wuo
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (wuo *WarnsUpdateOne) SetTarget(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetTarget(s)
|
|
return wuo
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (wuo *WarnsUpdateOne) SetType(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetType(s)
|
|
return wuo
|
|
}
|
|
|
|
// SetDuration sets the "duration" field.
|
|
func (wuo *WarnsUpdateOne) SetDuration(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetDuration(s)
|
|
return wuo
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (wuo *WarnsUpdateOne) SetReason(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetReason(s)
|
|
return wuo
|
|
}
|
|
|
|
// SetRefid sets the "refid" field.
|
|
func (wuo *WarnsUpdateOne) SetRefid(s string) *WarnsUpdateOne {
|
|
wuo.mutation.SetRefid(s)
|
|
return wuo
|
|
}
|
|
|
|
// Mutation returns the WarnsMutation object of the builder.
|
|
func (wuo *WarnsUpdateOne) Mutation() *WarnsMutation {
|
|
return wuo.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 (wuo *WarnsUpdateOne) Select(field string, fields ...string) *WarnsUpdateOne {
|
|
wuo.fields = append([]string{field}, fields...)
|
|
return wuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Warns entity.
|
|
func (wuo *WarnsUpdateOne) Save(ctx context.Context) (*Warns, error) {
|
|
var (
|
|
err error
|
|
node *Warns
|
|
)
|
|
if len(wuo.hooks) == 0 {
|
|
node, err = wuo.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*WarnsMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
wuo.mutation = mutation
|
|
node, err = wuo.sqlSave(ctx)
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(wuo.hooks) - 1; i >= 0; i-- {
|
|
if wuo.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = wuo.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, wuo.mutation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nv, ok := v.(*Warns)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from WarnsMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wuo *WarnsUpdateOne) SaveX(ctx context.Context) *Warns {
|
|
node, err := wuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (wuo *WarnsUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := wuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wuo *WarnsUpdateOne) ExecX(ctx context.Context) {
|
|
if err := wuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (wuo *WarnsUpdateOne) sqlSave(ctx context.Context) (_node *Warns, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: warns.Table,
|
|
Columns: warns.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: warns.FieldID,
|
|
},
|
|
},
|
|
}
|
|
id, ok := wuo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Warns.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := wuo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, warns.FieldID)
|
|
for _, f := range fields {
|
|
if !warns.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != warns.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := wuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := wuo.mutation.Emitter(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldEmitter,
|
|
})
|
|
}
|
|
if value, ok := wuo.mutation.Serverid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldServerid,
|
|
})
|
|
}
|
|
if value, ok := wuo.mutation.Target(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldTarget,
|
|
})
|
|
}
|
|
if value, ok := wuo.mutation.GetType(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldType,
|
|
})
|
|
}
|
|
if value, ok := wuo.mutation.Duration(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldDuration,
|
|
})
|
|
}
|
|
if value, ok := wuo.mutation.Reason(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldReason,
|
|
})
|
|
}
|
|
if value, ok := wuo.mutation.Refid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldRefid,
|
|
})
|
|
}
|
|
_node = &Warns{config: wuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{warns.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
return _node, nil
|
|
}
|