298 lines
7.8 KiB
Go
298 lines
7.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"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/blacklist"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/predicate"
|
|
)
|
|
|
|
// BlacklistUpdate is the builder for updating Blacklist entities.
|
|
type BlacklistUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *BlacklistMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the BlacklistUpdate builder.
|
|
func (bu *BlacklistUpdate) Where(ps ...predicate.Blacklist) *BlacklistUpdate {
|
|
bu.mutation.Where(ps...)
|
|
return bu
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (bu *BlacklistUpdate) SetServerid(s string) *BlacklistUpdate {
|
|
bu.mutation.SetServerid(s)
|
|
return bu
|
|
}
|
|
|
|
// SetWord sets the "word" field.
|
|
func (bu *BlacklistUpdate) SetWord(s string) *BlacklistUpdate {
|
|
bu.mutation.SetWord(s)
|
|
return bu
|
|
}
|
|
|
|
// Mutation returns the BlacklistMutation object of the builder.
|
|
func (bu *BlacklistUpdate) Mutation() *BlacklistMutation {
|
|
return bu.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (bu *BlacklistUpdate) Save(ctx context.Context) (int, error) {
|
|
var (
|
|
err error
|
|
affected int
|
|
)
|
|
if len(bu.hooks) == 0 {
|
|
affected, err = bu.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*BlacklistMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
bu.mutation = mutation
|
|
affected, err = bu.sqlSave(ctx)
|
|
mutation.done = true
|
|
return affected, err
|
|
})
|
|
for i := len(bu.hooks) - 1; i >= 0; i-- {
|
|
if bu.hooks[i] == nil {
|
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = bu.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, bu.mutation); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
return affected, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (bu *BlacklistUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := bu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (bu *BlacklistUpdate) Exec(ctx context.Context) error {
|
|
_, err := bu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (bu *BlacklistUpdate) ExecX(ctx context.Context) {
|
|
if err := bu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (bu *BlacklistUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: blacklist.Table,
|
|
Columns: blacklist.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: blacklist.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := bu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := bu.mutation.Serverid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: blacklist.FieldServerid,
|
|
})
|
|
}
|
|
if value, ok := bu.mutation.Word(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: blacklist.FieldWord,
|
|
})
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{blacklist.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
return n, nil
|
|
}
|
|
|
|
// BlacklistUpdateOne is the builder for updating a single Blacklist entity.
|
|
type BlacklistUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *BlacklistMutation
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (buo *BlacklistUpdateOne) SetServerid(s string) *BlacklistUpdateOne {
|
|
buo.mutation.SetServerid(s)
|
|
return buo
|
|
}
|
|
|
|
// SetWord sets the "word" field.
|
|
func (buo *BlacklistUpdateOne) SetWord(s string) *BlacklistUpdateOne {
|
|
buo.mutation.SetWord(s)
|
|
return buo
|
|
}
|
|
|
|
// Mutation returns the BlacklistMutation object of the builder.
|
|
func (buo *BlacklistUpdateOne) Mutation() *BlacklistMutation {
|
|
return buo.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 (buo *BlacklistUpdateOne) Select(field string, fields ...string) *BlacklistUpdateOne {
|
|
buo.fields = append([]string{field}, fields...)
|
|
return buo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Blacklist entity.
|
|
func (buo *BlacklistUpdateOne) Save(ctx context.Context) (*Blacklist, error) {
|
|
var (
|
|
err error
|
|
node *Blacklist
|
|
)
|
|
if len(buo.hooks) == 0 {
|
|
node, err = buo.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*BlacklistMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
buo.mutation = mutation
|
|
node, err = buo.sqlSave(ctx)
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(buo.hooks) - 1; i >= 0; i-- {
|
|
if buo.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = buo.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, buo.mutation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nv, ok := v.(*Blacklist)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from BlacklistMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (buo *BlacklistUpdateOne) SaveX(ctx context.Context) *Blacklist {
|
|
node, err := buo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (buo *BlacklistUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := buo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (buo *BlacklistUpdateOne) ExecX(ctx context.Context) {
|
|
if err := buo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (buo *BlacklistUpdateOne) sqlSave(ctx context.Context) (_node *Blacklist, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: blacklist.Table,
|
|
Columns: blacklist.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: blacklist.FieldID,
|
|
},
|
|
},
|
|
}
|
|
id, ok := buo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Blacklist.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := buo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, blacklist.FieldID)
|
|
for _, f := range fields {
|
|
if !blacklist.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != blacklist.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := buo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := buo.mutation.Serverid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: blacklist.FieldServerid,
|
|
})
|
|
}
|
|
if value, ok := buo.mutation.Word(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: blacklist.FieldWord,
|
|
})
|
|
}
|
|
_node = &Blacklist{config: buo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{blacklist.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
return _node, nil
|
|
}
|