341 lines
8.7 KiB
Go
341 lines
8.7 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/warns"
|
|
)
|
|
|
|
// WarnsCreate is the builder for creating a Warns entity.
|
|
type WarnsCreate struct {
|
|
config
|
|
mutation *WarnsMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetEmitter sets the "emitter" field.
|
|
func (wc *WarnsCreate) SetEmitter(s string) *WarnsCreate {
|
|
wc.mutation.SetEmitter(s)
|
|
return wc
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (wc *WarnsCreate) SetServerid(s string) *WarnsCreate {
|
|
wc.mutation.SetServerid(s)
|
|
return wc
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (wc *WarnsCreate) SetTarget(s string) *WarnsCreate {
|
|
wc.mutation.SetTarget(s)
|
|
return wc
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (wc *WarnsCreate) SetType(s string) *WarnsCreate {
|
|
wc.mutation.SetType(s)
|
|
return wc
|
|
}
|
|
|
|
// SetDuration sets the "duration" field.
|
|
func (wc *WarnsCreate) SetDuration(s string) *WarnsCreate {
|
|
wc.mutation.SetDuration(s)
|
|
return wc
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (wc *WarnsCreate) SetReason(s string) *WarnsCreate {
|
|
wc.mutation.SetReason(s)
|
|
return wc
|
|
}
|
|
|
|
// SetRefid sets the "refid" field.
|
|
func (wc *WarnsCreate) SetRefid(s string) *WarnsCreate {
|
|
wc.mutation.SetRefid(s)
|
|
return wc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (wc *WarnsCreate) SetID(i int) *WarnsCreate {
|
|
wc.mutation.SetID(i)
|
|
return wc
|
|
}
|
|
|
|
// Mutation returns the WarnsMutation object of the builder.
|
|
func (wc *WarnsCreate) Mutation() *WarnsMutation {
|
|
return wc.mutation
|
|
}
|
|
|
|
// Save creates the Warns in the database.
|
|
func (wc *WarnsCreate) Save(ctx context.Context) (*Warns, error) {
|
|
var (
|
|
err error
|
|
node *Warns
|
|
)
|
|
if len(wc.hooks) == 0 {
|
|
if err = wc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
node, err = wc.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)
|
|
}
|
|
if err = wc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
wc.mutation = mutation
|
|
if node, err = wc.sqlSave(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &node.ID
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(wc.hooks) - 1; i >= 0; i-- {
|
|
if wc.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = wc.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, wc.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 calls Save and panics if Save returns an error.
|
|
func (wc *WarnsCreate) SaveX(ctx context.Context) *Warns {
|
|
v, err := wc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wc *WarnsCreate) Exec(ctx context.Context) error {
|
|
_, err := wc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wc *WarnsCreate) ExecX(ctx context.Context) {
|
|
if err := wc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (wc *WarnsCreate) check() error {
|
|
if _, ok := wc.mutation.Emitter(); !ok {
|
|
return &ValidationError{Name: "emitter", err: errors.New(`ent: missing required field "Warns.emitter"`)}
|
|
}
|
|
if _, ok := wc.mutation.Serverid(); !ok {
|
|
return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Warns.serverid"`)}
|
|
}
|
|
if _, ok := wc.mutation.Target(); !ok {
|
|
return &ValidationError{Name: "target", err: errors.New(`ent: missing required field "Warns.target"`)}
|
|
}
|
|
if _, ok := wc.mutation.GetType(); !ok {
|
|
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Warns.type"`)}
|
|
}
|
|
if _, ok := wc.mutation.Duration(); !ok {
|
|
return &ValidationError{Name: "duration", err: errors.New(`ent: missing required field "Warns.duration"`)}
|
|
}
|
|
if _, ok := wc.mutation.Reason(); !ok {
|
|
return &ValidationError{Name: "reason", err: errors.New(`ent: missing required field "Warns.reason"`)}
|
|
}
|
|
if _, ok := wc.mutation.Refid(); !ok {
|
|
return &ValidationError{Name: "refid", err: errors.New(`ent: missing required field "Warns.refid"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (wc *WarnsCreate) sqlSave(ctx context.Context) (*Warns, error) {
|
|
_node, _spec := wc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, wc.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 (wc *WarnsCreate) createSpec() (*Warns, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Warns{config: wc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: warns.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: warns.FieldID,
|
|
},
|
|
}
|
|
)
|
|
if id, ok := wc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := wc.mutation.Emitter(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldEmitter,
|
|
})
|
|
_node.Emitter = value
|
|
}
|
|
if value, ok := wc.mutation.Serverid(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldServerid,
|
|
})
|
|
_node.Serverid = value
|
|
}
|
|
if value, ok := wc.mutation.Target(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldTarget,
|
|
})
|
|
_node.Target = value
|
|
}
|
|
if value, ok := wc.mutation.GetType(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldType,
|
|
})
|
|
_node.Type = value
|
|
}
|
|
if value, ok := wc.mutation.Duration(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldDuration,
|
|
})
|
|
_node.Duration = value
|
|
}
|
|
if value, ok := wc.mutation.Reason(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldReason,
|
|
})
|
|
_node.Reason = value
|
|
}
|
|
if value, ok := wc.mutation.Refid(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: warns.FieldRefid,
|
|
})
|
|
_node.Refid = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// WarnsCreateBulk is the builder for creating many Warns entities in bulk.
|
|
type WarnsCreateBulk struct {
|
|
config
|
|
builders []*WarnsCreate
|
|
}
|
|
|
|
// Save creates the Warns entities in the database.
|
|
func (wcb *WarnsCreateBulk) Save(ctx context.Context) ([]*Warns, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(wcb.builders))
|
|
nodes := make([]*Warns, len(wcb.builders))
|
|
mutators := make([]Mutator, len(wcb.builders))
|
|
for i := range wcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := wcb.builders[i]
|
|
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)
|
|
}
|
|
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, wcb.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, wcb.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, wcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wcb *WarnsCreateBulk) SaveX(ctx context.Context) []*Warns {
|
|
v, err := wcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wcb *WarnsCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := wcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wcb *WarnsCreateBulk) ExecX(ctx context.Context) {
|
|
if err := wcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|