added spray patterns
This commit is contained in:
277
ent/spray_create.go
Normal file
277
ent/spray_create.go
Normal file
@@ -0,0 +1,277 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"csgowtfd/ent/matchplayer"
|
||||
"csgowtfd/ent/spray"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SprayCreate is the builder for creating a Spray entity.
|
||||
type SprayCreate struct {
|
||||
config
|
||||
mutation *SprayMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetWeapon sets the "weapon" field.
|
||||
func (sc *SprayCreate) SetWeapon(i int) *SprayCreate {
|
||||
sc.mutation.SetWeapon(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetSpray sets the "spray" field.
|
||||
func (sc *SprayCreate) SetSpray(b []byte) *SprayCreate {
|
||||
sc.mutation.SetSpray(b)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID.
|
||||
func (sc *SprayCreate) SetMatchPlayersID(id int) *SprayCreate {
|
||||
sc.mutation.SetMatchPlayersID(id)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID if the given value is not nil.
|
||||
func (sc *SprayCreate) SetNillableMatchPlayersID(id *int) *SprayCreate {
|
||||
if id != nil {
|
||||
sc = sc.SetMatchPlayersID(*id)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetMatchPlayers sets the "match_players" edge to the MatchPlayer entity.
|
||||
func (sc *SprayCreate) SetMatchPlayers(m *MatchPlayer) *SprayCreate {
|
||||
return sc.SetMatchPlayersID(m.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SprayMutation object of the builder.
|
||||
func (sc *SprayCreate) Mutation() *SprayMutation {
|
||||
return sc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Spray in the database.
|
||||
func (sc *SprayCreate) Save(ctx context.Context) (*Spray, error) {
|
||||
var (
|
||||
err error
|
||||
node *Spray
|
||||
)
|
||||
if len(sc.hooks) == 0 {
|
||||
if err = sc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = sc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SprayMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = sc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sc.mutation = mutation
|
||||
if node, err = sc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(sc.hooks) - 1; i >= 0; i-- {
|
||||
if sc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = sc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, sc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sc *SprayCreate) SaveX(ctx context.Context) *Spray {
|
||||
v, err := sc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sc *SprayCreate) Exec(ctx context.Context) error {
|
||||
_, err := sc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sc *SprayCreate) ExecX(ctx context.Context) {
|
||||
if err := sc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sc *SprayCreate) check() error {
|
||||
if _, ok := sc.mutation.Weapon(); !ok {
|
||||
return &ValidationError{Name: "weapon", err: errors.New(`ent: missing required field "weapon"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Spray(); !ok {
|
||||
return &ValidationError{Name: "spray", err: errors.New(`ent: missing required field "spray"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *SprayCreate) sqlSave(ctx context.Context) (*Spray, error) {
|
||||
_node, _spec := sc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sc.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 (sc *SprayCreate) createSpec() (*Spray, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Spray{config: sc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: spray.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: spray.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := sc.mutation.Weapon(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: spray.FieldWeapon,
|
||||
})
|
||||
_node.Weapon = value
|
||||
}
|
||||
if value, ok := sc.mutation.Spray(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: spray.FieldSpray,
|
||||
})
|
||||
_node.Spray = value
|
||||
}
|
||||
if nodes := sc.mutation.MatchPlayersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: spray.MatchPlayersTable,
|
||||
Columns: []string{spray.MatchPlayersColumn},
|
||||
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_spray = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// SprayCreateBulk is the builder for creating many Spray entities in bulk.
|
||||
type SprayCreateBulk struct {
|
||||
config
|
||||
builders []*SprayCreate
|
||||
}
|
||||
|
||||
// Save creates the Spray entities in the database.
|
||||
func (scb *SprayCreateBulk) Save(ctx context.Context) ([]*Spray, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
||||
nodes := make([]*Spray, len(scb.builders))
|
||||
mutators := make([]Mutator, len(scb.builders))
|
||||
for i := range scb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := scb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SprayMutation)
|
||||
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, scb.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, scb.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, scb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (scb *SprayCreateBulk) SaveX(ctx context.Context) []*Spray {
|
||||
v, err := scb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (scb *SprayCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := scb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (scb *SprayCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := scb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user