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