290 lines
7.4 KiB
Go
290 lines
7.4 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/logging"
|
|
)
|
|
|
|
// LoggingCreate is the builder for creating a Logging entity.
|
|
type LoggingCreate struct {
|
|
config
|
|
mutation *LoggingMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (lc *LoggingCreate) SetServerid(s string) *LoggingCreate {
|
|
lc.mutation.SetServerid(s)
|
|
return lc
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (lc *LoggingCreate) SetType(s string) *LoggingCreate {
|
|
lc.mutation.SetType(s)
|
|
return lc
|
|
}
|
|
|
|
// SetCommiter sets the "commiter" field.
|
|
func (lc *LoggingCreate) SetCommiter(s string) *LoggingCreate {
|
|
lc.mutation.SetCommiter(s)
|
|
return lc
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (lc *LoggingCreate) SetDescription(s string) *LoggingCreate {
|
|
lc.mutation.SetDescription(s)
|
|
return lc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (lc *LoggingCreate) SetID(i int) *LoggingCreate {
|
|
lc.mutation.SetID(i)
|
|
return lc
|
|
}
|
|
|
|
// Mutation returns the LoggingMutation object of the builder.
|
|
func (lc *LoggingCreate) Mutation() *LoggingMutation {
|
|
return lc.mutation
|
|
}
|
|
|
|
// Save creates the Logging in the database.
|
|
func (lc *LoggingCreate) Save(ctx context.Context) (*Logging, error) {
|
|
var (
|
|
err error
|
|
node *Logging
|
|
)
|
|
if len(lc.hooks) == 0 {
|
|
if err = lc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
node, err = lc.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)
|
|
}
|
|
if err = lc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
lc.mutation = mutation
|
|
if node, err = lc.sqlSave(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &node.ID
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(lc.hooks) - 1; i >= 0; i-- {
|
|
if lc.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = lc.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, lc.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 calls Save and panics if Save returns an error.
|
|
func (lc *LoggingCreate) SaveX(ctx context.Context) *Logging {
|
|
v, err := lc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (lc *LoggingCreate) Exec(ctx context.Context) error {
|
|
_, err := lc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (lc *LoggingCreate) ExecX(ctx context.Context) {
|
|
if err := lc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (lc *LoggingCreate) check() error {
|
|
if _, ok := lc.mutation.Serverid(); !ok {
|
|
return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Logging.serverid"`)}
|
|
}
|
|
if _, ok := lc.mutation.GetType(); !ok {
|
|
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Logging.type"`)}
|
|
}
|
|
if _, ok := lc.mutation.Commiter(); !ok {
|
|
return &ValidationError{Name: "commiter", err: errors.New(`ent: missing required field "Logging.commiter"`)}
|
|
}
|
|
if _, ok := lc.mutation.Description(); !ok {
|
|
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "Logging.description"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (lc *LoggingCreate) sqlSave(ctx context.Context) (*Logging, error) {
|
|
_node, _spec := lc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, lc.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != _node.ID {
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
}
|
|
return _node, nil
|
|
}
|
|
|
|
func (lc *LoggingCreate) createSpec() (*Logging, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Logging{config: lc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: logging.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: logging.FieldID,
|
|
},
|
|
}
|
|
)
|
|
if id, ok := lc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := lc.mutation.Serverid(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: logging.FieldServerid,
|
|
})
|
|
_node.Serverid = value
|
|
}
|
|
if value, ok := lc.mutation.GetType(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: logging.FieldType,
|
|
})
|
|
_node.Type = value
|
|
}
|
|
if value, ok := lc.mutation.Commiter(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: logging.FieldCommiter,
|
|
})
|
|
_node.Commiter = value
|
|
}
|
|
if value, ok := lc.mutation.Description(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: logging.FieldDescription,
|
|
})
|
|
_node.Description = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// LoggingCreateBulk is the builder for creating many Logging entities in bulk.
|
|
type LoggingCreateBulk struct {
|
|
config
|
|
builders []*LoggingCreate
|
|
}
|
|
|
|
// Save creates the Logging entities in the database.
|
|
func (lcb *LoggingCreateBulk) Save(ctx context.Context) ([]*Logging, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(lcb.builders))
|
|
nodes := make([]*Logging, len(lcb.builders))
|
|
mutators := make([]Mutator, len(lcb.builders))
|
|
for i := range lcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := lcb.builders[i]
|
|
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)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
var err error
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, lcb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, lcb.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(id)
|
|
}
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, lcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (lcb *LoggingCreateBulk) SaveX(ctx context.Context) []*Logging {
|
|
v, err := lcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (lcb *LoggingCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := lcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (lcb *LoggingCreateBulk) ExecX(ctx context.Context) {
|
|
if err := lcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|