302 lines
7.8 KiB
Go
302 lines
7.8 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"
|
|
"git.harting.dev/csgowtf/csgowtfd/ent/matchplayer"
|
|
"git.harting.dev/csgowtf/csgowtfd/ent/weapon"
|
|
)
|
|
|
|
// WeaponCreate is the builder for creating a Weapon entity.
|
|
type WeaponCreate struct {
|
|
config
|
|
mutation *WeaponMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetVictim sets the "victim" field.
|
|
func (wc *WeaponCreate) SetVictim(u uint64) *WeaponCreate {
|
|
wc.mutation.SetVictim(u)
|
|
return wc
|
|
}
|
|
|
|
// SetDmg sets the "dmg" field.
|
|
func (wc *WeaponCreate) SetDmg(u uint) *WeaponCreate {
|
|
wc.mutation.SetDmg(u)
|
|
return wc
|
|
}
|
|
|
|
// SetEqType sets the "eq_type" field.
|
|
func (wc *WeaponCreate) SetEqType(i int) *WeaponCreate {
|
|
wc.mutation.SetEqType(i)
|
|
return wc
|
|
}
|
|
|
|
// SetHitGroup sets the "hit_group" field.
|
|
func (wc *WeaponCreate) SetHitGroup(i int) *WeaponCreate {
|
|
wc.mutation.SetHitGroup(i)
|
|
return wc
|
|
}
|
|
|
|
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
|
|
func (wc *WeaponCreate) SetStatID(id int) *WeaponCreate {
|
|
wc.mutation.SetStatID(id)
|
|
return wc
|
|
}
|
|
|
|
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
|
|
func (wc *WeaponCreate) SetNillableStatID(id *int) *WeaponCreate {
|
|
if id != nil {
|
|
wc = wc.SetStatID(*id)
|
|
}
|
|
return wc
|
|
}
|
|
|
|
// SetStat sets the "stat" edge to the MatchPlayer entity.
|
|
func (wc *WeaponCreate) SetStat(m *MatchPlayer) *WeaponCreate {
|
|
return wc.SetStatID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the WeaponMutation object of the builder.
|
|
func (wc *WeaponCreate) Mutation() *WeaponMutation {
|
|
return wc.mutation
|
|
}
|
|
|
|
// Save creates the Weapon in the database.
|
|
func (wc *WeaponCreate) Save(ctx context.Context) (*Weapon, error) {
|
|
var (
|
|
err error
|
|
node *Weapon
|
|
)
|
|
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.(*WeaponMutation)
|
|
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.(*Weapon)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from WeaponMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (wc *WeaponCreate) SaveX(ctx context.Context) *Weapon {
|
|
v, err := wc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wc *WeaponCreate) Exec(ctx context.Context) error {
|
|
_, err := wc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wc *WeaponCreate) 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 *WeaponCreate) check() error {
|
|
if _, ok := wc.mutation.Victim(); !ok {
|
|
return &ValidationError{Name: "victim", err: errors.New(`ent: missing required field "Weapon.victim"`)}
|
|
}
|
|
if _, ok := wc.mutation.Dmg(); !ok {
|
|
return &ValidationError{Name: "dmg", err: errors.New(`ent: missing required field "Weapon.dmg"`)}
|
|
}
|
|
if _, ok := wc.mutation.EqType(); !ok {
|
|
return &ValidationError{Name: "eq_type", err: errors.New(`ent: missing required field "Weapon.eq_type"`)}
|
|
}
|
|
if _, ok := wc.mutation.HitGroup(); !ok {
|
|
return &ValidationError{Name: "hit_group", err: errors.New(`ent: missing required field "Weapon.hit_group"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (wc *WeaponCreate) sqlSave(ctx context.Context) (*Weapon, 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
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
return _node, nil
|
|
}
|
|
|
|
func (wc *WeaponCreate) createSpec() (*Weapon, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Weapon{config: wc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: weapon.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: weapon.FieldID,
|
|
},
|
|
}
|
|
)
|
|
if value, ok := wc.mutation.Victim(); ok {
|
|
_spec.SetField(weapon.FieldVictim, field.TypeUint64, value)
|
|
_node.Victim = value
|
|
}
|
|
if value, ok := wc.mutation.Dmg(); ok {
|
|
_spec.SetField(weapon.FieldDmg, field.TypeUint, value)
|
|
_node.Dmg = value
|
|
}
|
|
if value, ok := wc.mutation.EqType(); ok {
|
|
_spec.SetField(weapon.FieldEqType, field.TypeInt, value)
|
|
_node.EqType = value
|
|
}
|
|
if value, ok := wc.mutation.HitGroup(); ok {
|
|
_spec.SetField(weapon.FieldHitGroup, field.TypeInt, value)
|
|
_node.HitGroup = value
|
|
}
|
|
if nodes := wc.mutation.StatIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: weapon.StatTable,
|
|
Columns: []string{weapon.StatColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: matchplayer.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.match_player_weapon_stats = &nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// WeaponCreateBulk is the builder for creating many Weapon entities in bulk.
|
|
type WeaponCreateBulk struct {
|
|
config
|
|
builders []*WeaponCreate
|
|
}
|
|
|
|
// Save creates the Weapon entities in the database.
|
|
func (wcb *WeaponCreateBulk) Save(ctx context.Context) ([]*Weapon, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(wcb.builders))
|
|
nodes := make([]*Weapon, 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.(*WeaponMutation)
|
|
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 {
|
|
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 *WeaponCreateBulk) SaveX(ctx context.Context) []*Weapon {
|
|
v, err := wcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wcb *WeaponCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := wcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wcb *WeaponCreateBulk) ExecX(ctx context.Context) {
|
|
if err := wcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|