Reviewed-on: https://git.harting.dev/CSGOWTF/csgowtfd/pulls/1 Co-authored-by: Giovanni Harting <539@idlegandalf.com> Co-committed-by: Giovanni Harting <539@idlegandalf.com>
312 lines
8.2 KiB
Go
312 lines
8.2 KiB
Go
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"csgowtfd/ent/stats"
|
|
"csgowtfd/ent/weaponstats"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// WeaponStatsCreate is the builder for creating a WeaponStats entity.
|
|
type WeaponStatsCreate struct {
|
|
config
|
|
mutation *WeaponStatsMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetVictim sets the "victim" field.
|
|
func (wsc *WeaponStatsCreate) SetVictim(u uint64) *WeaponStatsCreate {
|
|
wsc.mutation.SetVictim(u)
|
|
return wsc
|
|
}
|
|
|
|
// SetDmg sets the "dmg" field.
|
|
func (wsc *WeaponStatsCreate) SetDmg(u uint) *WeaponStatsCreate {
|
|
wsc.mutation.SetDmg(u)
|
|
return wsc
|
|
}
|
|
|
|
// SetEqType sets the "eq_type" field.
|
|
func (wsc *WeaponStatsCreate) SetEqType(i int) *WeaponStatsCreate {
|
|
wsc.mutation.SetEqType(i)
|
|
return wsc
|
|
}
|
|
|
|
// SetHitGroup sets the "hit_group" field.
|
|
func (wsc *WeaponStatsCreate) SetHitGroup(i int) *WeaponStatsCreate {
|
|
wsc.mutation.SetHitGroup(i)
|
|
return wsc
|
|
}
|
|
|
|
// SetStatID sets the "stat" edge to the Stats entity by ID.
|
|
func (wsc *WeaponStatsCreate) SetStatID(id int) *WeaponStatsCreate {
|
|
wsc.mutation.SetStatID(id)
|
|
return wsc
|
|
}
|
|
|
|
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
|
|
func (wsc *WeaponStatsCreate) SetNillableStatID(id *int) *WeaponStatsCreate {
|
|
if id != nil {
|
|
wsc = wsc.SetStatID(*id)
|
|
}
|
|
return wsc
|
|
}
|
|
|
|
// SetStat sets the "stat" edge to the Stats entity.
|
|
func (wsc *WeaponStatsCreate) SetStat(s *Stats) *WeaponStatsCreate {
|
|
return wsc.SetStatID(s.ID)
|
|
}
|
|
|
|
// Mutation returns the WeaponStatsMutation object of the builder.
|
|
func (wsc *WeaponStatsCreate) Mutation() *WeaponStatsMutation {
|
|
return wsc.mutation
|
|
}
|
|
|
|
// Save creates the WeaponStats in the database.
|
|
func (wsc *WeaponStatsCreate) Save(ctx context.Context) (*WeaponStats, error) {
|
|
var (
|
|
err error
|
|
node *WeaponStats
|
|
)
|
|
if len(wsc.hooks) == 0 {
|
|
if err = wsc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
node, err = wsc.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*WeaponStatsMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err = wsc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
wsc.mutation = mutation
|
|
if node, err = wsc.sqlSave(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &node.ID
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(wsc.hooks) - 1; i >= 0; i-- {
|
|
if wsc.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = wsc.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, wsc.mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (wsc *WeaponStatsCreate) SaveX(ctx context.Context) *WeaponStats {
|
|
v, err := wsc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wsc *WeaponStatsCreate) Exec(ctx context.Context) error {
|
|
_, err := wsc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wsc *WeaponStatsCreate) ExecX(ctx context.Context) {
|
|
if err := wsc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (wsc *WeaponStatsCreate) check() error {
|
|
if _, ok := wsc.mutation.Victim(); !ok {
|
|
return &ValidationError{Name: "victim", err: errors.New(`ent: missing required field "victim"`)}
|
|
}
|
|
if _, ok := wsc.mutation.Dmg(); !ok {
|
|
return &ValidationError{Name: "dmg", err: errors.New(`ent: missing required field "dmg"`)}
|
|
}
|
|
if _, ok := wsc.mutation.EqType(); !ok {
|
|
return &ValidationError{Name: "eq_type", err: errors.New(`ent: missing required field "eq_type"`)}
|
|
}
|
|
if _, ok := wsc.mutation.HitGroup(); !ok {
|
|
return &ValidationError{Name: "hit_group", err: errors.New(`ent: missing required field "hit_group"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (wsc *WeaponStatsCreate) sqlSave(ctx context.Context) (*WeaponStats, error) {
|
|
_node, _spec := wsc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, wsc.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{err.Error(), err}
|
|
}
|
|
return nil, err
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
return _node, nil
|
|
}
|
|
|
|
func (wsc *WeaponStatsCreate) createSpec() (*WeaponStats, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &WeaponStats{config: wsc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: weaponstats.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: weaponstats.FieldID,
|
|
},
|
|
}
|
|
)
|
|
if value, ok := wsc.mutation.Victim(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint64,
|
|
Value: value,
|
|
Column: weaponstats.FieldVictim,
|
|
})
|
|
_node.Victim = value
|
|
}
|
|
if value, ok := wsc.mutation.Dmg(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeUint,
|
|
Value: value,
|
|
Column: weaponstats.FieldDmg,
|
|
})
|
|
_node.Dmg = value
|
|
}
|
|
if value, ok := wsc.mutation.EqType(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: weaponstats.FieldEqType,
|
|
})
|
|
_node.EqType = value
|
|
}
|
|
if value, ok := wsc.mutation.HitGroup(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Value: value,
|
|
Column: weaponstats.FieldHitGroup,
|
|
})
|
|
_node.HitGroup = value
|
|
}
|
|
if nodes := wsc.mutation.StatIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: weaponstats.StatTable,
|
|
Columns: []string{weaponstats.StatColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: stats.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.stats_weapon_stats = &nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// WeaponStatsCreateBulk is the builder for creating many WeaponStats entities in bulk.
|
|
type WeaponStatsCreateBulk struct {
|
|
config
|
|
builders []*WeaponStatsCreate
|
|
}
|
|
|
|
// Save creates the WeaponStats entities in the database.
|
|
func (wscb *WeaponStatsCreateBulk) Save(ctx context.Context) ([]*WeaponStats, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(wscb.builders))
|
|
nodes := make([]*WeaponStats, len(wscb.builders))
|
|
mutators := make([]Mutator, len(wscb.builders))
|
|
for i := range wscb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := wscb.builders[i]
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*WeaponStatsMutation)
|
|
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, wscb.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, wscb.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{err.Error(), err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
mutation.done = true
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(id)
|
|
}
|
|
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, wscb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wscb *WeaponStatsCreateBulk) SaveX(ctx context.Context) []*WeaponStats {
|
|
v, err := wscb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wscb *WeaponStatsCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := wscb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wscb *WeaponStatsCreateBulk) ExecX(ctx context.Context) {
|
|
if err := wscb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|