import from unified repo
This commit is contained in:
531
ent/player_create.go
Normal file
531
ent/player_create.go
Normal file
@@ -0,0 +1,531 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// PlayerCreate is the builder for creating a Player entity.
|
||||
type PlayerCreate struct {
|
||||
config
|
||||
mutation *PlayerMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetSteamid sets the "steamid" field.
|
||||
func (pc *PlayerCreate) SetSteamid(u uint64) *PlayerCreate {
|
||||
pc.mutation.SetSteamid(u)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (pc *PlayerCreate) SetName(s string) *PlayerCreate {
|
||||
pc.mutation.SetName(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableName(s *string) *PlayerCreate {
|
||||
if s != nil {
|
||||
pc.SetName(*s)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetAvatarURL sets the "avatar_url" field.
|
||||
func (pc *PlayerCreate) SetAvatarURL(s string) *PlayerCreate {
|
||||
pc.mutation.SetAvatarURL(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableAvatarURL sets the "avatar_url" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableAvatarURL(s *string) *PlayerCreate {
|
||||
if s != nil {
|
||||
pc.SetAvatarURL(*s)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetVanityURL sets the "vanity_url" field.
|
||||
func (pc *PlayerCreate) SetVanityURL(s string) *PlayerCreate {
|
||||
pc.mutation.SetVanityURL(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableVanityURL sets the "vanity_url" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableVanityURL(s *string) *PlayerCreate {
|
||||
if s != nil {
|
||||
pc.SetVanityURL(*s)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetVanityURLReal sets the "vanity_url_real" field.
|
||||
func (pc *PlayerCreate) SetVanityURLReal(s string) *PlayerCreate {
|
||||
pc.mutation.SetVanityURLReal(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableVanityURLReal sets the "vanity_url_real" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableVanityURLReal(s *string) *PlayerCreate {
|
||||
if s != nil {
|
||||
pc.SetVanityURLReal(*s)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetVac sets the "vac" field.
|
||||
func (pc *PlayerCreate) SetVac(b bool) *PlayerCreate {
|
||||
pc.mutation.SetVac(b)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableVac sets the "vac" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableVac(b *bool) *PlayerCreate {
|
||||
if b != nil {
|
||||
pc.SetVac(*b)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetVacDate sets the "vac_date" field.
|
||||
func (pc *PlayerCreate) SetVacDate(t time.Time) *PlayerCreate {
|
||||
pc.mutation.SetVacDate(t)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableVacDate sets the "vac_date" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableVacDate(t *time.Time) *PlayerCreate {
|
||||
if t != nil {
|
||||
pc.SetVacDate(*t)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetVacCount sets the "vac_count" field.
|
||||
func (pc *PlayerCreate) SetVacCount(i int) *PlayerCreate {
|
||||
pc.mutation.SetVacCount(i)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableVacCount sets the "vac_count" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableVacCount(i *int) *PlayerCreate {
|
||||
if i != nil {
|
||||
pc.SetVacCount(*i)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetSteamUpdated sets the "steam_updated" field.
|
||||
func (pc *PlayerCreate) SetSteamUpdated(t time.Time) *PlayerCreate {
|
||||
pc.mutation.SetSteamUpdated(t)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableSteamUpdated sets the "steam_updated" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableSteamUpdated(t *time.Time) *PlayerCreate {
|
||||
if t != nil {
|
||||
pc.SetSteamUpdated(*t)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetSharecodeUpdated sets the "sharecode_updated" field.
|
||||
func (pc *PlayerCreate) SetSharecodeUpdated(t time.Time) *PlayerCreate {
|
||||
pc.mutation.SetSharecodeUpdated(t)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableSharecodeUpdated sets the "sharecode_updated" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableSharecodeUpdated(t *time.Time) *PlayerCreate {
|
||||
if t != nil {
|
||||
pc.SetSharecodeUpdated(*t)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetAuthCode sets the "auth_code" field.
|
||||
func (pc *PlayerCreate) SetAuthCode(s string) *PlayerCreate {
|
||||
pc.mutation.SetAuthCode(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableAuthCode sets the "auth_code" field if the given value is not nil.
|
||||
func (pc *PlayerCreate) SetNillableAuthCode(s *string) *PlayerCreate {
|
||||
if s != nil {
|
||||
pc.SetAuthCode(*s)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
|
||||
func (pc *PlayerCreate) AddStatIDs(ids ...int) *PlayerCreate {
|
||||
pc.mutation.AddStatIDs(ids...)
|
||||
return pc
|
||||
}
|
||||
|
||||
// AddStats adds the "stats" edges to the Stats entity.
|
||||
func (pc *PlayerCreate) AddStats(s ...*Stats) *PlayerCreate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return pc.AddStatIDs(ids...)
|
||||
}
|
||||
|
||||
// AddMatchIDs adds the "matches" edge to the Match entity by IDs.
|
||||
func (pc *PlayerCreate) AddMatchIDs(ids ...int) *PlayerCreate {
|
||||
pc.mutation.AddMatchIDs(ids...)
|
||||
return pc
|
||||
}
|
||||
|
||||
// AddMatches adds the "matches" edges to the Match entity.
|
||||
func (pc *PlayerCreate) AddMatches(m ...*Match) *PlayerCreate {
|
||||
ids := make([]int, len(m))
|
||||
for i := range m {
|
||||
ids[i] = m[i].ID
|
||||
}
|
||||
return pc.AddMatchIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the PlayerMutation object of the builder.
|
||||
func (pc *PlayerCreate) Mutation() *PlayerMutation {
|
||||
return pc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Player in the database.
|
||||
func (pc *PlayerCreate) Save(ctx context.Context) (*Player, error) {
|
||||
var (
|
||||
err error
|
||||
node *Player
|
||||
)
|
||||
pc.defaults()
|
||||
if len(pc.hooks) == 0 {
|
||||
if err = pc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = pc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PlayerMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = pc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pc.mutation = mutation
|
||||
if node, err = pc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(pc.hooks) - 1; i >= 0; i-- {
|
||||
if pc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = pc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, pc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (pc *PlayerCreate) SaveX(ctx context.Context) *Player {
|
||||
v, err := pc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pc *PlayerCreate) Exec(ctx context.Context) error {
|
||||
_, err := pc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pc *PlayerCreate) ExecX(ctx context.Context) {
|
||||
if err := pc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (pc *PlayerCreate) defaults() {
|
||||
if _, ok := pc.mutation.Vac(); !ok {
|
||||
v := player.DefaultVac
|
||||
pc.mutation.SetVac(v)
|
||||
}
|
||||
if _, ok := pc.mutation.SteamUpdated(); !ok {
|
||||
v := player.DefaultSteamUpdated()
|
||||
pc.mutation.SetSteamUpdated(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (pc *PlayerCreate) check() error {
|
||||
if _, ok := pc.mutation.Steamid(); !ok {
|
||||
return &ValidationError{Name: "steamid", err: errors.New(`ent: missing required field "steamid"`)}
|
||||
}
|
||||
if _, ok := pc.mutation.Vac(); !ok {
|
||||
return &ValidationError{Name: "vac", err: errors.New(`ent: missing required field "vac"`)}
|
||||
}
|
||||
if _, ok := pc.mutation.SteamUpdated(); !ok {
|
||||
return &ValidationError{Name: "steam_updated", err: errors.New(`ent: missing required field "steam_updated"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pc *PlayerCreate) sqlSave(ctx context.Context) (*Player, error) {
|
||||
_node, _spec := pc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, pc.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 (pc *PlayerCreate) createSpec() (*Player, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Player{config: pc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: player.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: player.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := pc.mutation.Steamid(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUint64,
|
||||
Value: value,
|
||||
Column: player.FieldSteamid,
|
||||
})
|
||||
_node.Steamid = value
|
||||
}
|
||||
if value, ok := pc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: player.FieldName,
|
||||
})
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := pc.mutation.AvatarURL(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: player.FieldAvatarURL,
|
||||
})
|
||||
_node.AvatarURL = value
|
||||
}
|
||||
if value, ok := pc.mutation.VanityURL(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: player.FieldVanityURL,
|
||||
})
|
||||
_node.VanityURL = value
|
||||
}
|
||||
if value, ok := pc.mutation.VanityURLReal(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: player.FieldVanityURLReal,
|
||||
})
|
||||
_node.VanityURLReal = value
|
||||
}
|
||||
if value, ok := pc.mutation.Vac(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: player.FieldVac,
|
||||
})
|
||||
_node.Vac = value
|
||||
}
|
||||
if value, ok := pc.mutation.VacDate(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: player.FieldVacDate,
|
||||
})
|
||||
_node.VacDate = value
|
||||
}
|
||||
if value, ok := pc.mutation.VacCount(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: player.FieldVacCount,
|
||||
})
|
||||
_node.VacCount = value
|
||||
}
|
||||
if value, ok := pc.mutation.SteamUpdated(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: player.FieldSteamUpdated,
|
||||
})
|
||||
_node.SteamUpdated = value
|
||||
}
|
||||
if value, ok := pc.mutation.SharecodeUpdated(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: player.FieldSharecodeUpdated,
|
||||
})
|
||||
_node.SharecodeUpdated = value
|
||||
}
|
||||
if value, ok := pc.mutation.AuthCode(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: player.FieldAuthCode,
|
||||
})
|
||||
_node.AuthCode = value
|
||||
}
|
||||
if nodes := pc.mutation.StatsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: player.StatsTable,
|
||||
Columns: []string{player.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 := pc.mutation.MatchesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: player.MatchesTable,
|
||||
Columns: player.MatchesPrimaryKey,
|
||||
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)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// PlayerCreateBulk is the builder for creating many Player entities in bulk.
|
||||
type PlayerCreateBulk struct {
|
||||
config
|
||||
builders []*PlayerCreate
|
||||
}
|
||||
|
||||
// Save creates the Player entities in the database.
|
||||
func (pcb *PlayerCreateBulk) Save(ctx context.Context) ([]*Player, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(pcb.builders))
|
||||
nodes := make([]*Player, len(pcb.builders))
|
||||
mutators := make([]Mutator, len(pcb.builders))
|
||||
for i := range pcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := pcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PlayerMutation)
|
||||
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, pcb.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, pcb.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, pcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (pcb *PlayerCreateBulk) SaveX(ctx context.Context) []*Player {
|
||||
v, err := pcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pcb *PlayerCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := pcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pcb *PlayerCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := pcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user