import from unified repo
This commit is contained in:
518
ent/stats_create.go
Normal file
518
ent/stats_create.go
Normal file
@@ -0,0 +1,518 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"csgowtfd/ent/match"
|
||||
"csgowtfd/ent/player"
|
||||
"csgowtfd/ent/stats"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// StatsCreate is the builder for creating a Stats entity.
|
||||
type StatsCreate struct {
|
||||
config
|
||||
mutation *StatsMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetTeamID sets the "team_id" field.
|
||||
func (sc *StatsCreate) SetTeamID(i int) *StatsCreate {
|
||||
sc.mutation.SetTeamID(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetKills sets the "kills" field.
|
||||
func (sc *StatsCreate) SetKills(i int) *StatsCreate {
|
||||
sc.mutation.SetKills(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetDeaths sets the "deaths" field.
|
||||
func (sc *StatsCreate) SetDeaths(i int) *StatsCreate {
|
||||
sc.mutation.SetDeaths(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetAssists sets the "assists" field.
|
||||
func (sc *StatsCreate) SetAssists(i int) *StatsCreate {
|
||||
sc.mutation.SetAssists(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetHeadshot sets the "headshot" field.
|
||||
func (sc *StatsCreate) SetHeadshot(i int) *StatsCreate {
|
||||
sc.mutation.SetHeadshot(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetMvp sets the "mvp" field.
|
||||
func (sc *StatsCreate) SetMvp(i int) *StatsCreate {
|
||||
sc.mutation.SetMvp(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetScore sets the "score" field.
|
||||
func (sc *StatsCreate) SetScore(i int) *StatsCreate {
|
||||
sc.mutation.SetScore(i)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetExtended sets the "extended" field.
|
||||
func (sc *StatsCreate) SetExtended(skkgaaaallllg struct {
|
||||
MultiKills struct {
|
||||
Duo int "json:\"duo,omitempty\""
|
||||
Triple int "json:\"triple,omitempty\""
|
||||
Quad int "json:\"quad,omitempty\""
|
||||
Pent int "json:\"pent,omitempty\""
|
||||
} "json:\"multi_kills,omitempty\""
|
||||
Dmg struct {
|
||||
Enemy int "json:\"enemy,omitempty\""
|
||||
Team int "json:\"team,omitempty\""
|
||||
UD struct {
|
||||
HE int "json:\"he,omitempty\""
|
||||
Flames int "json:\"flames,omitempty\""
|
||||
Flash int "json:\"flash,omitempty\""
|
||||
Decoy int "json:\"decoy,omitempty\""
|
||||
Smoke int "json:\"smoke,omitempty\""
|
||||
} "json:\"ud,omitempty\""
|
||||
HitGroup struct {
|
||||
Head int "json:\"head,omitempty\""
|
||||
Chest int "json:\"chest,omitempty\""
|
||||
Stomach int "json:\"stomach,omitempty\""
|
||||
LeftArm int "json:\"left_arm,omitempty\""
|
||||
RightArm int "json:\"right_arm,omitempty\""
|
||||
LeftLeg int "json:\"left_leg,omitempty\""
|
||||
RightLeg int "json:\"right_leg,omitempty\""
|
||||
Gear int "json:\"gear,omitempty\""
|
||||
} "json:\"hit_group,omitempty\""
|
||||
} "json:\"dmg,omitempty\""
|
||||
Crosshair string "json:\"crosshair,omitempty\""
|
||||
Color int "json:\"color,omitempty\""
|
||||
KAST int "json:\"kast,omitempty\""
|
||||
Rank struct {
|
||||
Old int "json:\"old,omitempty\""
|
||||
New int "json:\"new,omitempty\""
|
||||
} "json:\"rank,omitempty\""
|
||||
Flash struct {
|
||||
Duration struct {
|
||||
Self float32 "json:\"self,omitempty\""
|
||||
Team float32 "json:\"team,omitempty\""
|
||||
Enemy float32 "json:\"enemy,omitempty\""
|
||||
} "json:\"duration,omitempty\""
|
||||
Total struct {
|
||||
Team int "json:\"team,omitempty\""
|
||||
Enemy int "json:\"enemy,omitempty\""
|
||||
Self int "json:\"self,omitempty\""
|
||||
} "json:\"total,omitempty\""
|
||||
} "json:\"flash,omitempty\""
|
||||
}) *StatsCreate {
|
||||
sc.mutation.SetExtended(skkgaaaallllg)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableExtended sets the "extended" field if the given value is not nil.
|
||||
func (sc *StatsCreate) SetNillableExtended(skkgaaaallllg *struct {
|
||||
MultiKills struct {
|
||||
Duo int "json:\"duo,omitempty\""
|
||||
Triple int "json:\"triple,omitempty\""
|
||||
Quad int "json:\"quad,omitempty\""
|
||||
Pent int "json:\"pent,omitempty\""
|
||||
} "json:\"multi_kills,omitempty\""
|
||||
Dmg struct {
|
||||
Enemy int "json:\"enemy,omitempty\""
|
||||
Team int "json:\"team,omitempty\""
|
||||
UD struct {
|
||||
HE int "json:\"he,omitempty\""
|
||||
Flames int "json:\"flames,omitempty\""
|
||||
Flash int "json:\"flash,omitempty\""
|
||||
Decoy int "json:\"decoy,omitempty\""
|
||||
Smoke int "json:\"smoke,omitempty\""
|
||||
} "json:\"ud,omitempty\""
|
||||
HitGroup struct {
|
||||
Head int "json:\"head,omitempty\""
|
||||
Chest int "json:\"chest,omitempty\""
|
||||
Stomach int "json:\"stomach,omitempty\""
|
||||
LeftArm int "json:\"left_arm,omitempty\""
|
||||
RightArm int "json:\"right_arm,omitempty\""
|
||||
LeftLeg int "json:\"left_leg,omitempty\""
|
||||
RightLeg int "json:\"right_leg,omitempty\""
|
||||
Gear int "json:\"gear,omitempty\""
|
||||
} "json:\"hit_group,omitempty\""
|
||||
} "json:\"dmg,omitempty\""
|
||||
Crosshair string "json:\"crosshair,omitempty\""
|
||||
Color int "json:\"color,omitempty\""
|
||||
KAST int "json:\"kast,omitempty\""
|
||||
Rank struct {
|
||||
Old int "json:\"old,omitempty\""
|
||||
New int "json:\"new,omitempty\""
|
||||
} "json:\"rank,omitempty\""
|
||||
Flash struct {
|
||||
Duration struct {
|
||||
Self float32 "json:\"self,omitempty\""
|
||||
Team float32 "json:\"team,omitempty\""
|
||||
Enemy float32 "json:\"enemy,omitempty\""
|
||||
} "json:\"duration,omitempty\""
|
||||
Total struct {
|
||||
Team int "json:\"team,omitempty\""
|
||||
Enemy int "json:\"enemy,omitempty\""
|
||||
Self int "json:\"self,omitempty\""
|
||||
} "json:\"total,omitempty\""
|
||||
} "json:\"flash,omitempty\""
|
||||
}) *StatsCreate {
|
||||
if skkgaaaallllg != nil {
|
||||
sc.SetExtended(*skkgaaaallllg)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetMatchesID sets the "matches" edge to the Match entity by ID.
|
||||
func (sc *StatsCreate) SetMatchesID(id int) *StatsCreate {
|
||||
sc.mutation.SetMatchesID(id)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableMatchesID sets the "matches" edge to the Match entity by ID if the given value is not nil.
|
||||
func (sc *StatsCreate) SetNillableMatchesID(id *int) *StatsCreate {
|
||||
if id != nil {
|
||||
sc = sc.SetMatchesID(*id)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetMatches sets the "matches" edge to the Match entity.
|
||||
func (sc *StatsCreate) SetMatches(m *Match) *StatsCreate {
|
||||
return sc.SetMatchesID(m.ID)
|
||||
}
|
||||
|
||||
// SetPlayersID sets the "players" edge to the Player entity by ID.
|
||||
func (sc *StatsCreate) SetPlayersID(id int) *StatsCreate {
|
||||
sc.mutation.SetPlayersID(id)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillablePlayersID sets the "players" edge to the Player entity by ID if the given value is not nil.
|
||||
func (sc *StatsCreate) SetNillablePlayersID(id *int) *StatsCreate {
|
||||
if id != nil {
|
||||
sc = sc.SetPlayersID(*id)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetPlayers sets the "players" edge to the Player entity.
|
||||
func (sc *StatsCreate) SetPlayers(p *Player) *StatsCreate {
|
||||
return sc.SetPlayersID(p.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the StatsMutation object of the builder.
|
||||
func (sc *StatsCreate) Mutation() *StatsMutation {
|
||||
return sc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Stats in the database.
|
||||
func (sc *StatsCreate) Save(ctx context.Context) (*Stats, error) {
|
||||
var (
|
||||
err error
|
||||
node *Stats
|
||||
)
|
||||
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.(*StatsMutation)
|
||||
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 *StatsCreate) SaveX(ctx context.Context) *Stats {
|
||||
v, err := sc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sc *StatsCreate) Exec(ctx context.Context) error {
|
||||
_, err := sc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sc *StatsCreate) 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 *StatsCreate) check() error {
|
||||
if _, ok := sc.mutation.TeamID(); !ok {
|
||||
return &ValidationError{Name: "team_id", err: errors.New(`ent: missing required field "team_id"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Kills(); !ok {
|
||||
return &ValidationError{Name: "kills", err: errors.New(`ent: missing required field "kills"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Deaths(); !ok {
|
||||
return &ValidationError{Name: "deaths", err: errors.New(`ent: missing required field "deaths"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Assists(); !ok {
|
||||
return &ValidationError{Name: "assists", err: errors.New(`ent: missing required field "assists"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Headshot(); !ok {
|
||||
return &ValidationError{Name: "headshot", err: errors.New(`ent: missing required field "headshot"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Mvp(); !ok {
|
||||
return &ValidationError{Name: "mvp", err: errors.New(`ent: missing required field "mvp"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Score(); !ok {
|
||||
return &ValidationError{Name: "score", err: errors.New(`ent: missing required field "score"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *StatsCreate) sqlSave(ctx context.Context) (*Stats, 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 *StatsCreate) createSpec() (*Stats, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Stats{config: sc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: stats.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: stats.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := sc.mutation.TeamID(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldTeamID,
|
||||
})
|
||||
_node.TeamID = value
|
||||
}
|
||||
if value, ok := sc.mutation.Kills(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldKills,
|
||||
})
|
||||
_node.Kills = value
|
||||
}
|
||||
if value, ok := sc.mutation.Deaths(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldDeaths,
|
||||
})
|
||||
_node.Deaths = value
|
||||
}
|
||||
if value, ok := sc.mutation.Assists(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldAssists,
|
||||
})
|
||||
_node.Assists = value
|
||||
}
|
||||
if value, ok := sc.mutation.Headshot(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldHeadshot,
|
||||
})
|
||||
_node.Headshot = value
|
||||
}
|
||||
if value, ok := sc.mutation.Mvp(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldMvp,
|
||||
})
|
||||
_node.Mvp = value
|
||||
}
|
||||
if value, ok := sc.mutation.Score(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: stats.FieldScore,
|
||||
})
|
||||
_node.Score = value
|
||||
}
|
||||
if value, ok := sc.mutation.Extended(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: stats.FieldExtended,
|
||||
})
|
||||
_node.Extended = value
|
||||
}
|
||||
if nodes := sc.mutation.MatchesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: stats.MatchesTable,
|
||||
Columns: []string{stats.MatchesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: match.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.match_stats = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := sc.mutation.PlayersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: stats.PlayersTable,
|
||||
Columns: []string{stats.PlayersColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: player.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.player_stats = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// StatsCreateBulk is the builder for creating many Stats entities in bulk.
|
||||
type StatsCreateBulk struct {
|
||||
config
|
||||
builders []*StatsCreate
|
||||
}
|
||||
|
||||
// Save creates the Stats entities in the database.
|
||||
func (scb *StatsCreateBulk) Save(ctx context.Context) ([]*Stats, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
||||
nodes := make([]*Stats, 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.(*StatsMutation)
|
||||
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 *StatsCreateBulk) SaveX(ctx context.Context) []*Stats {
|
||||
v, err := scb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (scb *StatsCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := scb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (scb *StatsCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := scb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user