import from unified repo
This commit is contained in:
552
ent/match_create.go
Normal file
552
ent/match_create.go
Normal file
@@ -0,0 +1,552 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"csgowtfd/ent/match"
|
||||
"csgowtfd/ent/player"
|
||||
"csgowtfd/ent/stats"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MatchCreate is the builder for creating a Match entity.
|
||||
type MatchCreate struct {
|
||||
config
|
||||
mutation *MatchMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetMatchID sets the "match_id" field.
|
||||
func (mc *MatchCreate) SetMatchID(u uint64) *MatchCreate {
|
||||
mc.mutation.SetMatchID(u)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetShareCode sets the "share_code" field.
|
||||
func (mc *MatchCreate) SetShareCode(s string) *MatchCreate {
|
||||
mc.mutation.SetShareCode(s)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetMap sets the "map" field.
|
||||
func (mc *MatchCreate) SetMap(s string) *MatchCreate {
|
||||
mc.mutation.SetMap(s)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableMap sets the "map" field if the given value is not nil.
|
||||
func (mc *MatchCreate) SetNillableMap(s *string) *MatchCreate {
|
||||
if s != nil {
|
||||
mc.SetMap(*s)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (mc *MatchCreate) SetDate(t time.Time) *MatchCreate {
|
||||
mc.mutation.SetDate(t)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetScoreTeamA sets the "score_team_a" field.
|
||||
func (mc *MatchCreate) SetScoreTeamA(i int) *MatchCreate {
|
||||
mc.mutation.SetScoreTeamA(i)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetScoreTeamB sets the "score_team_b" field.
|
||||
func (mc *MatchCreate) SetScoreTeamB(i int) *MatchCreate {
|
||||
mc.mutation.SetScoreTeamB(i)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetReplayURL sets the "replay_url" field.
|
||||
func (mc *MatchCreate) SetReplayURL(s string) *MatchCreate {
|
||||
mc.mutation.SetReplayURL(s)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableReplayURL sets the "replay_url" field if the given value is not nil.
|
||||
func (mc *MatchCreate) SetNillableReplayURL(s *string) *MatchCreate {
|
||||
if s != nil {
|
||||
mc.SetReplayURL(*s)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetDuration sets the "duration" field.
|
||||
func (mc *MatchCreate) SetDuration(i int) *MatchCreate {
|
||||
mc.mutation.SetDuration(i)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetMatchResult sets the "match_result" field.
|
||||
func (mc *MatchCreate) SetMatchResult(i int) *MatchCreate {
|
||||
mc.mutation.SetMatchResult(i)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetMaxRounds sets the "max_rounds" field.
|
||||
func (mc *MatchCreate) SetMaxRounds(i int) *MatchCreate {
|
||||
mc.mutation.SetMaxRounds(i)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetDemoExpired sets the "demo_expired" field.
|
||||
func (mc *MatchCreate) SetDemoExpired(b bool) *MatchCreate {
|
||||
mc.mutation.SetDemoExpired(b)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableDemoExpired sets the "demo_expired" field if the given value is not nil.
|
||||
func (mc *MatchCreate) SetNillableDemoExpired(b *bool) *MatchCreate {
|
||||
if b != nil {
|
||||
mc.SetDemoExpired(*b)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetDemoParsed sets the "demo_parsed" field.
|
||||
func (mc *MatchCreate) SetDemoParsed(b bool) *MatchCreate {
|
||||
mc.mutation.SetDemoParsed(b)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableDemoParsed sets the "demo_parsed" field if the given value is not nil.
|
||||
func (mc *MatchCreate) SetNillableDemoParsed(b *bool) *MatchCreate {
|
||||
if b != nil {
|
||||
mc.SetDemoParsed(*b)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetEco sets the "eco" field.
|
||||
func (mc *MatchCreate) SetEco(s struct {
|
||||
Rounds []*struct {
|
||||
Team int "json:\"team\""
|
||||
Bank int "json:\"bank\""
|
||||
Equipment int "json:\"equipment\""
|
||||
} "json:\"rounds\""
|
||||
}) *MatchCreate {
|
||||
mc.mutation.SetEco(s)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableEco sets the "eco" field if the given value is not nil.
|
||||
func (mc *MatchCreate) SetNillableEco(s *struct {
|
||||
Rounds []*struct {
|
||||
Team int "json:\"team\""
|
||||
Bank int "json:\"bank\""
|
||||
Equipment int "json:\"equipment\""
|
||||
} "json:\"rounds\""
|
||||
}) *MatchCreate {
|
||||
if s != nil {
|
||||
mc.SetEco(*s)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
|
||||
func (mc *MatchCreate) AddStatIDs(ids ...int) *MatchCreate {
|
||||
mc.mutation.AddStatIDs(ids...)
|
||||
return mc
|
||||
}
|
||||
|
||||
// AddStats adds the "stats" edges to the Stats entity.
|
||||
func (mc *MatchCreate) AddStats(s ...*Stats) *MatchCreate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return mc.AddStatIDs(ids...)
|
||||
}
|
||||
|
||||
// AddPlayerIDs adds the "players" edge to the Player entity by IDs.
|
||||
func (mc *MatchCreate) AddPlayerIDs(ids ...int) *MatchCreate {
|
||||
mc.mutation.AddPlayerIDs(ids...)
|
||||
return mc
|
||||
}
|
||||
|
||||
// AddPlayers adds the "players" edges to the Player entity.
|
||||
func (mc *MatchCreate) AddPlayers(p ...*Player) *MatchCreate {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return mc.AddPlayerIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the MatchMutation object of the builder.
|
||||
func (mc *MatchCreate) Mutation() *MatchMutation {
|
||||
return mc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Match in the database.
|
||||
func (mc *MatchCreate) Save(ctx context.Context) (*Match, error) {
|
||||
var (
|
||||
err error
|
||||
node *Match
|
||||
)
|
||||
mc.defaults()
|
||||
if len(mc.hooks) == 0 {
|
||||
if err = mc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = mc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*MatchMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = mc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mc.mutation = mutation
|
||||
if node, err = mc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(mc.hooks) - 1; i >= 0; i-- {
|
||||
if mc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = mc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, mc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (mc *MatchCreate) SaveX(ctx context.Context) *Match {
|
||||
v, err := mc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (mc *MatchCreate) Exec(ctx context.Context) error {
|
||||
_, err := mc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (mc *MatchCreate) ExecX(ctx context.Context) {
|
||||
if err := mc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (mc *MatchCreate) defaults() {
|
||||
if _, ok := mc.mutation.DemoExpired(); !ok {
|
||||
v := match.DefaultDemoExpired
|
||||
mc.mutation.SetDemoExpired(v)
|
||||
}
|
||||
if _, ok := mc.mutation.DemoParsed(); !ok {
|
||||
v := match.DefaultDemoParsed
|
||||
mc.mutation.SetDemoParsed(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (mc *MatchCreate) check() error {
|
||||
if _, ok := mc.mutation.MatchID(); !ok {
|
||||
return &ValidationError{Name: "match_id", err: errors.New(`ent: missing required field "match_id"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.ShareCode(); !ok {
|
||||
return &ValidationError{Name: "share_code", err: errors.New(`ent: missing required field "share_code"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.Date(); !ok {
|
||||
return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "date"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.ScoreTeamA(); !ok {
|
||||
return &ValidationError{Name: "score_team_a", err: errors.New(`ent: missing required field "score_team_a"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.ScoreTeamB(); !ok {
|
||||
return &ValidationError{Name: "score_team_b", err: errors.New(`ent: missing required field "score_team_b"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.Duration(); !ok {
|
||||
return &ValidationError{Name: "duration", err: errors.New(`ent: missing required field "duration"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.MatchResult(); !ok {
|
||||
return &ValidationError{Name: "match_result", err: errors.New(`ent: missing required field "match_result"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.MaxRounds(); !ok {
|
||||
return &ValidationError{Name: "max_rounds", err: errors.New(`ent: missing required field "max_rounds"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.DemoExpired(); !ok {
|
||||
return &ValidationError{Name: "demo_expired", err: errors.New(`ent: missing required field "demo_expired"`)}
|
||||
}
|
||||
if _, ok := mc.mutation.DemoParsed(); !ok {
|
||||
return &ValidationError{Name: "demo_parsed", err: errors.New(`ent: missing required field "demo_parsed"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mc *MatchCreate) sqlSave(ctx context.Context) (*Match, error) {
|
||||
_node, _spec := mc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, mc.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 (mc *MatchCreate) createSpec() (*Match, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Match{config: mc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: match.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: match.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := mc.mutation.MatchID(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUint64,
|
||||
Value: value,
|
||||
Column: match.FieldMatchID,
|
||||
})
|
||||
_node.MatchID = value
|
||||
}
|
||||
if value, ok := mc.mutation.ShareCode(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: match.FieldShareCode,
|
||||
})
|
||||
_node.ShareCode = value
|
||||
}
|
||||
if value, ok := mc.mutation.Map(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: match.FieldMap,
|
||||
})
|
||||
_node.Map = value
|
||||
}
|
||||
if value, ok := mc.mutation.Date(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: match.FieldDate,
|
||||
})
|
||||
_node.Date = value
|
||||
}
|
||||
if value, ok := mc.mutation.ScoreTeamA(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: match.FieldScoreTeamA,
|
||||
})
|
||||
_node.ScoreTeamA = value
|
||||
}
|
||||
if value, ok := mc.mutation.ScoreTeamB(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: match.FieldScoreTeamB,
|
||||
})
|
||||
_node.ScoreTeamB = value
|
||||
}
|
||||
if value, ok := mc.mutation.ReplayURL(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: match.FieldReplayURL,
|
||||
})
|
||||
_node.ReplayURL = value
|
||||
}
|
||||
if value, ok := mc.mutation.Duration(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: match.FieldDuration,
|
||||
})
|
||||
_node.Duration = value
|
||||
}
|
||||
if value, ok := mc.mutation.MatchResult(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: match.FieldMatchResult,
|
||||
})
|
||||
_node.MatchResult = value
|
||||
}
|
||||
if value, ok := mc.mutation.MaxRounds(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: match.FieldMaxRounds,
|
||||
})
|
||||
_node.MaxRounds = value
|
||||
}
|
||||
if value, ok := mc.mutation.DemoExpired(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: match.FieldDemoExpired,
|
||||
})
|
||||
_node.DemoExpired = value
|
||||
}
|
||||
if value, ok := mc.mutation.DemoParsed(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: match.FieldDemoParsed,
|
||||
})
|
||||
_node.DemoParsed = value
|
||||
}
|
||||
if value, ok := mc.mutation.Eco(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: match.FieldEco,
|
||||
})
|
||||
_node.Eco = value
|
||||
}
|
||||
if nodes := mc.mutation.StatsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: match.StatsTable,
|
||||
Columns: []string{match.StatsColumn},
|
||||
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)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := mc.mutation.PlayersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: match.PlayersTable,
|
||||
Columns: match.PlayersPrimaryKey,
|
||||
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)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// MatchCreateBulk is the builder for creating many Match entities in bulk.
|
||||
type MatchCreateBulk struct {
|
||||
config
|
||||
builders []*MatchCreate
|
||||
}
|
||||
|
||||
// Save creates the Match entities in the database.
|
||||
func (mcb *MatchCreateBulk) Save(ctx context.Context) ([]*Match, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(mcb.builders))
|
||||
nodes := make([]*Match, len(mcb.builders))
|
||||
mutators := make([]Mutator, len(mcb.builders))
|
||||
for i := range mcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := mcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*MatchMutation)
|
||||
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, mcb.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, mcb.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, mcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (mcb *MatchCreateBulk) SaveX(ctx context.Context) []*Match {
|
||||
v, err := mcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (mcb *MatchCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := mcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (mcb *MatchCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := mcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user