initial commit
This commit is contained in:
375
ent/punishments_update.go
Normal file
375
ent/punishments_update.go
Normal file
@@ -0,0 +1,375 @@
|
||||
// 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/punishments"
|
||||
)
|
||||
|
||||
// PunishmentsUpdate is the builder for updating Punishments entities.
|
||||
type PunishmentsUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *PunishmentsMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PunishmentsUpdate builder.
|
||||
func (pu *PunishmentsUpdate) Where(ps ...predicate.Punishments) *PunishmentsUpdate {
|
||||
pu.mutation.Where(ps...)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetServerid sets the "serverid" field.
|
||||
func (pu *PunishmentsUpdate) SetServerid(s string) *PunishmentsUpdate {
|
||||
pu.mutation.SetServerid(s)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetWarnamount sets the "warnamount" field.
|
||||
func (pu *PunishmentsUpdate) SetWarnamount(s string) *PunishmentsUpdate {
|
||||
pu.mutation.SetWarnamount(s)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetActiontype sets the "actiontype" field.
|
||||
func (pu *PunishmentsUpdate) SetActiontype(s string) *PunishmentsUpdate {
|
||||
pu.mutation.SetActiontype(s)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetDuration sets the "duration" field.
|
||||
func (pu *PunishmentsUpdate) SetDuration(s string) *PunishmentsUpdate {
|
||||
pu.mutation.SetDuration(s)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (pu *PunishmentsUpdate) SetReason(s string) *PunishmentsUpdate {
|
||||
pu.mutation.SetReason(s)
|
||||
return pu
|
||||
}
|
||||
|
||||
// Mutation returns the PunishmentsMutation object of the builder.
|
||||
func (pu *PunishmentsUpdate) Mutation() *PunishmentsMutation {
|
||||
return pu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (pu *PunishmentsUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(pu.hooks) == 0 {
|
||||
affected, err = pu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PunishmentsMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
pu.mutation = mutation
|
||||
affected, err = pu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(pu.hooks) - 1; i >= 0; i-- {
|
||||
if pu.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = pu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, pu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (pu *PunishmentsUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := pu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pu *PunishmentsUpdate) Exec(ctx context.Context) error {
|
||||
_, err := pu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pu *PunishmentsUpdate) ExecX(ctx context.Context) {
|
||||
if err := pu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (pu *PunishmentsUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: punishments.Table,
|
||||
Columns: punishments.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: punishments.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := pu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := pu.mutation.Serverid(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldServerid,
|
||||
})
|
||||
}
|
||||
if value, ok := pu.mutation.Warnamount(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldWarnamount,
|
||||
})
|
||||
}
|
||||
if value, ok := pu.mutation.Actiontype(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldActiontype,
|
||||
})
|
||||
}
|
||||
if value, ok := pu.mutation.Duration(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldDuration,
|
||||
})
|
||||
}
|
||||
if value, ok := pu.mutation.Reason(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldReason,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{punishments.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// PunishmentsUpdateOne is the builder for updating a single Punishments entity.
|
||||
type PunishmentsUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *PunishmentsMutation
|
||||
}
|
||||
|
||||
// SetServerid sets the "serverid" field.
|
||||
func (puo *PunishmentsUpdateOne) SetServerid(s string) *PunishmentsUpdateOne {
|
||||
puo.mutation.SetServerid(s)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetWarnamount sets the "warnamount" field.
|
||||
func (puo *PunishmentsUpdateOne) SetWarnamount(s string) *PunishmentsUpdateOne {
|
||||
puo.mutation.SetWarnamount(s)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetActiontype sets the "actiontype" field.
|
||||
func (puo *PunishmentsUpdateOne) SetActiontype(s string) *PunishmentsUpdateOne {
|
||||
puo.mutation.SetActiontype(s)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetDuration sets the "duration" field.
|
||||
func (puo *PunishmentsUpdateOne) SetDuration(s string) *PunishmentsUpdateOne {
|
||||
puo.mutation.SetDuration(s)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (puo *PunishmentsUpdateOne) SetReason(s string) *PunishmentsUpdateOne {
|
||||
puo.mutation.SetReason(s)
|
||||
return puo
|
||||
}
|
||||
|
||||
// Mutation returns the PunishmentsMutation object of the builder.
|
||||
func (puo *PunishmentsUpdateOne) Mutation() *PunishmentsMutation {
|
||||
return puo.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 (puo *PunishmentsUpdateOne) Select(field string, fields ...string) *PunishmentsUpdateOne {
|
||||
puo.fields = append([]string{field}, fields...)
|
||||
return puo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Punishments entity.
|
||||
func (puo *PunishmentsUpdateOne) Save(ctx context.Context) (*Punishments, error) {
|
||||
var (
|
||||
err error
|
||||
node *Punishments
|
||||
)
|
||||
if len(puo.hooks) == 0 {
|
||||
node, err = puo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PunishmentsMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
puo.mutation = mutation
|
||||
node, err = puo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(puo.hooks) - 1; i >= 0; i-- {
|
||||
if puo.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = puo.hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, puo.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*Punishments)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from PunishmentsMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (puo *PunishmentsUpdateOne) SaveX(ctx context.Context) *Punishments {
|
||||
node, err := puo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (puo *PunishmentsUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := puo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (puo *PunishmentsUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := puo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (puo *PunishmentsUpdateOne) sqlSave(ctx context.Context) (_node *Punishments, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: punishments.Table,
|
||||
Columns: punishments.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: punishments.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := puo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Punishments.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := puo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, punishments.FieldID)
|
||||
for _, f := range fields {
|
||||
if !punishments.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != punishments.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := puo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := puo.mutation.Serverid(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldServerid,
|
||||
})
|
||||
}
|
||||
if value, ok := puo.mutation.Warnamount(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldWarnamount,
|
||||
})
|
||||
}
|
||||
if value, ok := puo.mutation.Actiontype(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldActiontype,
|
||||
})
|
||||
}
|
||||
if value, ok := puo.mutation.Duration(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldDuration,
|
||||
})
|
||||
}
|
||||
if value, ok := puo.mutation.Reason(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: punishments.FieldReason,
|
||||
})
|
||||
}
|
||||
_node = &Punishments{config: puo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{punishments.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user