added spray patterns

This commit is contained in:
2021-10-31 08:40:02 +01:00
parent 268793f0e5
commit 978232dd0a
66 changed files with 16805 additions and 11903 deletions

View File

@@ -62,7 +62,7 @@ func SteamId2AccountId(steamId uint64) uint32 {
return uint32(steamId - 76561197960265728)
}
func playerStatsFromRound(round *protobuf.CMsgGCCStrike15V2_MatchmakingServerRoundStats, p *ent.Player) (int32, int32, int32, int32, int32, int32) {
func playerStatsFromRound(round *protobuf.CMsgGCCStrike15V2_MatchmakingServerRoundStats, p *ent.Player) (kills int32, deaths int32, assists int32, headshots int32, score int32, mvps int32) {
for i, acc := range round.GetReservation().GetAccountIds() {
if AccountId2SteamId(acc) == p.ID {
return round.GetKills()[i], round.GetDeaths()[i], round.GetAssists()[i], round.GetEnemyHeadshots()[i], round.GetScores()[i], round.GetMvps()[i]
@@ -431,7 +431,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
}
kills, deaths, assists, hs, score, mvp := playerStatsFromRound(lastRound, mPlayer)
err := d.db.Stats.Create().
err := d.db.MatchPlayer.Create().
SetMatches(tMatch).
SetPlayers(mPlayer).
SetTeamID(teamId).
@@ -451,15 +451,21 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
}
}
// clear cache for player
// clear cache or regen values player
for _, p := range players {
err = d.cache.Delete(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, p.ID))
if err != nil {
log.Warningf("[DL] Unable to delete cache key %s: %v", fmt.Sprintf(utils.SideMetaCacheKey, p.ID), err)
}
err = d.cache.Delete(context.Background(), fmt.Sprintf(utils.MatchMetaCacheKey, p.ID))
w, l, t, err := utils.GetWinLossTieForPlayer(p)
if err != nil {
log.Warningf("[DL] Unable to delete cache key %s: %v", fmt.Sprintf(utils.MatchMetaCacheKey, p.ID), err)
log.Warningf("[DL] Failure to calculate WinLossTie for player %d: %v", p.ID, err)
continue
}
err = p.Update().SetWins(w).SetTies(t).SetLooses(l).Exec(context.Background())
if err != nil {
log.Warningf("[DL] Failure to save WinLossTie for player %d: %v", p.ID, err)
}
}

View File

@@ -1,13 +1,16 @@
package csgo
import (
"bytes"
"compress/bzip2"
"context"
"csgowtfd/ent"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"encoding/gob"
"fmt"
"github.com/golang/geo/r2"
"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
@@ -29,10 +32,79 @@ type DemoParser struct {
db *ent.Client
}
type Encounter struct {
Spotted uint64
TimeToReact float32
FirstFrag bool
Spray []*Spray
CrosshairMovement r2.Point
Time time.Duration
}
type Sprays struct {
Sprayer uint64
Sprays []*Spray
Weapon int
}
type Spray struct {
Time time.Duration
Spray [][]float32
}
type DemoNotFoundError struct {
error
}
func (s *Sprays) Add(currentTime time.Duration, sprayPoint []float32, timeout int, maxLength int) {
sprayFound := false
for _, sp := range s.Sprays {
if currentTime.Milliseconds()-sp.Time.Milliseconds() <= int64(timeout) {
sprayFound = true
if len(sp.Spray) < maxLength+1 {
sp.Spray = append(sp.Spray, []float32{
sprayPoint[0] - sp.Spray[0][0],
sprayPoint[1] - sp.Spray[0][1],
})
}
}
}
if !sprayFound {
s.Sprays = append(s.Sprays, &Spray{
Time: currentTime,
Spray: [][]float32{sprayPoint},
})
}
}
func (s *Sprays) Avg() (avg [][]float32) {
var (
total int
)
total++
for _, sp := range s.Sprays {
for i, r2p := range sp.Spray {
if i == 0 {
continue
}
if len(avg) <= i-1 {
avg = append(avg, r2p)
} else {
avg[i-1][0] += r2p[0]
avg[i-1][1] += r2p[1]
}
}
}
for i, r2p := range avg {
avg[i][0] = r2p[0] / float32(total)
avg[i][1] = r2p[1] / float32(total)
}
return
}
func (p *DemoParser) Setup(db *ent.Client, worker int) error {
p.demoQueue = make(chan *Demo, 1000)
p.db = db
@@ -51,10 +123,10 @@ func (p *DemoParser) ParseDemo(demo *Demo) error {
}
}
func (p *DemoParser) downloadDecompressReplay(demo *Demo) (io.Reader, error) {
log.Debugf("[DP] Downloading replay for %d", demo.MatchId)
func (d *Demo) download() (io.Reader, error) {
log.Debugf("[DP] Downloading replay for %d", d.MatchId)
r, err := http.Get(demo.Url)
r, err := http.Get(d.Url)
if err != nil {
return nil, err
}
@@ -65,8 +137,8 @@ func (p *DemoParser) downloadDecompressReplay(demo *Demo) (io.Reader, error) {
return bzip2.NewReader(r.Body), nil
}
func (p *DemoParser) getDBPlayer(demo *Demo, demoPlayer *common.Player) (*ent.Stats, error) {
tMatchPlayer, err := p.db.Stats.Query().WithMatches(func(q *ent.MatchQuery) {
func (p *DemoParser) getDBPlayer(demo *Demo, demoPlayer *common.Player) (*ent.MatchPlayer, error) {
tMatchPlayer, err := p.db.MatchPlayer.Query().WithMatches(func(q *ent.MatchQuery) {
q.Where(match.ID(demo.MatchId))
}).WithPlayers(func(q *ent.PlayerQuery) {
q.Where(player.ID(demoPlayer.SteamID64))
@@ -78,7 +150,7 @@ func (p *DemoParser) getDBPlayer(demo *Demo, demoPlayer *common.Player) (*ent.St
return tMatchPlayer, nil
}
func (p *DemoParser) getMatchPlayerBySteamID(stats []*ent.Stats, steamId uint64) *ent.Stats {
func (p *DemoParser) getMatchPlayerBySteamID(stats []*ent.MatchPlayer, steamId uint64) *ent.MatchPlayer {
for _, tStats := range stats {
tPLayer, err := tStats.Edges.PlayersOrErr()
if err != nil {
@@ -112,7 +184,7 @@ func (p *DemoParser) parseWorker() {
}
startTime := time.Now()
fDemo, err := p.downloadDecompressReplay(demo)
fDemo, err := demo.download()
if err != nil {
if _, ok := err.(DemoNotFoundError); ok {
if tMatch.Date.Before(time.Now().UTC().AddDate(0, 0, -30)) {
@@ -146,8 +218,47 @@ func (p *DemoParser) parseWorker() {
Bank int
Spent int
}, 0)
encounters := make([]*Encounter, 0)
spays := make([]*Sprays, 0)
demoParser := demoinfocs.NewParser(fDemo)
// onPlayerSpotted
demoParser.RegisterEventHandler(func(e events.PlayerSpottersChanged) {
gs := demoParser.GameState()
if !gs.IsMatchStarted() {
return
}
encounters = append(encounters, &Encounter{
Spotted: e.Spotted.SteamID64,
Time: demoParser.CurrentTime(),
})
})
// onWeaponFire
demoParser.RegisterEventHandler(func(e events.WeaponFire) {
gs := demoParser.GameState()
if !gs.IsMatchStarted() {
return
}
playerWeaponFound := false
for _, spray := range spays {
if e.Shooter.SteamID64 == spray.Sprayer && int(e.Weapon.Type) == spray.Weapon {
playerWeaponFound = true
spray.Add(demoParser.CurrentTime(), []float32{e.Shooter.ViewDirectionX(), e.Shooter.ViewDirectionY()}, 500, 10)
}
}
if !playerWeaponFound {
spays = append(spays, &Sprays{
Sprayer: e.Shooter.SteamID64,
Sprays: []*Spray{{demoParser.CurrentTime(), [][]float32{{e.Shooter.ViewDirectionX(), e.Shooter.ViewDirectionY()}}}},
Weapon: int(e.Weapon.Type),
})
}
})
// onPlayerHurt
demoParser.RegisterEventHandler(func(e events.PlayerHurt) {
if e.Attacker == nil || e.Player == nil || e.Weapon == nil || !demoParser.GameState().IsMatchStarted() {
@@ -244,22 +355,22 @@ func (p *DemoParser) parseWorker() {
tMatchPlayer.Crosshair = demoPlayer.CrosshairCode()
switch demoPlayer.Color() {
case common.Yellow:
tMatchPlayer.Color = stats.ColorYellow
tMatchPlayer.Color = matchplayer.ColorYellow
break
case common.Green:
tMatchPlayer.Color = stats.ColorGreen
tMatchPlayer.Color = matchplayer.ColorGreen
break
case common.Purple:
tMatchPlayer.Color = stats.ColorPurple
tMatchPlayer.Color = matchplayer.ColorPurple
break
case common.Blue:
tMatchPlayer.Color = stats.ColorBlue
tMatchPlayer.Color = matchplayer.ColorBlue
break
case common.Orange:
tMatchPlayer.Color = stats.ColorOrange
tMatchPlayer.Color = matchplayer.ColorOrange
break
default:
tMatchPlayer.Color = stats.ColorGrey
tMatchPlayer.Color = matchplayer.ColorGrey
}
}
}
@@ -289,7 +400,7 @@ func (p *DemoParser) parseWorker() {
for _, tMatchPlayer := range tStats {
if tMatchPlayer.Color == "" {
tMatchPlayer.Color = stats.ColorGrey
tMatchPlayer.Color = matchplayer.ColorGrey
}
nMatchPLayer, err := tMatchPlayer.Update().
@@ -318,18 +429,37 @@ func (p *DemoParser) parseWorker() {
}
for _, eqDmg := range eqMap[tMatchPlayer.PlayerStats] {
err := p.db.WeaponStats.Create().SetStat(nMatchPLayer).SetDmg(eqDmg.Dmg).SetVictim(eqDmg.To).SetHitGroup(eqDmg.HitGroup).SetEqType(eqDmg.Eq).Exec(context.Background())
err := p.db.Weapon.Create().SetStat(nMatchPLayer).SetDmg(eqDmg.Dmg).SetVictim(eqDmg.To).SetHitGroup(eqDmg.HitGroup).SetEqType(eqDmg.Eq).Exec(context.Background())
if err != nil {
log.Errorf("[DP] Unable to create WeaponStat: %v", err)
}
}
for _, eco := range ecoMap[tMatchPlayer.PlayerStats] {
err := p.db.RoundStats.Create().SetStat(nMatchPLayer).SetRound(uint(eco.Round)).SetBank(uint(eco.Bank)).SetEquipment(uint(eco.EqV)).SetSpent(uint(eco.Spent)).Exec(context.Background())
err := p.db.RoundStats.Create().SetMatchPlayer(nMatchPLayer).SetRound(uint(eco.Round)).SetBank(uint(eco.Bank)).SetEquipment(uint(eco.EqV)).SetSpent(uint(eco.Spent)).Exec(context.Background())
if err != nil {
log.Errorf("[DP] Unable to create RoundStat: %v", err)
}
}
for _, spray := range spays {
if spray.Sprayer == nMatchPLayer.PlayerStats {
if sprayAvg := spray.Avg(); len(sprayAvg) >= 5 {
sprayBuf := new(bytes.Buffer)
enc := gob.NewEncoder(sprayBuf)
err = enc.Encode(sprayAvg)
if err != nil {
log.Warningf("[DP] Failure to encode spray %v as bytes: %v", spray, err)
continue
}
err = p.db.Spray.Create().SetMatchPlayers(nMatchPLayer).SetWeapon(spray.Weapon).SetSpray(sprayBuf.Bytes()).Exec(context.Background())
if err != nil {
log.Warningf("[DP] Failure adding spray to database: %v", err)
}
}
}
}
}
log.Infof("[DP] parsed match %d (took %s/%s)", demo.MatchId, downloadTime, time.Since(startTime))

View File

@@ -10,10 +10,11 @@ import (
"csgowtfd/ent/migrate"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"csgowtfd/ent/spray"
"csgowtfd/ent/weapon"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
@@ -27,14 +28,16 @@ type Client struct {
Schema *migrate.Schema
// Match is the client for interacting with the Match builders.
Match *MatchClient
// MatchPlayer is the client for interacting with the MatchPlayer builders.
MatchPlayer *MatchPlayerClient
// Player is the client for interacting with the Player builders.
Player *PlayerClient
// RoundStats is the client for interacting with the RoundStats builders.
RoundStats *RoundStatsClient
// Stats is the client for interacting with the Stats builders.
Stats *StatsClient
// WeaponStats is the client for interacting with the WeaponStats builders.
WeaponStats *WeaponStatsClient
// Spray is the client for interacting with the Spray builders.
Spray *SprayClient
// Weapon is the client for interacting with the Weapon builders.
Weapon *WeaponClient
}
// NewClient creates a new client configured with the given options.
@@ -49,10 +52,11 @@ func NewClient(opts ...Option) *Client {
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.Match = NewMatchClient(c.config)
c.MatchPlayer = NewMatchPlayerClient(c.config)
c.Player = NewPlayerClient(c.config)
c.RoundStats = NewRoundStatsClient(c.config)
c.Stats = NewStatsClient(c.config)
c.WeaponStats = NewWeaponStatsClient(c.config)
c.Spray = NewSprayClient(c.config)
c.Weapon = NewWeaponClient(c.config)
}
// Open opens a database/sql.DB specified by the driver name and
@@ -87,10 +91,11 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
ctx: ctx,
config: cfg,
Match: NewMatchClient(cfg),
MatchPlayer: NewMatchPlayerClient(cfg),
Player: NewPlayerClient(cfg),
RoundStats: NewRoundStatsClient(cfg),
Stats: NewStatsClient(cfg),
WeaponStats: NewWeaponStatsClient(cfg),
Spray: NewSprayClient(cfg),
Weapon: NewWeaponClient(cfg),
}, nil
}
@@ -110,10 +115,11 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
return &Tx{
config: cfg,
Match: NewMatchClient(cfg),
MatchPlayer: NewMatchPlayerClient(cfg),
Player: NewPlayerClient(cfg),
RoundStats: NewRoundStatsClient(cfg),
Stats: NewStatsClient(cfg),
WeaponStats: NewWeaponStatsClient(cfg),
Spray: NewSprayClient(cfg),
Weapon: NewWeaponClient(cfg),
}, nil
}
@@ -144,10 +150,11 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
c.Match.Use(hooks...)
c.MatchPlayer.Use(hooks...)
c.Player.Use(hooks...)
c.RoundStats.Use(hooks...)
c.Stats.Use(hooks...)
c.WeaponStats.Use(hooks...)
c.Spray.Use(hooks...)
c.Weapon.Use(hooks...)
}
// MatchClient is a client for the Match schema.
@@ -236,13 +243,13 @@ func (c *MatchClient) GetX(ctx context.Context, id uint64) *Match {
}
// QueryStats queries the stats edge of a Match.
func (c *MatchClient) QueryStats(m *Match) *StatsQuery {
query := &StatsQuery{config: c.config}
func (c *MatchClient) QueryStats(m *Match) *MatchPlayerQuery {
query := &MatchPlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := m.ID
step := sqlgraph.NewStep(
sqlgraph.From(match.Table, match.FieldID, id),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, match.StatsTable, match.StatsColumn),
)
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
@@ -272,6 +279,176 @@ func (c *MatchClient) Hooks() []Hook {
return c.hooks.Match
}
// MatchPlayerClient is a client for the MatchPlayer schema.
type MatchPlayerClient struct {
config
}
// NewMatchPlayerClient returns a client for the MatchPlayer from the given config.
func NewMatchPlayerClient(c config) *MatchPlayerClient {
return &MatchPlayerClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `matchplayer.Hooks(f(g(h())))`.
func (c *MatchPlayerClient) Use(hooks ...Hook) {
c.hooks.MatchPlayer = append(c.hooks.MatchPlayer, hooks...)
}
// Create returns a create builder for MatchPlayer.
func (c *MatchPlayerClient) Create() *MatchPlayerCreate {
mutation := newMatchPlayerMutation(c.config, OpCreate)
return &MatchPlayerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of MatchPlayer entities.
func (c *MatchPlayerClient) CreateBulk(builders ...*MatchPlayerCreate) *MatchPlayerCreateBulk {
return &MatchPlayerCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for MatchPlayer.
func (c *MatchPlayerClient) Update() *MatchPlayerUpdate {
mutation := newMatchPlayerMutation(c.config, OpUpdate)
return &MatchPlayerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *MatchPlayerClient) UpdateOne(mp *MatchPlayer) *MatchPlayerUpdateOne {
mutation := newMatchPlayerMutation(c.config, OpUpdateOne, withMatchPlayer(mp))
return &MatchPlayerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *MatchPlayerClient) UpdateOneID(id int) *MatchPlayerUpdateOne {
mutation := newMatchPlayerMutation(c.config, OpUpdateOne, withMatchPlayerID(id))
return &MatchPlayerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for MatchPlayer.
func (c *MatchPlayerClient) Delete() *MatchPlayerDelete {
mutation := newMatchPlayerMutation(c.config, OpDelete)
return &MatchPlayerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a delete builder for the given entity.
func (c *MatchPlayerClient) DeleteOne(mp *MatchPlayer) *MatchPlayerDeleteOne {
return c.DeleteOneID(mp.ID)
}
// DeleteOneID returns a delete builder for the given id.
func (c *MatchPlayerClient) DeleteOneID(id int) *MatchPlayerDeleteOne {
builder := c.Delete().Where(matchplayer.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &MatchPlayerDeleteOne{builder}
}
// Query returns a query builder for MatchPlayer.
func (c *MatchPlayerClient) Query() *MatchPlayerQuery {
return &MatchPlayerQuery{
config: c.config,
}
}
// Get returns a MatchPlayer entity by its id.
func (c *MatchPlayerClient) Get(ctx context.Context, id int) (*MatchPlayer, error) {
return c.Query().Where(matchplayer.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *MatchPlayerClient) GetX(ctx context.Context, id int) *MatchPlayer {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryMatches queries the matches edge of a MatchPlayer.
func (c *MatchPlayerClient) QueryMatches(mp *MatchPlayer) *MatchQuery {
query := &MatchQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := mp.ID
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, id),
sqlgraph.To(match.Table, match.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, matchplayer.MatchesTable, matchplayer.MatchesColumn),
)
fromV = sqlgraph.Neighbors(mp.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryPlayers queries the players edge of a MatchPlayer.
func (c *MatchPlayerClient) QueryPlayers(mp *MatchPlayer) *PlayerQuery {
query := &PlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := mp.ID
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, id),
sqlgraph.To(player.Table, player.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, matchplayer.PlayersTable, matchplayer.PlayersColumn),
)
fromV = sqlgraph.Neighbors(mp.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryWeaponStats queries the weapon_stats edge of a MatchPlayer.
func (c *MatchPlayerClient) QueryWeaponStats(mp *MatchPlayer) *WeaponQuery {
query := &WeaponQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := mp.ID
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, id),
sqlgraph.To(weapon.Table, weapon.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.WeaponStatsTable, matchplayer.WeaponStatsColumn),
)
fromV = sqlgraph.Neighbors(mp.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryRoundStats queries the round_stats edge of a MatchPlayer.
func (c *MatchPlayerClient) QueryRoundStats(mp *MatchPlayer) *RoundStatsQuery {
query := &RoundStatsQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := mp.ID
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, id),
sqlgraph.To(roundstats.Table, roundstats.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.RoundStatsTable, matchplayer.RoundStatsColumn),
)
fromV = sqlgraph.Neighbors(mp.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QuerySpray queries the spray edge of a MatchPlayer.
func (c *MatchPlayerClient) QuerySpray(mp *MatchPlayer) *SprayQuery {
query := &SprayQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := mp.ID
step := sqlgraph.NewStep(
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, id),
sqlgraph.To(spray.Table, spray.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.SprayTable, matchplayer.SprayColumn),
)
fromV = sqlgraph.Neighbors(mp.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *MatchPlayerClient) Hooks() []Hook {
return c.hooks.MatchPlayer
}
// PlayerClient is a client for the Player schema.
type PlayerClient struct {
config
@@ -358,13 +535,13 @@ func (c *PlayerClient) GetX(ctx context.Context, id uint64) *Player {
}
// QueryStats queries the stats edge of a Player.
func (c *PlayerClient) QueryStats(pl *Player) *StatsQuery {
query := &StatsQuery{config: c.config}
func (c *PlayerClient) QueryStats(pl *Player) *MatchPlayerQuery {
query := &MatchPlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := pl.ID
step := sqlgraph.NewStep(
sqlgraph.From(player.Table, player.FieldID, id),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, player.StatsTable, player.StatsColumn),
)
fromV = sqlgraph.Neighbors(pl.driver.Dialect(), step)
@@ -479,15 +656,15 @@ func (c *RoundStatsClient) GetX(ctx context.Context, id int) *RoundStats {
return obj
}
// QueryStat queries the stat edge of a RoundStats.
func (c *RoundStatsClient) QueryStat(rs *RoundStats) *StatsQuery {
query := &StatsQuery{config: c.config}
// QueryMatchPlayer queries the match_player edge of a RoundStats.
func (c *RoundStatsClient) QueryMatchPlayer(rs *RoundStats) *MatchPlayerQuery {
query := &MatchPlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := rs.ID
step := sqlgraph.NewStep(
sqlgraph.From(roundstats.Table, roundstats.FieldID, id),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, roundstats.StatTable, roundstats.StatColumn),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, roundstats.MatchPlayerTable, roundstats.MatchPlayerColumn),
)
fromV = sqlgraph.Neighbors(rs.driver.Dialect(), step)
return fromV, nil
@@ -500,84 +677,84 @@ func (c *RoundStatsClient) Hooks() []Hook {
return c.hooks.RoundStats
}
// StatsClient is a client for the Stats schema.
type StatsClient struct {
// SprayClient is a client for the Spray schema.
type SprayClient struct {
config
}
// NewStatsClient returns a client for the Stats from the given config.
func NewStatsClient(c config) *StatsClient {
return &StatsClient{config: c}
// NewSprayClient returns a client for the Spray from the given config.
func NewSprayClient(c config) *SprayClient {
return &SprayClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `stats.Hooks(f(g(h())))`.
func (c *StatsClient) Use(hooks ...Hook) {
c.hooks.Stats = append(c.hooks.Stats, hooks...)
// A call to `Use(f, g, h)` equals to `spray.Hooks(f(g(h())))`.
func (c *SprayClient) Use(hooks ...Hook) {
c.hooks.Spray = append(c.hooks.Spray, hooks...)
}
// Create returns a create builder for Stats.
func (c *StatsClient) Create() *StatsCreate {
mutation := newStatsMutation(c.config, OpCreate)
return &StatsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Create returns a create builder for Spray.
func (c *SprayClient) Create() *SprayCreate {
mutation := newSprayMutation(c.config, OpCreate)
return &SprayCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Stats entities.
func (c *StatsClient) CreateBulk(builders ...*StatsCreate) *StatsCreateBulk {
return &StatsCreateBulk{config: c.config, builders: builders}
// CreateBulk returns a builder for creating a bulk of Spray entities.
func (c *SprayClient) CreateBulk(builders ...*SprayCreate) *SprayCreateBulk {
return &SprayCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Stats.
func (c *StatsClient) Update() *StatsUpdate {
mutation := newStatsMutation(c.config, OpUpdate)
return &StatsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Update returns an update builder for Spray.
func (c *SprayClient) Update() *SprayUpdate {
mutation := newSprayMutation(c.config, OpUpdate)
return &SprayUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *StatsClient) UpdateOne(s *Stats) *StatsUpdateOne {
mutation := newStatsMutation(c.config, OpUpdateOne, withStats(s))
return &StatsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
func (c *SprayClient) UpdateOne(s *Spray) *SprayUpdateOne {
mutation := newSprayMutation(c.config, OpUpdateOne, withSpray(s))
return &SprayUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *StatsClient) UpdateOneID(id int) *StatsUpdateOne {
mutation := newStatsMutation(c.config, OpUpdateOne, withStatsID(id))
return &StatsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
func (c *SprayClient) UpdateOneID(id int) *SprayUpdateOne {
mutation := newSprayMutation(c.config, OpUpdateOne, withSprayID(id))
return &SprayUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Stats.
func (c *StatsClient) Delete() *StatsDelete {
mutation := newStatsMutation(c.config, OpDelete)
return &StatsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Delete returns a delete builder for Spray.
func (c *SprayClient) Delete() *SprayDelete {
mutation := newSprayMutation(c.config, OpDelete)
return &SprayDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a delete builder for the given entity.
func (c *StatsClient) DeleteOne(s *Stats) *StatsDeleteOne {
func (c *SprayClient) DeleteOne(s *Spray) *SprayDeleteOne {
return c.DeleteOneID(s.ID)
}
// DeleteOneID returns a delete builder for the given id.
func (c *StatsClient) DeleteOneID(id int) *StatsDeleteOne {
builder := c.Delete().Where(stats.ID(id))
func (c *SprayClient) DeleteOneID(id int) *SprayDeleteOne {
builder := c.Delete().Where(spray.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &StatsDeleteOne{builder}
return &SprayDeleteOne{builder}
}
// Query returns a query builder for Stats.
func (c *StatsClient) Query() *StatsQuery {
return &StatsQuery{
// Query returns a query builder for Spray.
func (c *SprayClient) Query() *SprayQuery {
return &SprayQuery{
config: c.config,
}
}
// Get returns a Stats entity by its id.
func (c *StatsClient) Get(ctx context.Context, id int) (*Stats, error) {
return c.Query().Where(stats.ID(id)).Only(ctx)
// Get returns a Spray entity by its id.
func (c *SprayClient) Get(ctx context.Context, id int) (*Spray, error) {
return c.Query().Where(spray.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *StatsClient) GetX(ctx context.Context, id int) *Stats {
func (c *SprayClient) GetX(ctx context.Context, id int) *Spray {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
@@ -585,63 +762,15 @@ func (c *StatsClient) GetX(ctx context.Context, id int) *Stats {
return obj
}
// QueryMatches queries the matches edge of a Stats.
func (c *StatsClient) QueryMatches(s *Stats) *MatchQuery {
query := &MatchQuery{config: c.config}
// QueryMatchPlayers queries the match_players edge of a Spray.
func (c *SprayClient) QueryMatchPlayers(s *Spray) *MatchPlayerQuery {
query := &MatchPlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := s.ID
step := sqlgraph.NewStep(
sqlgraph.From(stats.Table, stats.FieldID, id),
sqlgraph.To(match.Table, match.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, stats.MatchesTable, stats.MatchesColumn),
)
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryPlayers queries the players edge of a Stats.
func (c *StatsClient) QueryPlayers(s *Stats) *PlayerQuery {
query := &PlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := s.ID
step := sqlgraph.NewStep(
sqlgraph.From(stats.Table, stats.FieldID, id),
sqlgraph.To(player.Table, player.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, stats.PlayersTable, stats.PlayersColumn),
)
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryWeaponStats queries the weapon_stats edge of a Stats.
func (c *StatsClient) QueryWeaponStats(s *Stats) *WeaponStatsQuery {
query := &WeaponStatsQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := s.ID
step := sqlgraph.NewStep(
sqlgraph.From(stats.Table, stats.FieldID, id),
sqlgraph.To(weaponstats.Table, weaponstats.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, stats.WeaponStatsTable, stats.WeaponStatsColumn),
)
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryRoundStats queries the round_stats edge of a Stats.
func (c *StatsClient) QueryRoundStats(s *Stats) *RoundStatsQuery {
query := &RoundStatsQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := s.ID
step := sqlgraph.NewStep(
sqlgraph.From(stats.Table, stats.FieldID, id),
sqlgraph.To(roundstats.Table, roundstats.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, stats.RoundStatsTable, stats.RoundStatsColumn),
sqlgraph.From(spray.Table, spray.FieldID, id),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, spray.MatchPlayersTable, spray.MatchPlayersColumn),
)
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
return fromV, nil
@@ -650,88 +779,88 @@ func (c *StatsClient) QueryRoundStats(s *Stats) *RoundStatsQuery {
}
// Hooks returns the client hooks.
func (c *StatsClient) Hooks() []Hook {
return c.hooks.Stats
func (c *SprayClient) Hooks() []Hook {
return c.hooks.Spray
}
// WeaponStatsClient is a client for the WeaponStats schema.
type WeaponStatsClient struct {
// WeaponClient is a client for the Weapon schema.
type WeaponClient struct {
config
}
// NewWeaponStatsClient returns a client for the WeaponStats from the given config.
func NewWeaponStatsClient(c config) *WeaponStatsClient {
return &WeaponStatsClient{config: c}
// NewWeaponClient returns a client for the Weapon from the given config.
func NewWeaponClient(c config) *WeaponClient {
return &WeaponClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `weaponstats.Hooks(f(g(h())))`.
func (c *WeaponStatsClient) Use(hooks ...Hook) {
c.hooks.WeaponStats = append(c.hooks.WeaponStats, hooks...)
// A call to `Use(f, g, h)` equals to `weapon.Hooks(f(g(h())))`.
func (c *WeaponClient) Use(hooks ...Hook) {
c.hooks.Weapon = append(c.hooks.Weapon, hooks...)
}
// Create returns a create builder for WeaponStats.
func (c *WeaponStatsClient) Create() *WeaponStatsCreate {
mutation := newWeaponStatsMutation(c.config, OpCreate)
return &WeaponStatsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Create returns a create builder for Weapon.
func (c *WeaponClient) Create() *WeaponCreate {
mutation := newWeaponMutation(c.config, OpCreate)
return &WeaponCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of WeaponStats entities.
func (c *WeaponStatsClient) CreateBulk(builders ...*WeaponStatsCreate) *WeaponStatsCreateBulk {
return &WeaponStatsCreateBulk{config: c.config, builders: builders}
// CreateBulk returns a builder for creating a bulk of Weapon entities.
func (c *WeaponClient) CreateBulk(builders ...*WeaponCreate) *WeaponCreateBulk {
return &WeaponCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for WeaponStats.
func (c *WeaponStatsClient) Update() *WeaponStatsUpdate {
mutation := newWeaponStatsMutation(c.config, OpUpdate)
return &WeaponStatsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Update returns an update builder for Weapon.
func (c *WeaponClient) Update() *WeaponUpdate {
mutation := newWeaponMutation(c.config, OpUpdate)
return &WeaponUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *WeaponStatsClient) UpdateOne(ws *WeaponStats) *WeaponStatsUpdateOne {
mutation := newWeaponStatsMutation(c.config, OpUpdateOne, withWeaponStats(ws))
return &WeaponStatsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
func (c *WeaponClient) UpdateOne(w *Weapon) *WeaponUpdateOne {
mutation := newWeaponMutation(c.config, OpUpdateOne, withWeapon(w))
return &WeaponUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *WeaponStatsClient) UpdateOneID(id int) *WeaponStatsUpdateOne {
mutation := newWeaponStatsMutation(c.config, OpUpdateOne, withWeaponStatsID(id))
return &WeaponStatsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
func (c *WeaponClient) UpdateOneID(id int) *WeaponUpdateOne {
mutation := newWeaponMutation(c.config, OpUpdateOne, withWeaponID(id))
return &WeaponUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for WeaponStats.
func (c *WeaponStatsClient) Delete() *WeaponStatsDelete {
mutation := newWeaponStatsMutation(c.config, OpDelete)
return &WeaponStatsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Delete returns a delete builder for Weapon.
func (c *WeaponClient) Delete() *WeaponDelete {
mutation := newWeaponMutation(c.config, OpDelete)
return &WeaponDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a delete builder for the given entity.
func (c *WeaponStatsClient) DeleteOne(ws *WeaponStats) *WeaponStatsDeleteOne {
return c.DeleteOneID(ws.ID)
func (c *WeaponClient) DeleteOne(w *Weapon) *WeaponDeleteOne {
return c.DeleteOneID(w.ID)
}
// DeleteOneID returns a delete builder for the given id.
func (c *WeaponStatsClient) DeleteOneID(id int) *WeaponStatsDeleteOne {
builder := c.Delete().Where(weaponstats.ID(id))
func (c *WeaponClient) DeleteOneID(id int) *WeaponDeleteOne {
builder := c.Delete().Where(weapon.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &WeaponStatsDeleteOne{builder}
return &WeaponDeleteOne{builder}
}
// Query returns a query builder for WeaponStats.
func (c *WeaponStatsClient) Query() *WeaponStatsQuery {
return &WeaponStatsQuery{
// Query returns a query builder for Weapon.
func (c *WeaponClient) Query() *WeaponQuery {
return &WeaponQuery{
config: c.config,
}
}
// Get returns a WeaponStats entity by its id.
func (c *WeaponStatsClient) Get(ctx context.Context, id int) (*WeaponStats, error) {
return c.Query().Where(weaponstats.ID(id)).Only(ctx)
// Get returns a Weapon entity by its id.
func (c *WeaponClient) Get(ctx context.Context, id int) (*Weapon, error) {
return c.Query().Where(weapon.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *WeaponStatsClient) GetX(ctx context.Context, id int) *WeaponStats {
func (c *WeaponClient) GetX(ctx context.Context, id int) *Weapon {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
@@ -739,23 +868,23 @@ func (c *WeaponStatsClient) GetX(ctx context.Context, id int) *WeaponStats {
return obj
}
// QueryStat queries the stat edge of a WeaponStats.
func (c *WeaponStatsClient) QueryStat(ws *WeaponStats) *StatsQuery {
query := &StatsQuery{config: c.config}
// QueryStat queries the stat edge of a Weapon.
func (c *WeaponClient) QueryStat(w *Weapon) *MatchPlayerQuery {
query := &MatchPlayerQuery{config: c.config}
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
id := ws.ID
id := w.ID
step := sqlgraph.NewStep(
sqlgraph.From(weaponstats.Table, weaponstats.FieldID, id),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, weaponstats.StatTable, weaponstats.StatColumn),
sqlgraph.From(weapon.Table, weapon.FieldID, id),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, weapon.StatTable, weapon.StatColumn),
)
fromV = sqlgraph.Neighbors(ws.driver.Dialect(), step)
fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *WeaponStatsClient) Hooks() []Hook {
return c.hooks.WeaponStats
func (c *WeaponClient) Hooks() []Hook {
return c.hooks.Weapon
}

View File

@@ -25,10 +25,11 @@ type config struct {
// hooks per client, for fast access.
type hooks struct {
Match []ent.Hook
MatchPlayer []ent.Hook
Player []ent.Hook
RoundStats []ent.Hook
Stats []ent.Hook
WeaponStats []ent.Hook
Spray []ent.Hook
Weapon []ent.Hook
}
// Options applies the options on the config object.

View File

@@ -4,10 +4,11 @@ package ent
import (
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"csgowtfd/ent/spray"
"csgowtfd/ent/weapon"
"errors"
"fmt"
@@ -34,10 +35,11 @@ type OrderFunc func(*sql.Selector)
func columnChecker(table string) func(string) error {
checks := map[string]func(string) bool{
match.Table: match.ValidColumn,
matchplayer.Table: matchplayer.ValidColumn,
player.Table: player.ValidColumn,
roundstats.Table: roundstats.ValidColumn,
stats.Table: stats.ValidColumn,
weaponstats.Table: weaponstats.ValidColumn,
spray.Table: spray.ValidColumn,
weapon.Table: weapon.ValidColumn,
}
check, ok := checks[table]
if !ok {

View File

@@ -21,6 +21,19 @@ func (f MatchFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
return f(ctx, mv)
}
// The MatchPlayerFunc type is an adapter to allow the use of ordinary
// function as MatchPlayer mutator.
type MatchPlayerFunc func(context.Context, *ent.MatchPlayerMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f MatchPlayerFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.MatchPlayerMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MatchPlayerMutation", m)
}
return f(ctx, mv)
}
// The PlayerFunc type is an adapter to allow the use of ordinary
// function as Player mutator.
type PlayerFunc func(context.Context, *ent.PlayerMutation) (ent.Value, error)
@@ -47,28 +60,28 @@ func (f RoundStatsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value,
return f(ctx, mv)
}
// The StatsFunc type is an adapter to allow the use of ordinary
// function as Stats mutator.
type StatsFunc func(context.Context, *ent.StatsMutation) (ent.Value, error)
// The SprayFunc type is an adapter to allow the use of ordinary
// function as Spray mutator.
type SprayFunc func(context.Context, *ent.SprayMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f StatsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.StatsMutation)
func (f SprayFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.SprayMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StatsMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SprayMutation", m)
}
return f(ctx, mv)
}
// The WeaponStatsFunc type is an adapter to allow the use of ordinary
// function as WeaponStats mutator.
type WeaponStatsFunc func(context.Context, *ent.WeaponStatsMutation) (ent.Value, error)
// The WeaponFunc type is an adapter to allow the use of ordinary
// function as Weapon mutator.
type WeaponFunc func(context.Context, *ent.WeaponMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f WeaponStatsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.WeaponStatsMutation)
func (f WeaponFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.WeaponMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WeaponStatsMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WeaponMutation", m)
}
return f(ctx, mv)
}

View File

@@ -48,7 +48,7 @@ type Match struct {
// MatchEdges holds the relations/edges for other nodes in the graph.
type MatchEdges struct {
// Stats holds the value of the stats edge.
Stats []*Stats `json:"stats,omitempty"`
Stats []*MatchPlayer `json:"stats,omitempty"`
// Players holds the value of the players edge.
Players []*Player `json:"players,omitempty"`
// loadedTypes holds the information for reporting if a
@@ -58,7 +58,7 @@ type MatchEdges struct {
// StatsOrErr returns the Stats value or an error if the edge
// was not loaded in eager-loading.
func (e MatchEdges) StatsOrErr() ([]*Stats, error) {
func (e MatchEdges) StatsOrErr() ([]*MatchPlayer, error) {
if e.loadedTypes[0] {
return e.Stats, nil
}
@@ -186,7 +186,7 @@ func (m *Match) assignValues(columns []string, values []interface{}) error {
}
// QueryStats queries the "stats" edge of the Match entity.
func (m *Match) QueryStats() *StatsQuery {
func (m *Match) QueryStats() *MatchPlayerQuery {
return (&MatchClient{config: m.config}).QueryStats(m)
}

View File

@@ -38,10 +38,10 @@ const (
// Table holds the table name of the match in the database.
Table = "matches"
// StatsTable is the table that holds the stats relation/edge.
StatsTable = "stats"
// StatsInverseTable is the table name for the Stats entity.
// It exists in this package in order to avoid circular dependency with the "stats" package.
StatsInverseTable = "stats"
StatsTable = "match_players"
// StatsInverseTable is the table name for the MatchPlayer entity.
// It exists in this package in order to avoid circular dependency with the "matchplayer" package.
StatsInverseTable = "match_players"
// StatsColumn is the table column denoting the stats relation/edge.
StatsColumn = "match_stats"
// PlayersTable is the table that holds the players relation/edge. The primary key declared below.

View File

@@ -1049,7 +1049,7 @@ func HasStats() predicate.Match {
}
// HasStatsWith applies the HasEdge predicate on the "stats" edge with a given conditions (other predicates).
func HasStatsWith(preds ...predicate.Stats) predicate.Match {
func HasStatsWith(preds ...predicate.MatchPlayer) predicate.Match {
return predicate.Match(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),

View File

@@ -5,8 +5,8 @@ package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"errors"
"fmt"
"time"
@@ -140,17 +140,17 @@ func (mc *MatchCreate) SetID(u uint64) *MatchCreate {
return mc
}
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
// AddStatIDs adds the "stats" edge to the MatchPlayer 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
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (mc *MatchCreate) AddStats(m ...*MatchPlayer) *MatchCreate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return mc.AddStatIDs(ids...)
}
@@ -426,7 +426,7 @@ func (mc *MatchCreate) createSpec() (*Match, *sqlgraph.CreateSpec) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}

View File

@@ -5,9 +5,9 @@ package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/predicate"
"csgowtfd/ent/stats"
"database/sql/driver"
"errors"
"fmt"
@@ -28,7 +28,7 @@ type MatchQuery struct {
fields []string
predicates []predicate.Match
// eager-loading edges.
withStats *StatsQuery
withStats *MatchPlayerQuery
withPlayers *PlayerQuery
modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
@@ -68,8 +68,8 @@ func (mq *MatchQuery) Order(o ...OrderFunc) *MatchQuery {
}
// QueryStats chains the current query on the "stats" edge.
func (mq *MatchQuery) QueryStats() *StatsQuery {
query := &StatsQuery{config: mq.config}
func (mq *MatchQuery) QueryStats() *MatchPlayerQuery {
query := &MatchPlayerQuery{config: mq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mq.prepareQuery(ctx); err != nil {
return nil, err
@@ -80,7 +80,7 @@ func (mq *MatchQuery) QueryStats() *StatsQuery {
}
step := sqlgraph.NewStep(
sqlgraph.From(match.Table, match.FieldID, selector),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, match.StatsTable, match.StatsColumn),
)
fromU = sqlgraph.SetNeighbors(mq.driver.Dialect(), step)
@@ -302,8 +302,8 @@ func (mq *MatchQuery) Clone() *MatchQuery {
// WithStats tells the query-builder to eager-load the nodes that are connected to
// the "stats" edge. The optional arguments are used to configure the query builder of the edge.
func (mq *MatchQuery) WithStats(opts ...func(*StatsQuery)) *MatchQuery {
query := &StatsQuery{config: mq.config}
func (mq *MatchQuery) WithStats(opts ...func(*MatchPlayerQuery)) *MatchQuery {
query := &MatchPlayerQuery{config: mq.config}
for _, opt := range opts {
opt(query)
}
@@ -421,9 +421,9 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.Stats = []*Stats{}
nodes[i].Edges.Stats = []*MatchPlayer{}
}
query.Where(predicate.Stats(func(s *sql.Selector) {
query.Where(predicate.MatchPlayer(func(s *sql.Selector) {
s.Where(sql.InValues(match.StatsColumn, fks...))
}))
neighbors, err := query.All(ctx)

View File

@@ -5,9 +5,9 @@ package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/predicate"
"csgowtfd/ent/stats"
"fmt"
"time"
@@ -188,17 +188,17 @@ func (mu *MatchUpdate) SetNillableGamebanPresent(b *bool) *MatchUpdate {
return mu
}
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
// AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs.
func (mu *MatchUpdate) AddStatIDs(ids ...int) *MatchUpdate {
mu.mutation.AddStatIDs(ids...)
return mu
}
// AddStats adds the "stats" edges to the Stats entity.
func (mu *MatchUpdate) AddStats(s ...*Stats) *MatchUpdate {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (mu *MatchUpdate) AddStats(m ...*MatchPlayer) *MatchUpdate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return mu.AddStatIDs(ids...)
}
@@ -223,23 +223,23 @@ func (mu *MatchUpdate) Mutation() *MatchMutation {
return mu.mutation
}
// ClearStats clears all "stats" edges to the Stats entity.
// ClearStats clears all "stats" edges to the MatchPlayer entity.
func (mu *MatchUpdate) ClearStats() *MatchUpdate {
mu.mutation.ClearStats()
return mu
}
// RemoveStatIDs removes the "stats" edge to Stats entities by IDs.
// RemoveStatIDs removes the "stats" edge to MatchPlayer entities by IDs.
func (mu *MatchUpdate) RemoveStatIDs(ids ...int) *MatchUpdate {
mu.mutation.RemoveStatIDs(ids...)
return mu
}
// RemoveStats removes "stats" edges to Stats entities.
func (mu *MatchUpdate) RemoveStats(s ...*Stats) *MatchUpdate {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// RemoveStats removes "stats" edges to MatchPlayer entities.
func (mu *MatchUpdate) RemoveStats(m ...*MatchPlayer) *MatchUpdate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return mu.RemoveStatIDs(ids...)
}
@@ -478,7 +478,7 @@ func (mu *MatchUpdate) sqlSave(ctx context.Context) (n int, err error) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -494,7 +494,7 @@ func (mu *MatchUpdate) sqlSave(ctx context.Context) (n int, err error) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -513,7 +513,7 @@ func (mu *MatchUpdate) sqlSave(ctx context.Context) (n int, err error) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -754,17 +754,17 @@ func (muo *MatchUpdateOne) SetNillableGamebanPresent(b *bool) *MatchUpdateOne {
return muo
}
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
// AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs.
func (muo *MatchUpdateOne) AddStatIDs(ids ...int) *MatchUpdateOne {
muo.mutation.AddStatIDs(ids...)
return muo
}
// AddStats adds the "stats" edges to the Stats entity.
func (muo *MatchUpdateOne) AddStats(s ...*Stats) *MatchUpdateOne {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (muo *MatchUpdateOne) AddStats(m ...*MatchPlayer) *MatchUpdateOne {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return muo.AddStatIDs(ids...)
}
@@ -789,23 +789,23 @@ func (muo *MatchUpdateOne) Mutation() *MatchMutation {
return muo.mutation
}
// ClearStats clears all "stats" edges to the Stats entity.
// ClearStats clears all "stats" edges to the MatchPlayer entity.
func (muo *MatchUpdateOne) ClearStats() *MatchUpdateOne {
muo.mutation.ClearStats()
return muo
}
// RemoveStatIDs removes the "stats" edge to Stats entities by IDs.
// RemoveStatIDs removes the "stats" edge to MatchPlayer entities by IDs.
func (muo *MatchUpdateOne) RemoveStatIDs(ids ...int) *MatchUpdateOne {
muo.mutation.RemoveStatIDs(ids...)
return muo
}
// RemoveStats removes "stats" edges to Stats entities.
func (muo *MatchUpdateOne) RemoveStats(s ...*Stats) *MatchUpdateOne {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// RemoveStats removes "stats" edges to MatchPlayer entities.
func (muo *MatchUpdateOne) RemoveStats(m ...*MatchPlayer) *MatchUpdateOne {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return muo.RemoveStatIDs(ids...)
}
@@ -1068,7 +1068,7 @@ func (muo *MatchUpdateOne) sqlSave(ctx context.Context) (_node *Match, err error
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -1084,7 +1084,7 @@ func (muo *MatchUpdateOne) sqlSave(ctx context.Context) (_node *Match, err error
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -1103,7 +1103,7 @@ func (muo *MatchUpdateOne) sqlSave(ctx context.Context) (_node *Match, err error
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}

View File

@@ -4,16 +4,16 @@ package ent
import (
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
)
// Stats is the model entity for the Stats schema.
type Stats struct {
// MatchPlayer is the model entity for the MatchPlayer schema.
type MatchPlayer struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
@@ -60,7 +60,7 @@ type Stats struct {
// Crosshair holds the value of the "crosshair" field.
Crosshair string `json:"crosshair,omitempty"`
// Color holds the value of the "color" field.
Color stats.Color `json:"color,omitempty"`
Color matchplayer.Color `json:"color,omitempty"`
// Kast holds the value of the "kast" field.
Kast int `json:"kast,omitempty"`
// FlashDurationSelf holds the value of the "flash_duration_self" field.
@@ -79,29 +79,33 @@ type Stats struct {
MatchStats uint64 `json:"match_stats,omitempty"`
// PlayerStats holds the value of the "player_stats" field.
PlayerStats uint64 `json:"player_stats,omitempty"`
// FlashAssists holds the value of the "flash_assists" field.
FlashAssists int `json:"flash_assists,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the StatsQuery when eager-loading is set.
Edges StatsEdges `json:"edges"`
// The values are being populated by the MatchPlayerQuery when eager-loading is set.
Edges MatchPlayerEdges `json:"edges"`
}
// StatsEdges holds the relations/edges for other nodes in the graph.
type StatsEdges struct {
// MatchPlayerEdges holds the relations/edges for other nodes in the graph.
type MatchPlayerEdges struct {
// Matches holds the value of the matches edge.
Matches *Match `json:"matches,omitempty"`
// Players holds the value of the players edge.
Players *Player `json:"players,omitempty"`
// WeaponStats holds the value of the weapon_stats edge.
WeaponStats []*WeaponStats `json:"weapon_stats,omitempty"`
WeaponStats []*Weapon `json:"weapon_stats,omitempty"`
// RoundStats holds the value of the round_stats edge.
RoundStats []*RoundStats `json:"round_stats,omitempty"`
// Spray holds the value of the spray edge.
Spray []*Spray `json:"spray,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [4]bool
loadedTypes [5]bool
}
// MatchesOrErr returns the Matches value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e StatsEdges) MatchesOrErr() (*Match, error) {
func (e MatchPlayerEdges) MatchesOrErr() (*Match, error) {
if e.loadedTypes[0] {
if e.Matches == nil {
// The edge matches was loaded in eager-loading,
@@ -115,7 +119,7 @@ func (e StatsEdges) MatchesOrErr() (*Match, error) {
// PlayersOrErr returns the Players value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e StatsEdges) PlayersOrErr() (*Player, error) {
func (e MatchPlayerEdges) PlayersOrErr() (*Player, error) {
if e.loadedTypes[1] {
if e.Players == nil {
// The edge players was loaded in eager-loading,
@@ -129,7 +133,7 @@ func (e StatsEdges) PlayersOrErr() (*Player, error) {
// WeaponStatsOrErr returns the WeaponStats value or an error if the edge
// was not loaded in eager-loading.
func (e StatsEdges) WeaponStatsOrErr() ([]*WeaponStats, error) {
func (e MatchPlayerEdges) WeaponStatsOrErr() ([]*Weapon, error) {
if e.loadedTypes[2] {
return e.WeaponStats, nil
}
@@ -138,350 +142,372 @@ func (e StatsEdges) WeaponStatsOrErr() ([]*WeaponStats, error) {
// RoundStatsOrErr returns the RoundStats value or an error if the edge
// was not loaded in eager-loading.
func (e StatsEdges) RoundStatsOrErr() ([]*RoundStats, error) {
func (e MatchPlayerEdges) RoundStatsOrErr() ([]*RoundStats, error) {
if e.loadedTypes[3] {
return e.RoundStats, nil
}
return nil, &NotLoadedError{edge: "round_stats"}
}
// SprayOrErr returns the Spray value or an error if the edge
// was not loaded in eager-loading.
func (e MatchPlayerEdges) SprayOrErr() ([]*Spray, error) {
if e.loadedTypes[4] {
return e.Spray, nil
}
return nil, &NotLoadedError{edge: "spray"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Stats) scanValues(columns []string) ([]interface{}, error) {
func (*MatchPlayer) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case stats.FieldFlashDurationSelf, stats.FieldFlashDurationTeam, stats.FieldFlashDurationEnemy:
case matchplayer.FieldFlashDurationSelf, matchplayer.FieldFlashDurationTeam, matchplayer.FieldFlashDurationEnemy:
values[i] = new(sql.NullFloat64)
case stats.FieldID, stats.FieldTeamID, stats.FieldKills, stats.FieldDeaths, stats.FieldAssists, stats.FieldHeadshot, stats.FieldMvp, stats.FieldScore, stats.FieldRankNew, stats.FieldRankOld, stats.FieldMk2, stats.FieldMk3, stats.FieldMk4, stats.FieldMk5, stats.FieldDmgEnemy, stats.FieldDmgTeam, stats.FieldUdHe, stats.FieldUdFlames, stats.FieldUdFlash, stats.FieldUdDecoy, stats.FieldUdSmoke, stats.FieldKast, stats.FieldFlashTotalSelf, stats.FieldFlashTotalTeam, stats.FieldFlashTotalEnemy, stats.FieldMatchStats, stats.FieldPlayerStats:
case matchplayer.FieldID, matchplayer.FieldTeamID, matchplayer.FieldKills, matchplayer.FieldDeaths, matchplayer.FieldAssists, matchplayer.FieldHeadshot, matchplayer.FieldMvp, matchplayer.FieldScore, matchplayer.FieldRankNew, matchplayer.FieldRankOld, matchplayer.FieldMk2, matchplayer.FieldMk3, matchplayer.FieldMk4, matchplayer.FieldMk5, matchplayer.FieldDmgEnemy, matchplayer.FieldDmgTeam, matchplayer.FieldUdHe, matchplayer.FieldUdFlames, matchplayer.FieldUdFlash, matchplayer.FieldUdDecoy, matchplayer.FieldUdSmoke, matchplayer.FieldKast, matchplayer.FieldFlashTotalSelf, matchplayer.FieldFlashTotalTeam, matchplayer.FieldFlashTotalEnemy, matchplayer.FieldMatchStats, matchplayer.FieldPlayerStats, matchplayer.FieldFlashAssists:
values[i] = new(sql.NullInt64)
case stats.FieldCrosshair, stats.FieldColor:
case matchplayer.FieldCrosshair, matchplayer.FieldColor:
values[i] = new(sql.NullString)
default:
return nil, fmt.Errorf("unexpected column %q for type Stats", columns[i])
return nil, fmt.Errorf("unexpected column %q for type MatchPlayer", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Stats fields.
func (s *Stats) assignValues(columns []string, values []interface{}) error {
// to the MatchPlayer fields.
func (mp *MatchPlayer) assignValues(columns []string, values []interface{}) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case stats.FieldID:
case matchplayer.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
s.ID = int(value.Int64)
case stats.FieldTeamID:
mp.ID = int(value.Int64)
case matchplayer.FieldTeamID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field team_id", values[i])
} else if value.Valid {
s.TeamID = int(value.Int64)
mp.TeamID = int(value.Int64)
}
case stats.FieldKills:
case matchplayer.FieldKills:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field kills", values[i])
} else if value.Valid {
s.Kills = int(value.Int64)
mp.Kills = int(value.Int64)
}
case stats.FieldDeaths:
case matchplayer.FieldDeaths:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field deaths", values[i])
} else if value.Valid {
s.Deaths = int(value.Int64)
mp.Deaths = int(value.Int64)
}
case stats.FieldAssists:
case matchplayer.FieldAssists:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field assists", values[i])
} else if value.Valid {
s.Assists = int(value.Int64)
mp.Assists = int(value.Int64)
}
case stats.FieldHeadshot:
case matchplayer.FieldHeadshot:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field headshot", values[i])
} else if value.Valid {
s.Headshot = int(value.Int64)
mp.Headshot = int(value.Int64)
}
case stats.FieldMvp:
case matchplayer.FieldMvp:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field mvp", values[i])
} else if value.Valid {
s.Mvp = uint(value.Int64)
mp.Mvp = uint(value.Int64)
}
case stats.FieldScore:
case matchplayer.FieldScore:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field score", values[i])
} else if value.Valid {
s.Score = int(value.Int64)
mp.Score = int(value.Int64)
}
case stats.FieldRankNew:
case matchplayer.FieldRankNew:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field rank_new", values[i])
} else if value.Valid {
s.RankNew = int(value.Int64)
mp.RankNew = int(value.Int64)
}
case stats.FieldRankOld:
case matchplayer.FieldRankOld:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field rank_old", values[i])
} else if value.Valid {
s.RankOld = int(value.Int64)
mp.RankOld = int(value.Int64)
}
case stats.FieldMk2:
case matchplayer.FieldMk2:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field mk_2", values[i])
} else if value.Valid {
s.Mk2 = uint(value.Int64)
mp.Mk2 = uint(value.Int64)
}
case stats.FieldMk3:
case matchplayer.FieldMk3:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field mk_3", values[i])
} else if value.Valid {
s.Mk3 = uint(value.Int64)
mp.Mk3 = uint(value.Int64)
}
case stats.FieldMk4:
case matchplayer.FieldMk4:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field mk_4", values[i])
} else if value.Valid {
s.Mk4 = uint(value.Int64)
mp.Mk4 = uint(value.Int64)
}
case stats.FieldMk5:
case matchplayer.FieldMk5:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field mk_5", values[i])
} else if value.Valid {
s.Mk5 = uint(value.Int64)
mp.Mk5 = uint(value.Int64)
}
case stats.FieldDmgEnemy:
case matchplayer.FieldDmgEnemy:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field dmg_enemy", values[i])
} else if value.Valid {
s.DmgEnemy = uint(value.Int64)
mp.DmgEnemy = uint(value.Int64)
}
case stats.FieldDmgTeam:
case matchplayer.FieldDmgTeam:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field dmg_team", values[i])
} else if value.Valid {
s.DmgTeam = uint(value.Int64)
mp.DmgTeam = uint(value.Int64)
}
case stats.FieldUdHe:
case matchplayer.FieldUdHe:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ud_he", values[i])
} else if value.Valid {
s.UdHe = uint(value.Int64)
mp.UdHe = uint(value.Int64)
}
case stats.FieldUdFlames:
case matchplayer.FieldUdFlames:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ud_flames", values[i])
} else if value.Valid {
s.UdFlames = uint(value.Int64)
mp.UdFlames = uint(value.Int64)
}
case stats.FieldUdFlash:
case matchplayer.FieldUdFlash:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ud_flash", values[i])
} else if value.Valid {
s.UdFlash = uint(value.Int64)
mp.UdFlash = uint(value.Int64)
}
case stats.FieldUdDecoy:
case matchplayer.FieldUdDecoy:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ud_decoy", values[i])
} else if value.Valid {
s.UdDecoy = uint(value.Int64)
mp.UdDecoy = uint(value.Int64)
}
case stats.FieldUdSmoke:
case matchplayer.FieldUdSmoke:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ud_smoke", values[i])
} else if value.Valid {
s.UdSmoke = uint(value.Int64)
mp.UdSmoke = uint(value.Int64)
}
case stats.FieldCrosshair:
case matchplayer.FieldCrosshair:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field crosshair", values[i])
} else if value.Valid {
s.Crosshair = value.String
mp.Crosshair = value.String
}
case stats.FieldColor:
case matchplayer.FieldColor:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field color", values[i])
} else if value.Valid {
s.Color = stats.Color(value.String)
mp.Color = matchplayer.Color(value.String)
}
case stats.FieldKast:
case matchplayer.FieldKast:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field kast", values[i])
} else if value.Valid {
s.Kast = int(value.Int64)
mp.Kast = int(value.Int64)
}
case stats.FieldFlashDurationSelf:
case matchplayer.FieldFlashDurationSelf:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field flash_duration_self", values[i])
} else if value.Valid {
s.FlashDurationSelf = float32(value.Float64)
mp.FlashDurationSelf = float32(value.Float64)
}
case stats.FieldFlashDurationTeam:
case matchplayer.FieldFlashDurationTeam:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field flash_duration_team", values[i])
} else if value.Valid {
s.FlashDurationTeam = float32(value.Float64)
mp.FlashDurationTeam = float32(value.Float64)
}
case stats.FieldFlashDurationEnemy:
case matchplayer.FieldFlashDurationEnemy:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field flash_duration_enemy", values[i])
} else if value.Valid {
s.FlashDurationEnemy = float32(value.Float64)
mp.FlashDurationEnemy = float32(value.Float64)
}
case stats.FieldFlashTotalSelf:
case matchplayer.FieldFlashTotalSelf:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field flash_total_self", values[i])
} else if value.Valid {
s.FlashTotalSelf = uint(value.Int64)
mp.FlashTotalSelf = uint(value.Int64)
}
case stats.FieldFlashTotalTeam:
case matchplayer.FieldFlashTotalTeam:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field flash_total_team", values[i])
} else if value.Valid {
s.FlashTotalTeam = uint(value.Int64)
mp.FlashTotalTeam = uint(value.Int64)
}
case stats.FieldFlashTotalEnemy:
case matchplayer.FieldFlashTotalEnemy:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field flash_total_enemy", values[i])
} else if value.Valid {
s.FlashTotalEnemy = uint(value.Int64)
mp.FlashTotalEnemy = uint(value.Int64)
}
case stats.FieldMatchStats:
case matchplayer.FieldMatchStats:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field match_stats", values[i])
} else if value.Valid {
s.MatchStats = uint64(value.Int64)
mp.MatchStats = uint64(value.Int64)
}
case stats.FieldPlayerStats:
case matchplayer.FieldPlayerStats:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field player_stats", values[i])
} else if value.Valid {
s.PlayerStats = uint64(value.Int64)
mp.PlayerStats = uint64(value.Int64)
}
case matchplayer.FieldFlashAssists:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field flash_assists", values[i])
} else if value.Valid {
mp.FlashAssists = int(value.Int64)
}
}
}
return nil
}
// QueryMatches queries the "matches" edge of the Stats entity.
func (s *Stats) QueryMatches() *MatchQuery {
return (&StatsClient{config: s.config}).QueryMatches(s)
// QueryMatches queries the "matches" edge of the MatchPlayer entity.
func (mp *MatchPlayer) QueryMatches() *MatchQuery {
return (&MatchPlayerClient{config: mp.config}).QueryMatches(mp)
}
// QueryPlayers queries the "players" edge of the Stats entity.
func (s *Stats) QueryPlayers() *PlayerQuery {
return (&StatsClient{config: s.config}).QueryPlayers(s)
// QueryPlayers queries the "players" edge of the MatchPlayer entity.
func (mp *MatchPlayer) QueryPlayers() *PlayerQuery {
return (&MatchPlayerClient{config: mp.config}).QueryPlayers(mp)
}
// QueryWeaponStats queries the "weapon_stats" edge of the Stats entity.
func (s *Stats) QueryWeaponStats() *WeaponStatsQuery {
return (&StatsClient{config: s.config}).QueryWeaponStats(s)
// QueryWeaponStats queries the "weapon_stats" edge of the MatchPlayer entity.
func (mp *MatchPlayer) QueryWeaponStats() *WeaponQuery {
return (&MatchPlayerClient{config: mp.config}).QueryWeaponStats(mp)
}
// QueryRoundStats queries the "round_stats" edge of the Stats entity.
func (s *Stats) QueryRoundStats() *RoundStatsQuery {
return (&StatsClient{config: s.config}).QueryRoundStats(s)
// QueryRoundStats queries the "round_stats" edge of the MatchPlayer entity.
func (mp *MatchPlayer) QueryRoundStats() *RoundStatsQuery {
return (&MatchPlayerClient{config: mp.config}).QueryRoundStats(mp)
}
// Update returns a builder for updating this Stats.
// Note that you need to call Stats.Unwrap() before calling this method if this Stats
// QuerySpray queries the "spray" edge of the MatchPlayer entity.
func (mp *MatchPlayer) QuerySpray() *SprayQuery {
return (&MatchPlayerClient{config: mp.config}).QuerySpray(mp)
}
// Update returns a builder for updating this MatchPlayer.
// Note that you need to call MatchPlayer.Unwrap() before calling this method if this MatchPlayer
// was returned from a transaction, and the transaction was committed or rolled back.
func (s *Stats) Update() *StatsUpdateOne {
return (&StatsClient{config: s.config}).UpdateOne(s)
func (mp *MatchPlayer) Update() *MatchPlayerUpdateOne {
return (&MatchPlayerClient{config: mp.config}).UpdateOne(mp)
}
// Unwrap unwraps the Stats entity that was returned from a transaction after it was closed,
// Unwrap unwraps the MatchPlayer entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (s *Stats) Unwrap() *Stats {
tx, ok := s.config.driver.(*txDriver)
func (mp *MatchPlayer) Unwrap() *MatchPlayer {
tx, ok := mp.config.driver.(*txDriver)
if !ok {
panic("ent: Stats is not a transactional entity")
panic("ent: MatchPlayer is not a transactional entity")
}
s.config.driver = tx.drv
return s
mp.config.driver = tx.drv
return mp
}
// String implements the fmt.Stringer.
func (s *Stats) String() string {
func (mp *MatchPlayer) String() string {
var builder strings.Builder
builder.WriteString("Stats(")
builder.WriteString(fmt.Sprintf("id=%v", s.ID))
builder.WriteString("MatchPlayer(")
builder.WriteString(fmt.Sprintf("id=%v", mp.ID))
builder.WriteString(", team_id=")
builder.WriteString(fmt.Sprintf("%v", s.TeamID))
builder.WriteString(fmt.Sprintf("%v", mp.TeamID))
builder.WriteString(", kills=")
builder.WriteString(fmt.Sprintf("%v", s.Kills))
builder.WriteString(fmt.Sprintf("%v", mp.Kills))
builder.WriteString(", deaths=")
builder.WriteString(fmt.Sprintf("%v", s.Deaths))
builder.WriteString(fmt.Sprintf("%v", mp.Deaths))
builder.WriteString(", assists=")
builder.WriteString(fmt.Sprintf("%v", s.Assists))
builder.WriteString(fmt.Sprintf("%v", mp.Assists))
builder.WriteString(", headshot=")
builder.WriteString(fmt.Sprintf("%v", s.Headshot))
builder.WriteString(fmt.Sprintf("%v", mp.Headshot))
builder.WriteString(", mvp=")
builder.WriteString(fmt.Sprintf("%v", s.Mvp))
builder.WriteString(fmt.Sprintf("%v", mp.Mvp))
builder.WriteString(", score=")
builder.WriteString(fmt.Sprintf("%v", s.Score))
builder.WriteString(fmt.Sprintf("%v", mp.Score))
builder.WriteString(", rank_new=")
builder.WriteString(fmt.Sprintf("%v", s.RankNew))
builder.WriteString(fmt.Sprintf("%v", mp.RankNew))
builder.WriteString(", rank_old=")
builder.WriteString(fmt.Sprintf("%v", s.RankOld))
builder.WriteString(fmt.Sprintf("%v", mp.RankOld))
builder.WriteString(", mk_2=")
builder.WriteString(fmt.Sprintf("%v", s.Mk2))
builder.WriteString(fmt.Sprintf("%v", mp.Mk2))
builder.WriteString(", mk_3=")
builder.WriteString(fmt.Sprintf("%v", s.Mk3))
builder.WriteString(fmt.Sprintf("%v", mp.Mk3))
builder.WriteString(", mk_4=")
builder.WriteString(fmt.Sprintf("%v", s.Mk4))
builder.WriteString(fmt.Sprintf("%v", mp.Mk4))
builder.WriteString(", mk_5=")
builder.WriteString(fmt.Sprintf("%v", s.Mk5))
builder.WriteString(fmt.Sprintf("%v", mp.Mk5))
builder.WriteString(", dmg_enemy=")
builder.WriteString(fmt.Sprintf("%v", s.DmgEnemy))
builder.WriteString(fmt.Sprintf("%v", mp.DmgEnemy))
builder.WriteString(", dmg_team=")
builder.WriteString(fmt.Sprintf("%v", s.DmgTeam))
builder.WriteString(fmt.Sprintf("%v", mp.DmgTeam))
builder.WriteString(", ud_he=")
builder.WriteString(fmt.Sprintf("%v", s.UdHe))
builder.WriteString(fmt.Sprintf("%v", mp.UdHe))
builder.WriteString(", ud_flames=")
builder.WriteString(fmt.Sprintf("%v", s.UdFlames))
builder.WriteString(fmt.Sprintf("%v", mp.UdFlames))
builder.WriteString(", ud_flash=")
builder.WriteString(fmt.Sprintf("%v", s.UdFlash))
builder.WriteString(fmt.Sprintf("%v", mp.UdFlash))
builder.WriteString(", ud_decoy=")
builder.WriteString(fmt.Sprintf("%v", s.UdDecoy))
builder.WriteString(fmt.Sprintf("%v", mp.UdDecoy))
builder.WriteString(", ud_smoke=")
builder.WriteString(fmt.Sprintf("%v", s.UdSmoke))
builder.WriteString(fmt.Sprintf("%v", mp.UdSmoke))
builder.WriteString(", crosshair=")
builder.WriteString(s.Crosshair)
builder.WriteString(mp.Crosshair)
builder.WriteString(", color=")
builder.WriteString(fmt.Sprintf("%v", s.Color))
builder.WriteString(fmt.Sprintf("%v", mp.Color))
builder.WriteString(", kast=")
builder.WriteString(fmt.Sprintf("%v", s.Kast))
builder.WriteString(fmt.Sprintf("%v", mp.Kast))
builder.WriteString(", flash_duration_self=")
builder.WriteString(fmt.Sprintf("%v", s.FlashDurationSelf))
builder.WriteString(fmt.Sprintf("%v", mp.FlashDurationSelf))
builder.WriteString(", flash_duration_team=")
builder.WriteString(fmt.Sprintf("%v", s.FlashDurationTeam))
builder.WriteString(fmt.Sprintf("%v", mp.FlashDurationTeam))
builder.WriteString(", flash_duration_enemy=")
builder.WriteString(fmt.Sprintf("%v", s.FlashDurationEnemy))
builder.WriteString(fmt.Sprintf("%v", mp.FlashDurationEnemy))
builder.WriteString(", flash_total_self=")
builder.WriteString(fmt.Sprintf("%v", s.FlashTotalSelf))
builder.WriteString(fmt.Sprintf("%v", mp.FlashTotalSelf))
builder.WriteString(", flash_total_team=")
builder.WriteString(fmt.Sprintf("%v", s.FlashTotalTeam))
builder.WriteString(fmt.Sprintf("%v", mp.FlashTotalTeam))
builder.WriteString(", flash_total_enemy=")
builder.WriteString(fmt.Sprintf("%v", s.FlashTotalEnemy))
builder.WriteString(fmt.Sprintf("%v", mp.FlashTotalEnemy))
builder.WriteString(", match_stats=")
builder.WriteString(fmt.Sprintf("%v", s.MatchStats))
builder.WriteString(fmt.Sprintf("%v", mp.MatchStats))
builder.WriteString(", player_stats=")
builder.WriteString(fmt.Sprintf("%v", s.PlayerStats))
builder.WriteString(fmt.Sprintf("%v", mp.PlayerStats))
builder.WriteString(", flash_assists=")
builder.WriteString(fmt.Sprintf("%v", mp.FlashAssists))
builder.WriteByte(')')
return builder.String()
}
// StatsSlice is a parsable slice of Stats.
type StatsSlice []*Stats
// MatchPlayers is a parsable slice of MatchPlayer.
type MatchPlayers []*MatchPlayer
func (s StatsSlice) config(cfg config) {
for _i := range s {
s[_i].config = cfg
func (mp MatchPlayers) config(cfg config) {
for _i := range mp {
mp[_i].config = cfg
}
}

View File

@@ -1,14 +1,14 @@
// Code generated by entc, DO NOT EDIT.
package stats
package matchplayer
import (
"fmt"
)
const (
// Label holds the string label denoting the stats type in the database.
Label = "stats"
// Label holds the string label denoting the matchplayer type in the database.
Label = "match_player"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldTeamID holds the string denoting the team_id field in the database.
@@ -73,6 +73,8 @@ const (
FieldMatchStats = "match_stats"
// FieldPlayerStats holds the string denoting the player_stats field in the database.
FieldPlayerStats = "player_stats"
// FieldFlashAssists holds the string denoting the flash_assists field in the database.
FieldFlashAssists = "flash_assists"
// EdgeMatches holds the string denoting the matches edge name in mutations.
EdgeMatches = "matches"
// EdgePlayers holds the string denoting the players edge name in mutations.
@@ -81,39 +83,48 @@ const (
EdgeWeaponStats = "weapon_stats"
// EdgeRoundStats holds the string denoting the round_stats edge name in mutations.
EdgeRoundStats = "round_stats"
// Table holds the table name of the stats in the database.
Table = "stats"
// EdgeSpray holds the string denoting the spray edge name in mutations.
EdgeSpray = "spray"
// Table holds the table name of the matchplayer in the database.
Table = "match_players"
// MatchesTable is the table that holds the matches relation/edge.
MatchesTable = "stats"
MatchesTable = "match_players"
// MatchesInverseTable is the table name for the Match entity.
// It exists in this package in order to avoid circular dependency with the "match" package.
MatchesInverseTable = "matches"
// MatchesColumn is the table column denoting the matches relation/edge.
MatchesColumn = "match_stats"
// PlayersTable is the table that holds the players relation/edge.
PlayersTable = "stats"
PlayersTable = "match_players"
// PlayersInverseTable is the table name for the Player entity.
// It exists in this package in order to avoid circular dependency with the "player" package.
PlayersInverseTable = "players"
// PlayersColumn is the table column denoting the players relation/edge.
PlayersColumn = "player_stats"
// WeaponStatsTable is the table that holds the weapon_stats relation/edge.
WeaponStatsTable = "weapon_stats"
// WeaponStatsInverseTable is the table name for the WeaponStats entity.
// It exists in this package in order to avoid circular dependency with the "weaponstats" package.
WeaponStatsInverseTable = "weapon_stats"
WeaponStatsTable = "weapons"
// WeaponStatsInverseTable is the table name for the Weapon entity.
// It exists in this package in order to avoid circular dependency with the "weapon" package.
WeaponStatsInverseTable = "weapons"
// WeaponStatsColumn is the table column denoting the weapon_stats relation/edge.
WeaponStatsColumn = "stats_weapon_stats"
WeaponStatsColumn = "match_player_weapon_stats"
// RoundStatsTable is the table that holds the round_stats relation/edge.
RoundStatsTable = "round_stats"
// RoundStatsInverseTable is the table name for the RoundStats entity.
// It exists in this package in order to avoid circular dependency with the "roundstats" package.
RoundStatsInverseTable = "round_stats"
// RoundStatsColumn is the table column denoting the round_stats relation/edge.
RoundStatsColumn = "stats_round_stats"
RoundStatsColumn = "match_player_round_stats"
// SprayTable is the table that holds the spray relation/edge.
SprayTable = "sprays"
// SprayInverseTable is the table name for the Spray entity.
// It exists in this package in order to avoid circular dependency with the "spray" package.
SprayInverseTable = "sprays"
// SprayColumn is the table column denoting the spray relation/edge.
SprayColumn = "match_player_spray"
)
// Columns holds all SQL columns for stats fields.
// Columns holds all SQL columns for matchplayer fields.
var Columns = []string{
FieldID,
FieldTeamID,
@@ -147,6 +158,7 @@ var Columns = []string{
FieldFlashTotalEnemy,
FieldMatchStats,
FieldPlayerStats,
FieldFlashAssists,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -182,6 +194,6 @@ func ColorValidator(c Color) error {
case ColorGreen, ColorYellow, ColorPurple, ColorBlue, ColorOrange, ColorGrey:
return nil
default:
return fmt.Errorf("stats: invalid enum value for color field: %q", c)
return fmt.Errorf("matchplayer: invalid enum value for color field: %q", c)
}
}

File diff suppressed because it is too large Load Diff

1046
ent/matchplayer_create.go Normal file

File diff suppressed because it is too large Load Diff

111
ent/matchplayer_delete.go Normal file
View File

@@ -0,0 +1,111 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/predicate"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MatchPlayerDelete is the builder for deleting a MatchPlayer entity.
type MatchPlayerDelete struct {
config
hooks []Hook
mutation *MatchPlayerMutation
}
// Where appends a list predicates to the MatchPlayerDelete builder.
func (mpd *MatchPlayerDelete) Where(ps ...predicate.MatchPlayer) *MatchPlayerDelete {
mpd.mutation.Where(ps...)
return mpd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (mpd *MatchPlayerDelete) Exec(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(mpd.hooks) == 0 {
affected, err = mpd.sqlExec(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*MatchPlayerMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
mpd.mutation = mutation
affected, err = mpd.sqlExec(ctx)
mutation.done = true
return affected, err
})
for i := len(mpd.hooks) - 1; i >= 0; i-- {
if mpd.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = mpd.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, mpd.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// ExecX is like Exec, but panics if an error occurs.
func (mpd *MatchPlayerDelete) ExecX(ctx context.Context) int {
n, err := mpd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (mpd *MatchPlayerDelete) sqlExec(ctx context.Context) (int, error) {
_spec := &sqlgraph.DeleteSpec{
Node: &sqlgraph.NodeSpec{
Table: matchplayer.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: matchplayer.FieldID,
},
},
}
if ps := mpd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return sqlgraph.DeleteNodes(ctx, mpd.driver, _spec)
}
// MatchPlayerDeleteOne is the builder for deleting a single MatchPlayer entity.
type MatchPlayerDeleteOne struct {
mpd *MatchPlayerDelete
}
// Exec executes the deletion query.
func (mpdo *MatchPlayerDeleteOne) Exec(ctx context.Context) error {
n, err := mpdo.mpd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{matchplayer.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (mpdo *MatchPlayerDeleteOne) ExecX(ctx context.Context) {
mpdo.mpd.ExecX(ctx)
}

1267
ent/matchplayer_query.go Normal file

File diff suppressed because it is too large Load Diff

3619
ent/matchplayer_update.go Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -30,54 +30,8 @@ var (
Columns: MatchesColumns,
PrimaryKey: []*schema.Column{MatchesColumns[0]},
}
// PlayersColumns holds the columns for the "players" table.
PlayersColumns = []*schema.Column{
{Name: "id", Type: field.TypeUint64, Increment: true},
{Name: "name", Type: field.TypeString, Nullable: true},
{Name: "avatar", Type: field.TypeString, Nullable: true},
{Name: "vanity_url", Type: field.TypeString, Nullable: true},
{Name: "vanity_url_real", Type: field.TypeString, Nullable: true},
{Name: "vac_date", Type: field.TypeTime, Nullable: true},
{Name: "vac_count", Type: field.TypeInt, Nullable: true},
{Name: "game_ban_date", Type: field.TypeTime, Nullable: true},
{Name: "game_ban_count", Type: field.TypeInt, Nullable: true},
{Name: "steam_updated", Type: field.TypeTime},
{Name: "sharecode_updated", Type: field.TypeTime, Nullable: true},
{Name: "auth_code", Type: field.TypeString, Nullable: true},
{Name: "profile_created", Type: field.TypeTime, Nullable: true},
{Name: "oldest_sharecode_seen", Type: field.TypeString, Nullable: true},
}
// PlayersTable holds the schema information for the "players" table.
PlayersTable = &schema.Table{
Name: "players",
Columns: PlayersColumns,
PrimaryKey: []*schema.Column{PlayersColumns[0]},
}
// RoundStatsColumns holds the columns for the "round_stats" table.
RoundStatsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "round", Type: field.TypeUint},
{Name: "bank", Type: field.TypeUint},
{Name: "equipment", Type: field.TypeUint},
{Name: "spent", Type: field.TypeUint},
{Name: "stats_round_stats", Type: field.TypeInt, Nullable: true},
}
// RoundStatsTable holds the schema information for the "round_stats" table.
RoundStatsTable = &schema.Table{
Name: "round_stats",
Columns: RoundStatsColumns,
PrimaryKey: []*schema.Column{RoundStatsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "round_stats_stats_round_stats",
Columns: []*schema.Column{RoundStatsColumns[5]},
RefColumns: []*schema.Column{StatsColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// StatsColumns holds the columns for the "stats" table.
StatsColumns = []*schema.Column{
// MatchPlayersColumns holds the columns for the "match_players" table.
MatchPlayersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "team_id", Type: field.TypeInt},
{Name: "kills", Type: field.TypeInt},
@@ -108,48 +62,119 @@ var (
{Name: "flash_total_self", Type: field.TypeUint, Nullable: true},
{Name: "flash_total_team", Type: field.TypeUint, Nullable: true},
{Name: "flash_total_enemy", Type: field.TypeUint, Nullable: true},
{Name: "flash_assists", Type: field.TypeInt, Nullable: true},
{Name: "match_stats", Type: field.TypeUint64, Nullable: true},
{Name: "player_stats", Type: field.TypeUint64, Nullable: true},
}
// StatsTable holds the schema information for the "stats" table.
StatsTable = &schema.Table{
Name: "stats",
Columns: StatsColumns,
PrimaryKey: []*schema.Column{StatsColumns[0]},
// MatchPlayersTable holds the schema information for the "match_players" table.
MatchPlayersTable = &schema.Table{
Name: "match_players",
Columns: MatchPlayersColumns,
PrimaryKey: []*schema.Column{MatchPlayersColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "stats_matches_stats",
Columns: []*schema.Column{StatsColumns[30]},
Symbol: "match_players_matches_stats",
Columns: []*schema.Column{MatchPlayersColumns[31]},
RefColumns: []*schema.Column{MatchesColumns[0]},
OnDelete: schema.SetNull,
},
{
Symbol: "stats_players_stats",
Columns: []*schema.Column{StatsColumns[31]},
Symbol: "match_players_players_stats",
Columns: []*schema.Column{MatchPlayersColumns[32]},
RefColumns: []*schema.Column{PlayersColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// WeaponStatsColumns holds the columns for the "weapon_stats" table.
WeaponStatsColumns = []*schema.Column{
// PlayersColumns holds the columns for the "players" table.
PlayersColumns = []*schema.Column{
{Name: "id", Type: field.TypeUint64, Increment: true},
{Name: "name", Type: field.TypeString, Nullable: true},
{Name: "avatar", Type: field.TypeString, Nullable: true},
{Name: "vanity_url", Type: field.TypeString, Nullable: true},
{Name: "vanity_url_real", Type: field.TypeString, Nullable: true},
{Name: "vac_date", Type: field.TypeTime, Nullable: true},
{Name: "vac_count", Type: field.TypeInt, Nullable: true},
{Name: "game_ban_date", Type: field.TypeTime, Nullable: true},
{Name: "game_ban_count", Type: field.TypeInt, Nullable: true},
{Name: "steam_updated", Type: field.TypeTime},
{Name: "sharecode_updated", Type: field.TypeTime, Nullable: true},
{Name: "auth_code", Type: field.TypeString, Nullable: true},
{Name: "profile_created", Type: field.TypeTime, Nullable: true},
{Name: "oldest_sharecode_seen", Type: field.TypeString, Nullable: true},
{Name: "wins", Type: field.TypeInt, Nullable: true},
{Name: "looses", Type: field.TypeInt, Nullable: true},
{Name: "ties", Type: field.TypeInt, Nullable: true},
}
// PlayersTable holds the schema information for the "players" table.
PlayersTable = &schema.Table{
Name: "players",
Columns: PlayersColumns,
PrimaryKey: []*schema.Column{PlayersColumns[0]},
}
// RoundStatsColumns holds the columns for the "round_stats" table.
RoundStatsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "round", Type: field.TypeUint},
{Name: "bank", Type: field.TypeUint},
{Name: "equipment", Type: field.TypeUint},
{Name: "spent", Type: field.TypeUint},
{Name: "match_player_round_stats", Type: field.TypeInt, Nullable: true},
}
// RoundStatsTable holds the schema information for the "round_stats" table.
RoundStatsTable = &schema.Table{
Name: "round_stats",
Columns: RoundStatsColumns,
PrimaryKey: []*schema.Column{RoundStatsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "round_stats_match_players_round_stats",
Columns: []*schema.Column{RoundStatsColumns[5]},
RefColumns: []*schema.Column{MatchPlayersColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// SpraysColumns holds the columns for the "sprays" table.
SpraysColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "weapon", Type: field.TypeInt},
{Name: "spray", Type: field.TypeBytes},
{Name: "match_player_spray", Type: field.TypeInt, Nullable: true},
}
// SpraysTable holds the schema information for the "sprays" table.
SpraysTable = &schema.Table{
Name: "sprays",
Columns: SpraysColumns,
PrimaryKey: []*schema.Column{SpraysColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "sprays_match_players_spray",
Columns: []*schema.Column{SpraysColumns[3]},
RefColumns: []*schema.Column{MatchPlayersColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// WeaponsColumns holds the columns for the "weapons" table.
WeaponsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "victim", Type: field.TypeUint64},
{Name: "dmg", Type: field.TypeUint},
{Name: "eq_type", Type: field.TypeInt},
{Name: "hit_group", Type: field.TypeInt},
{Name: "stats_weapon_stats", Type: field.TypeInt, Nullable: true},
{Name: "match_player_weapon_stats", Type: field.TypeInt, Nullable: true},
}
// WeaponStatsTable holds the schema information for the "weapon_stats" table.
WeaponStatsTable = &schema.Table{
Name: "weapon_stats",
Columns: WeaponStatsColumns,
PrimaryKey: []*schema.Column{WeaponStatsColumns[0]},
// WeaponsTable holds the schema information for the "weapons" table.
WeaponsTable = &schema.Table{
Name: "weapons",
Columns: WeaponsColumns,
PrimaryKey: []*schema.Column{WeaponsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "weapon_stats_stats_weapon_stats",
Columns: []*schema.Column{WeaponStatsColumns[5]},
RefColumns: []*schema.Column{StatsColumns[0]},
Symbol: "weapons_match_players_weapon_stats",
Columns: []*schema.Column{WeaponsColumns[5]},
RefColumns: []*schema.Column{MatchPlayersColumns[0]},
OnDelete: schema.SetNull,
},
},
@@ -182,19 +207,21 @@ var (
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
MatchesTable,
MatchPlayersTable,
PlayersTable,
RoundStatsTable,
StatsTable,
WeaponStatsTable,
SpraysTable,
WeaponsTable,
PlayerMatchesTable,
}
)
func init() {
RoundStatsTable.ForeignKeys[0].RefTable = StatsTable
StatsTable.ForeignKeys[0].RefTable = MatchesTable
StatsTable.ForeignKeys[1].RefTable = PlayersTable
WeaponStatsTable.ForeignKeys[0].RefTable = StatsTable
MatchPlayersTable.ForeignKeys[0].RefTable = MatchesTable
MatchPlayersTable.ForeignKeys[1].RefTable = PlayersTable
RoundStatsTable.ForeignKeys[0].RefTable = MatchPlayersTable
SpraysTable.ForeignKeys[0].RefTable = MatchPlayersTable
WeaponsTable.ForeignKeys[0].RefTable = MatchPlayersTable
PlayerMatchesTable.ForeignKeys[0].RefTable = PlayersTable
PlayerMatchesTable.ForeignKeys[1].RefTable = MatchesTable
}

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,12 @@ type Player struct {
ProfileCreated time.Time `json:"profile_created,omitempty"`
// OldestSharecodeSeen holds the value of the "oldest_sharecode_seen" field.
OldestSharecodeSeen string `json:"oldest_sharecode_seen,omitempty"`
// Wins holds the value of the "wins" field.
Wins int `json:"wins,omitempty"`
// Looses holds the value of the "looses" field.
Looses int `json:"looses,omitempty"`
// Ties holds the value of the "ties" field.
Ties int `json:"ties,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PlayerQuery when eager-loading is set.
Edges PlayerEdges `json:"edges"`
@@ -50,7 +56,7 @@ type Player struct {
// PlayerEdges holds the relations/edges for other nodes in the graph.
type PlayerEdges struct {
// Stats holds the value of the stats edge.
Stats []*Stats `json:"stats,omitempty"`
Stats []*MatchPlayer `json:"stats,omitempty"`
// Matches holds the value of the matches edge.
Matches []*Match `json:"matches,omitempty"`
// loadedTypes holds the information for reporting if a
@@ -60,7 +66,7 @@ type PlayerEdges struct {
// StatsOrErr returns the Stats value or an error if the edge
// was not loaded in eager-loading.
func (e PlayerEdges) StatsOrErr() ([]*Stats, error) {
func (e PlayerEdges) StatsOrErr() ([]*MatchPlayer, error) {
if e.loadedTypes[0] {
return e.Stats, nil
}
@@ -81,7 +87,7 @@ func (*Player) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case player.FieldID, player.FieldVacCount, player.FieldGameBanCount:
case player.FieldID, player.FieldVacCount, player.FieldGameBanCount, player.FieldWins, player.FieldLooses, player.FieldTies:
values[i] = new(sql.NullInt64)
case player.FieldName, player.FieldAvatar, player.FieldVanityURL, player.FieldVanityURLReal, player.FieldAuthCode, player.FieldOldestSharecodeSeen:
values[i] = new(sql.NullString)
@@ -186,13 +192,31 @@ func (pl *Player) assignValues(columns []string, values []interface{}) error {
} else if value.Valid {
pl.OldestSharecodeSeen = value.String
}
case player.FieldWins:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field wins", values[i])
} else if value.Valid {
pl.Wins = int(value.Int64)
}
case player.FieldLooses:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field looses", values[i])
} else if value.Valid {
pl.Looses = int(value.Int64)
}
case player.FieldTies:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ties", values[i])
} else if value.Valid {
pl.Ties = int(value.Int64)
}
}
}
return nil
}
// QueryStats queries the "stats" edge of the Player entity.
func (pl *Player) QueryStats() *StatsQuery {
func (pl *Player) QueryStats() *MatchPlayerQuery {
return (&PlayerClient{config: pl.config}).QueryStats(pl)
}
@@ -249,6 +273,12 @@ func (pl *Player) String() string {
builder.WriteString(pl.ProfileCreated.Format(time.ANSIC))
builder.WriteString(", oldest_sharecode_seen=")
builder.WriteString(pl.OldestSharecodeSeen)
builder.WriteString(", wins=")
builder.WriteString(fmt.Sprintf("%v", pl.Wins))
builder.WriteString(", looses=")
builder.WriteString(fmt.Sprintf("%v", pl.Looses))
builder.WriteString(", ties=")
builder.WriteString(fmt.Sprintf("%v", pl.Ties))
builder.WriteByte(')')
return builder.String()
}

View File

@@ -37,6 +37,12 @@ const (
FieldProfileCreated = "profile_created"
// FieldOldestSharecodeSeen holds the string denoting the oldest_sharecode_seen field in the database.
FieldOldestSharecodeSeen = "oldest_sharecode_seen"
// FieldWins holds the string denoting the wins field in the database.
FieldWins = "wins"
// FieldLooses holds the string denoting the looses field in the database.
FieldLooses = "looses"
// FieldTies holds the string denoting the ties field in the database.
FieldTies = "ties"
// EdgeStats holds the string denoting the stats edge name in mutations.
EdgeStats = "stats"
// EdgeMatches holds the string denoting the matches edge name in mutations.
@@ -44,10 +50,10 @@ const (
// Table holds the table name of the player in the database.
Table = "players"
// StatsTable is the table that holds the stats relation/edge.
StatsTable = "stats"
// StatsInverseTable is the table name for the Stats entity.
// It exists in this package in order to avoid circular dependency with the "stats" package.
StatsInverseTable = "stats"
StatsTable = "match_players"
// StatsInverseTable is the table name for the MatchPlayer entity.
// It exists in this package in order to avoid circular dependency with the "matchplayer" package.
StatsInverseTable = "match_players"
// StatsColumn is the table column denoting the stats relation/edge.
StatsColumn = "player_stats"
// MatchesTable is the table that holds the matches relation/edge. The primary key declared below.
@@ -73,6 +79,9 @@ var Columns = []string{
FieldAuthCode,
FieldProfileCreated,
FieldOldestSharecodeSeen,
FieldWins,
FieldLooses,
FieldTies,
}
var (

View File

@@ -184,6 +184,27 @@ func OldestSharecodeSeen(v string) predicate.Player {
})
}
// Wins applies equality check predicate on the "wins" field. It's identical to WinsEQ.
func Wins(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldWins), v))
})
}
// Looses applies equality check predicate on the "looses" field. It's identical to LoosesEQ.
func Looses(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldLooses), v))
})
}
// Ties applies equality check predicate on the "ties" field. It's identical to TiesEQ.
func Ties(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldTies), v))
})
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
@@ -1550,6 +1571,276 @@ func OldestSharecodeSeenContainsFold(v string) predicate.Player {
})
}
// WinsEQ applies the EQ predicate on the "wins" field.
func WinsEQ(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldWins), v))
})
}
// WinsNEQ applies the NEQ predicate on the "wins" field.
func WinsNEQ(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldWins), v))
})
}
// WinsIn applies the In predicate on the "wins" field.
func WinsIn(vs ...int) predicate.Player {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Player(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldWins), v...))
})
}
// WinsNotIn applies the NotIn predicate on the "wins" field.
func WinsNotIn(vs ...int) predicate.Player {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Player(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldWins), v...))
})
}
// WinsGT applies the GT predicate on the "wins" field.
func WinsGT(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldWins), v))
})
}
// WinsGTE applies the GTE predicate on the "wins" field.
func WinsGTE(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldWins), v))
})
}
// WinsLT applies the LT predicate on the "wins" field.
func WinsLT(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldWins), v))
})
}
// WinsLTE applies the LTE predicate on the "wins" field.
func WinsLTE(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldWins), v))
})
}
// WinsIsNil applies the IsNil predicate on the "wins" field.
func WinsIsNil() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldWins)))
})
}
// WinsNotNil applies the NotNil predicate on the "wins" field.
func WinsNotNil() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldWins)))
})
}
// LoosesEQ applies the EQ predicate on the "looses" field.
func LoosesEQ(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldLooses), v))
})
}
// LoosesNEQ applies the NEQ predicate on the "looses" field.
func LoosesNEQ(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldLooses), v))
})
}
// LoosesIn applies the In predicate on the "looses" field.
func LoosesIn(vs ...int) predicate.Player {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Player(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldLooses), v...))
})
}
// LoosesNotIn applies the NotIn predicate on the "looses" field.
func LoosesNotIn(vs ...int) predicate.Player {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Player(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldLooses), v...))
})
}
// LoosesGT applies the GT predicate on the "looses" field.
func LoosesGT(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldLooses), v))
})
}
// LoosesGTE applies the GTE predicate on the "looses" field.
func LoosesGTE(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldLooses), v))
})
}
// LoosesLT applies the LT predicate on the "looses" field.
func LoosesLT(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldLooses), v))
})
}
// LoosesLTE applies the LTE predicate on the "looses" field.
func LoosesLTE(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldLooses), v))
})
}
// LoosesIsNil applies the IsNil predicate on the "looses" field.
func LoosesIsNil() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldLooses)))
})
}
// LoosesNotNil applies the NotNil predicate on the "looses" field.
func LoosesNotNil() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldLooses)))
})
}
// TiesEQ applies the EQ predicate on the "ties" field.
func TiesEQ(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldTies), v))
})
}
// TiesNEQ applies the NEQ predicate on the "ties" field.
func TiesNEQ(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldTies), v))
})
}
// TiesIn applies the In predicate on the "ties" field.
func TiesIn(vs ...int) predicate.Player {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Player(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldTies), v...))
})
}
// TiesNotIn applies the NotIn predicate on the "ties" field.
func TiesNotIn(vs ...int) predicate.Player {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Player(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldTies), v...))
})
}
// TiesGT applies the GT predicate on the "ties" field.
func TiesGT(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldTies), v))
})
}
// TiesGTE applies the GTE predicate on the "ties" field.
func TiesGTE(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldTies), v))
})
}
// TiesLT applies the LT predicate on the "ties" field.
func TiesLT(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldTies), v))
})
}
// TiesLTE applies the LTE predicate on the "ties" field.
func TiesLTE(v int) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldTies), v))
})
}
// TiesIsNil applies the IsNil predicate on the "ties" field.
func TiesIsNil() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldTies)))
})
}
// TiesNotNil applies the NotNil predicate on the "ties" field.
func TiesNotNil() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldTies)))
})
}
// HasStats applies the HasEdge predicate on the "stats" edge.
func HasStats() predicate.Player {
return predicate.Player(func(s *sql.Selector) {
@@ -1563,7 +1854,7 @@ func HasStats() predicate.Player {
}
// HasStatsWith applies the HasEdge predicate on the "stats" edge with a given conditions (other predicates).
func HasStatsWith(preds ...predicate.Stats) predicate.Player {
func HasStatsWith(preds ...predicate.MatchPlayer) predicate.Player {
return predicate.Player(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),

View File

@@ -5,8 +5,8 @@ package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"errors"
"fmt"
"time"
@@ -204,23 +204,65 @@ func (pc *PlayerCreate) SetNillableOldestSharecodeSeen(s *string) *PlayerCreate
return pc
}
// SetWins sets the "wins" field.
func (pc *PlayerCreate) SetWins(i int) *PlayerCreate {
pc.mutation.SetWins(i)
return pc
}
// SetNillableWins sets the "wins" field if the given value is not nil.
func (pc *PlayerCreate) SetNillableWins(i *int) *PlayerCreate {
if i != nil {
pc.SetWins(*i)
}
return pc
}
// SetLooses sets the "looses" field.
func (pc *PlayerCreate) SetLooses(i int) *PlayerCreate {
pc.mutation.SetLooses(i)
return pc
}
// SetNillableLooses sets the "looses" field if the given value is not nil.
func (pc *PlayerCreate) SetNillableLooses(i *int) *PlayerCreate {
if i != nil {
pc.SetLooses(*i)
}
return pc
}
// SetTies sets the "ties" field.
func (pc *PlayerCreate) SetTies(i int) *PlayerCreate {
pc.mutation.SetTies(i)
return pc
}
// SetNillableTies sets the "ties" field if the given value is not nil.
func (pc *PlayerCreate) SetNillableTies(i *int) *PlayerCreate {
if i != nil {
pc.SetTies(*i)
}
return pc
}
// SetID sets the "id" field.
func (pc *PlayerCreate) SetID(u uint64) *PlayerCreate {
pc.mutation.SetID(u)
return pc
}
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
// AddStatIDs adds the "stats" edge to the MatchPlayer 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
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (pc *PlayerCreate) AddStats(m ...*MatchPlayer) *PlayerCreate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return pc.AddStatIDs(ids...)
}
@@ -459,6 +501,30 @@ func (pc *PlayerCreate) createSpec() (*Player, *sqlgraph.CreateSpec) {
})
_node.OldestSharecodeSeen = value
}
if value, ok := pc.mutation.Wins(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldWins,
})
_node.Wins = value
}
if value, ok := pc.mutation.Looses(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldLooses,
})
_node.Looses = value
}
if value, ok := pc.mutation.Ties(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldTies,
})
_node.Ties = value
}
if nodes := pc.mutation.StatsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -469,7 +535,7 @@ func (pc *PlayerCreate) createSpec() (*Player, *sqlgraph.CreateSpec) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}

View File

@@ -5,9 +5,9 @@ package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/predicate"
"csgowtfd/ent/stats"
"database/sql/driver"
"errors"
"fmt"
@@ -28,7 +28,7 @@ type PlayerQuery struct {
fields []string
predicates []predicate.Player
// eager-loading edges.
withStats *StatsQuery
withStats *MatchPlayerQuery
withMatches *MatchQuery
modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
@@ -68,8 +68,8 @@ func (pq *PlayerQuery) Order(o ...OrderFunc) *PlayerQuery {
}
// QueryStats chains the current query on the "stats" edge.
func (pq *PlayerQuery) QueryStats() *StatsQuery {
query := &StatsQuery{config: pq.config}
func (pq *PlayerQuery) QueryStats() *MatchPlayerQuery {
query := &MatchPlayerQuery{config: pq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := pq.prepareQuery(ctx); err != nil {
return nil, err
@@ -80,7 +80,7 @@ func (pq *PlayerQuery) QueryStats() *StatsQuery {
}
step := sqlgraph.NewStep(
sqlgraph.From(player.Table, player.FieldID, selector),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, player.StatsTable, player.StatsColumn),
)
fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step)
@@ -302,8 +302,8 @@ func (pq *PlayerQuery) Clone() *PlayerQuery {
// WithStats tells the query-builder to eager-load the nodes that are connected to
// the "stats" edge. The optional arguments are used to configure the query builder of the edge.
func (pq *PlayerQuery) WithStats(opts ...func(*StatsQuery)) *PlayerQuery {
query := &StatsQuery{config: pq.config}
func (pq *PlayerQuery) WithStats(opts ...func(*MatchPlayerQuery)) *PlayerQuery {
query := &MatchPlayerQuery{config: pq.config}
for _, opt := range opts {
opt(query)
}
@@ -421,9 +421,9 @@ func (pq *PlayerQuery) sqlAll(ctx context.Context) ([]*Player, error) {
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.Stats = []*Stats{}
nodes[i].Edges.Stats = []*MatchPlayer{}
}
query.Where(predicate.Stats(func(s *sql.Selector) {
query.Where(predicate.MatchPlayer(func(s *sql.Selector) {
s.Where(sql.InValues(player.StatsColumn, fks...))
}))
neighbors, err := query.All(ctx)

View File

@@ -5,9 +5,9 @@ package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/predicate"
"csgowtfd/ent/stats"
"fmt"
"time"
@@ -297,17 +297,98 @@ func (pu *PlayerUpdate) ClearOldestSharecodeSeen() *PlayerUpdate {
return pu
}
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
// SetWins sets the "wins" field.
func (pu *PlayerUpdate) SetWins(i int) *PlayerUpdate {
pu.mutation.ResetWins()
pu.mutation.SetWins(i)
return pu
}
// SetNillableWins sets the "wins" field if the given value is not nil.
func (pu *PlayerUpdate) SetNillableWins(i *int) *PlayerUpdate {
if i != nil {
pu.SetWins(*i)
}
return pu
}
// AddWins adds i to the "wins" field.
func (pu *PlayerUpdate) AddWins(i int) *PlayerUpdate {
pu.mutation.AddWins(i)
return pu
}
// ClearWins clears the value of the "wins" field.
func (pu *PlayerUpdate) ClearWins() *PlayerUpdate {
pu.mutation.ClearWins()
return pu
}
// SetLooses sets the "looses" field.
func (pu *PlayerUpdate) SetLooses(i int) *PlayerUpdate {
pu.mutation.ResetLooses()
pu.mutation.SetLooses(i)
return pu
}
// SetNillableLooses sets the "looses" field if the given value is not nil.
func (pu *PlayerUpdate) SetNillableLooses(i *int) *PlayerUpdate {
if i != nil {
pu.SetLooses(*i)
}
return pu
}
// AddLooses adds i to the "looses" field.
func (pu *PlayerUpdate) AddLooses(i int) *PlayerUpdate {
pu.mutation.AddLooses(i)
return pu
}
// ClearLooses clears the value of the "looses" field.
func (pu *PlayerUpdate) ClearLooses() *PlayerUpdate {
pu.mutation.ClearLooses()
return pu
}
// SetTies sets the "ties" field.
func (pu *PlayerUpdate) SetTies(i int) *PlayerUpdate {
pu.mutation.ResetTies()
pu.mutation.SetTies(i)
return pu
}
// SetNillableTies sets the "ties" field if the given value is not nil.
func (pu *PlayerUpdate) SetNillableTies(i *int) *PlayerUpdate {
if i != nil {
pu.SetTies(*i)
}
return pu
}
// AddTies adds i to the "ties" field.
func (pu *PlayerUpdate) AddTies(i int) *PlayerUpdate {
pu.mutation.AddTies(i)
return pu
}
// ClearTies clears the value of the "ties" field.
func (pu *PlayerUpdate) ClearTies() *PlayerUpdate {
pu.mutation.ClearTies()
return pu
}
// AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs.
func (pu *PlayerUpdate) AddStatIDs(ids ...int) *PlayerUpdate {
pu.mutation.AddStatIDs(ids...)
return pu
}
// AddStats adds the "stats" edges to the Stats entity.
func (pu *PlayerUpdate) AddStats(s ...*Stats) *PlayerUpdate {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (pu *PlayerUpdate) AddStats(m ...*MatchPlayer) *PlayerUpdate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return pu.AddStatIDs(ids...)
}
@@ -332,23 +413,23 @@ func (pu *PlayerUpdate) Mutation() *PlayerMutation {
return pu.mutation
}
// ClearStats clears all "stats" edges to the Stats entity.
// ClearStats clears all "stats" edges to the MatchPlayer entity.
func (pu *PlayerUpdate) ClearStats() *PlayerUpdate {
pu.mutation.ClearStats()
return pu
}
// RemoveStatIDs removes the "stats" edge to Stats entities by IDs.
// RemoveStatIDs removes the "stats" edge to MatchPlayer entities by IDs.
func (pu *PlayerUpdate) RemoveStatIDs(ids ...int) *PlayerUpdate {
pu.mutation.RemoveStatIDs(ids...)
return pu
}
// RemoveStats removes "stats" edges to Stats entities.
func (pu *PlayerUpdate) RemoveStats(s ...*Stats) *PlayerUpdate {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// RemoveStats removes "stats" edges to MatchPlayer entities.
func (pu *PlayerUpdate) RemoveStats(m ...*MatchPlayer) *PlayerUpdate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return pu.RemoveStatIDs(ids...)
}
@@ -623,6 +704,66 @@ func (pu *PlayerUpdate) sqlSave(ctx context.Context) (n int, err error) {
Column: player.FieldOldestSharecodeSeen,
})
}
if value, ok := pu.mutation.Wins(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldWins,
})
}
if value, ok := pu.mutation.AddedWins(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldWins,
})
}
if pu.mutation.WinsCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: player.FieldWins,
})
}
if value, ok := pu.mutation.Looses(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldLooses,
})
}
if value, ok := pu.mutation.AddedLooses(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldLooses,
})
}
if pu.mutation.LoosesCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: player.FieldLooses,
})
}
if value, ok := pu.mutation.Ties(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldTies,
})
}
if value, ok := pu.mutation.AddedTies(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldTies,
})
}
if pu.mutation.TiesCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: player.FieldTies,
})
}
if pu.mutation.StatsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -633,7 +774,7 @@ func (pu *PlayerUpdate) sqlSave(ctx context.Context) (n int, err error) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -649,7 +790,7 @@ func (pu *PlayerUpdate) sqlSave(ctx context.Context) (n int, err error) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -668,7 +809,7 @@ func (pu *PlayerUpdate) sqlSave(ctx context.Context) (n int, err error) {
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -1018,17 +1159,98 @@ func (puo *PlayerUpdateOne) ClearOldestSharecodeSeen() *PlayerUpdateOne {
return puo
}
// AddStatIDs adds the "stats" edge to the Stats entity by IDs.
// SetWins sets the "wins" field.
func (puo *PlayerUpdateOne) SetWins(i int) *PlayerUpdateOne {
puo.mutation.ResetWins()
puo.mutation.SetWins(i)
return puo
}
// SetNillableWins sets the "wins" field if the given value is not nil.
func (puo *PlayerUpdateOne) SetNillableWins(i *int) *PlayerUpdateOne {
if i != nil {
puo.SetWins(*i)
}
return puo
}
// AddWins adds i to the "wins" field.
func (puo *PlayerUpdateOne) AddWins(i int) *PlayerUpdateOne {
puo.mutation.AddWins(i)
return puo
}
// ClearWins clears the value of the "wins" field.
func (puo *PlayerUpdateOne) ClearWins() *PlayerUpdateOne {
puo.mutation.ClearWins()
return puo
}
// SetLooses sets the "looses" field.
func (puo *PlayerUpdateOne) SetLooses(i int) *PlayerUpdateOne {
puo.mutation.ResetLooses()
puo.mutation.SetLooses(i)
return puo
}
// SetNillableLooses sets the "looses" field if the given value is not nil.
func (puo *PlayerUpdateOne) SetNillableLooses(i *int) *PlayerUpdateOne {
if i != nil {
puo.SetLooses(*i)
}
return puo
}
// AddLooses adds i to the "looses" field.
func (puo *PlayerUpdateOne) AddLooses(i int) *PlayerUpdateOne {
puo.mutation.AddLooses(i)
return puo
}
// ClearLooses clears the value of the "looses" field.
func (puo *PlayerUpdateOne) ClearLooses() *PlayerUpdateOne {
puo.mutation.ClearLooses()
return puo
}
// SetTies sets the "ties" field.
func (puo *PlayerUpdateOne) SetTies(i int) *PlayerUpdateOne {
puo.mutation.ResetTies()
puo.mutation.SetTies(i)
return puo
}
// SetNillableTies sets the "ties" field if the given value is not nil.
func (puo *PlayerUpdateOne) SetNillableTies(i *int) *PlayerUpdateOne {
if i != nil {
puo.SetTies(*i)
}
return puo
}
// AddTies adds i to the "ties" field.
func (puo *PlayerUpdateOne) AddTies(i int) *PlayerUpdateOne {
puo.mutation.AddTies(i)
return puo
}
// ClearTies clears the value of the "ties" field.
func (puo *PlayerUpdateOne) ClearTies() *PlayerUpdateOne {
puo.mutation.ClearTies()
return puo
}
// AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs.
func (puo *PlayerUpdateOne) AddStatIDs(ids ...int) *PlayerUpdateOne {
puo.mutation.AddStatIDs(ids...)
return puo
}
// AddStats adds the "stats" edges to the Stats entity.
func (puo *PlayerUpdateOne) AddStats(s ...*Stats) *PlayerUpdateOne {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// AddStats adds the "stats" edges to the MatchPlayer entity.
func (puo *PlayerUpdateOne) AddStats(m ...*MatchPlayer) *PlayerUpdateOne {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return puo.AddStatIDs(ids...)
}
@@ -1053,23 +1275,23 @@ func (puo *PlayerUpdateOne) Mutation() *PlayerMutation {
return puo.mutation
}
// ClearStats clears all "stats" edges to the Stats entity.
// ClearStats clears all "stats" edges to the MatchPlayer entity.
func (puo *PlayerUpdateOne) ClearStats() *PlayerUpdateOne {
puo.mutation.ClearStats()
return puo
}
// RemoveStatIDs removes the "stats" edge to Stats entities by IDs.
// RemoveStatIDs removes the "stats" edge to MatchPlayer entities by IDs.
func (puo *PlayerUpdateOne) RemoveStatIDs(ids ...int) *PlayerUpdateOne {
puo.mutation.RemoveStatIDs(ids...)
return puo
}
// RemoveStats removes "stats" edges to Stats entities.
func (puo *PlayerUpdateOne) RemoveStats(s ...*Stats) *PlayerUpdateOne {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
// RemoveStats removes "stats" edges to MatchPlayer entities.
func (puo *PlayerUpdateOne) RemoveStats(m ...*MatchPlayer) *PlayerUpdateOne {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return puo.RemoveStatIDs(ids...)
}
@@ -1368,6 +1590,66 @@ func (puo *PlayerUpdateOne) sqlSave(ctx context.Context) (_node *Player, err err
Column: player.FieldOldestSharecodeSeen,
})
}
if value, ok := puo.mutation.Wins(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldWins,
})
}
if value, ok := puo.mutation.AddedWins(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldWins,
})
}
if puo.mutation.WinsCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: player.FieldWins,
})
}
if value, ok := puo.mutation.Looses(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldLooses,
})
}
if value, ok := puo.mutation.AddedLooses(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldLooses,
})
}
if puo.mutation.LoosesCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: player.FieldLooses,
})
}
if value, ok := puo.mutation.Ties(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldTies,
})
}
if value, ok := puo.mutation.AddedTies(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: player.FieldTies,
})
}
if puo.mutation.TiesCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: player.FieldTies,
})
}
if puo.mutation.StatsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -1378,7 +1660,7 @@ func (puo *PlayerUpdateOne) sqlSave(ctx context.Context) (_node *Player, err err
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -1394,7 +1676,7 @@ func (puo *PlayerUpdateOne) sqlSave(ctx context.Context) (_node *Player, err err
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -1413,7 +1695,7 @@ func (puo *PlayerUpdateOne) sqlSave(ctx context.Context) (_node *Player, err err
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}

View File

@@ -9,14 +9,17 @@ import (
// Match is the predicate function for match builders.
type Match func(*sql.Selector)
// MatchPlayer is the predicate function for matchplayer builders.
type MatchPlayer func(*sql.Selector)
// Player is the predicate function for player builders.
type Player func(*sql.Selector)
// RoundStats is the predicate function for roundstats builders.
type RoundStats func(*sql.Selector)
// Stats is the predicate function for stats builders.
type Stats func(*sql.Selector)
// Spray is the predicate function for spray builders.
type Spray func(*sql.Selector)
// WeaponStats is the predicate function for weaponstats builders.
type WeaponStats func(*sql.Selector)
// Weapon is the predicate function for weapon builders.
type Weapon func(*sql.Selector)

View File

@@ -3,8 +3,8 @@
package ent
import (
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"fmt"
"strings"
@@ -27,30 +27,30 @@ type RoundStats struct {
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the RoundStatsQuery when eager-loading is set.
Edges RoundStatsEdges `json:"edges"`
stats_round_stats *int
match_player_round_stats *int
}
// RoundStatsEdges holds the relations/edges for other nodes in the graph.
type RoundStatsEdges struct {
// Stat holds the value of the stat edge.
Stat *Stats `json:"stat,omitempty"`
// MatchPlayer holds the value of the match_player edge.
MatchPlayer *MatchPlayer `json:"match_player,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// StatOrErr returns the Stat value or an error if the edge
// MatchPlayerOrErr returns the MatchPlayer value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RoundStatsEdges) StatOrErr() (*Stats, error) {
func (e RoundStatsEdges) MatchPlayerOrErr() (*MatchPlayer, error) {
if e.loadedTypes[0] {
if e.Stat == nil {
// The edge stat was loaded in eager-loading,
if e.MatchPlayer == nil {
// The edge match_player was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: stats.Label}
return nil, &NotFoundError{label: matchplayer.Label}
}
return e.Stat, nil
return e.MatchPlayer, nil
}
return nil, &NotLoadedError{edge: "stat"}
return nil, &NotLoadedError{edge: "match_player"}
}
// scanValues returns the types for scanning values from sql.Rows.
@@ -60,7 +60,7 @@ func (*RoundStats) scanValues(columns []string) ([]interface{}, error) {
switch columns[i] {
case roundstats.FieldID, roundstats.FieldRound, roundstats.FieldBank, roundstats.FieldEquipment, roundstats.FieldSpent:
values[i] = new(sql.NullInt64)
case roundstats.ForeignKeys[0]: // stats_round_stats
case roundstats.ForeignKeys[0]: // match_player_round_stats
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type RoundStats", columns[i])
@@ -109,19 +109,19 @@ func (rs *RoundStats) assignValues(columns []string, values []interface{}) error
}
case roundstats.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field stats_round_stats", value)
return fmt.Errorf("unexpected type %T for edge-field match_player_round_stats", value)
} else if value.Valid {
rs.stats_round_stats = new(int)
*rs.stats_round_stats = int(value.Int64)
rs.match_player_round_stats = new(int)
*rs.match_player_round_stats = int(value.Int64)
}
}
}
return nil
}
// QueryStat queries the "stat" edge of the RoundStats entity.
func (rs *RoundStats) QueryStat() *StatsQuery {
return (&RoundStatsClient{config: rs.config}).QueryStat(rs)
// QueryMatchPlayer queries the "match_player" edge of the RoundStats entity.
func (rs *RoundStats) QueryMatchPlayer() *MatchPlayerQuery {
return (&RoundStatsClient{config: rs.config}).QueryMatchPlayer(rs)
}
// Update returns a builder for updating this RoundStats.

View File

@@ -15,17 +15,17 @@ const (
FieldEquipment = "equipment"
// FieldSpent holds the string denoting the spent field in the database.
FieldSpent = "spent"
// EdgeStat holds the string denoting the stat edge name in mutations.
EdgeStat = "stat"
// EdgeMatchPlayer holds the string denoting the match_player edge name in mutations.
EdgeMatchPlayer = "match_player"
// Table holds the table name of the roundstats in the database.
Table = "round_stats"
// StatTable is the table that holds the stat relation/edge.
StatTable = "round_stats"
// StatInverseTable is the table name for the Stats entity.
// It exists in this package in order to avoid circular dependency with the "stats" package.
StatInverseTable = "stats"
// StatColumn is the table column denoting the stat relation/edge.
StatColumn = "stats_round_stats"
// MatchPlayerTable is the table that holds the match_player relation/edge.
MatchPlayerTable = "round_stats"
// MatchPlayerInverseTable is the table name for the MatchPlayer entity.
// It exists in this package in order to avoid circular dependency with the "matchplayer" package.
MatchPlayerInverseTable = "match_players"
// MatchPlayerColumn is the table column denoting the match_player relation/edge.
MatchPlayerColumn = "match_player_round_stats"
)
// Columns holds all SQL columns for roundstats fields.
@@ -40,7 +40,7 @@ var Columns = []string{
// ForeignKeys holds the SQL foreign-keys that are owned by the "round_stats"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"stats_round_stats",
"match_player_round_stats",
}
// ValidColumn reports if the column name is valid (part of the table columns).

View File

@@ -424,25 +424,25 @@ func SpentLTE(v uint) predicate.RoundStats {
})
}
// HasStat applies the HasEdge predicate on the "stat" edge.
func HasStat() predicate.RoundStats {
// HasMatchPlayer applies the HasEdge predicate on the "match_player" edge.
func HasMatchPlayer() predicate.RoundStats {
return predicate.RoundStats(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(StatTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, StatTable, StatColumn),
sqlgraph.To(MatchPlayerTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, MatchPlayerTable, MatchPlayerColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasStatWith applies the HasEdge predicate on the "stat" edge with a given conditions (other predicates).
func HasStatWith(preds ...predicate.Stats) predicate.RoundStats {
// HasMatchPlayerWith applies the HasEdge predicate on the "match_player" edge with a given conditions (other predicates).
func HasMatchPlayerWith(preds ...predicate.MatchPlayer) predicate.RoundStats {
return predicate.RoundStats(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(StatInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, StatTable, StatColumn),
sqlgraph.To(MatchPlayerInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, MatchPlayerTable, MatchPlayerColumn),
)
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {

View File

@@ -4,8 +4,8 @@ package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"errors"
"fmt"
@@ -44,23 +44,23 @@ func (rsc *RoundStatsCreate) SetSpent(u uint) *RoundStatsCreate {
return rsc
}
// SetStatID sets the "stat" edge to the Stats entity by ID.
func (rsc *RoundStatsCreate) SetStatID(id int) *RoundStatsCreate {
rsc.mutation.SetStatID(id)
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
func (rsc *RoundStatsCreate) SetMatchPlayerID(id int) *RoundStatsCreate {
rsc.mutation.SetMatchPlayerID(id)
return rsc
}
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
func (rsc *RoundStatsCreate) SetNillableStatID(id *int) *RoundStatsCreate {
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
func (rsc *RoundStatsCreate) SetNillableMatchPlayerID(id *int) *RoundStatsCreate {
if id != nil {
rsc = rsc.SetStatID(*id)
rsc = rsc.SetMatchPlayerID(*id)
}
return rsc
}
// SetStat sets the "stat" edge to the Stats entity.
func (rsc *RoundStatsCreate) SetStat(s *Stats) *RoundStatsCreate {
return rsc.SetStatID(s.ID)
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
func (rsc *RoundStatsCreate) SetMatchPlayer(m *MatchPlayer) *RoundStatsCreate {
return rsc.SetMatchPlayerID(m.ID)
}
// Mutation returns the RoundStatsMutation object of the builder.
@@ -204,24 +204,24 @@ func (rsc *RoundStatsCreate) createSpec() (*RoundStats, *sqlgraph.CreateSpec) {
})
_node.Spent = value
}
if nodes := rsc.mutation.StatIDs(); len(nodes) > 0 {
if nodes := rsc.mutation.MatchPlayerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.StatTable,
Columns: []string{roundstats.StatColumn},
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.stats_round_stats = &nodes[0]
_node.match_player_round_stats = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -4,9 +4,9 @@ package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/predicate"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"errors"
"fmt"
"math"
@@ -26,7 +26,7 @@ type RoundStatsQuery struct {
fields []string
predicates []predicate.RoundStats
// eager-loading edges.
withStat *StatsQuery
withMatchPlayer *MatchPlayerQuery
withFKs bool
modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
@@ -65,9 +65,9 @@ func (rsq *RoundStatsQuery) Order(o ...OrderFunc) *RoundStatsQuery {
return rsq
}
// QueryStat chains the current query on the "stat" edge.
func (rsq *RoundStatsQuery) QueryStat() *StatsQuery {
query := &StatsQuery{config: rsq.config}
// QueryMatchPlayer chains the current query on the "match_player" edge.
func (rsq *RoundStatsQuery) QueryMatchPlayer() *MatchPlayerQuery {
query := &MatchPlayerQuery{config: rsq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := rsq.prepareQuery(ctx); err != nil {
return nil, err
@@ -78,8 +78,8 @@ func (rsq *RoundStatsQuery) QueryStat() *StatsQuery {
}
step := sqlgraph.NewStep(
sqlgraph.From(roundstats.Table, roundstats.FieldID, selector),
sqlgraph.To(stats.Table, stats.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, roundstats.StatTable, roundstats.StatColumn),
sqlgraph.To(matchplayer.Table, matchplayer.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, roundstats.MatchPlayerTable, roundstats.MatchPlayerColumn),
)
fromU = sqlgraph.SetNeighbors(rsq.driver.Dialect(), step)
return fromU, nil
@@ -268,21 +268,21 @@ func (rsq *RoundStatsQuery) Clone() *RoundStatsQuery {
offset: rsq.offset,
order: append([]OrderFunc{}, rsq.order...),
predicates: append([]predicate.RoundStats{}, rsq.predicates...),
withStat: rsq.withStat.Clone(),
withMatchPlayer: rsq.withMatchPlayer.Clone(),
// clone intermediate query.
sql: rsq.sql.Clone(),
path: rsq.path,
}
}
// WithStat tells the query-builder to eager-load the nodes that are connected to
// the "stat" edge. The optional arguments are used to configure the query builder of the edge.
func (rsq *RoundStatsQuery) WithStat(opts ...func(*StatsQuery)) *RoundStatsQuery {
query := &StatsQuery{config: rsq.config}
// WithMatchPlayer tells the query-builder to eager-load the nodes that are connected to
// the "match_player" edge. The optional arguments are used to configure the query builder of the edge.
func (rsq *RoundStatsQuery) WithMatchPlayer(opts ...func(*MatchPlayerQuery)) *RoundStatsQuery {
query := &MatchPlayerQuery{config: rsq.config}
for _, opt := range opts {
opt(query)
}
rsq.withStat = query
rsq.withMatchPlayer = query
return rsq
}
@@ -353,10 +353,10 @@ func (rsq *RoundStatsQuery) sqlAll(ctx context.Context) ([]*RoundStats, error) {
withFKs = rsq.withFKs
_spec = rsq.querySpec()
loadedTypes = [1]bool{
rsq.withStat != nil,
rsq.withMatchPlayer != nil,
}
)
if rsq.withStat != nil {
if rsq.withMatchPlayer != nil {
withFKs = true
}
if withFKs {
@@ -385,20 +385,20 @@ func (rsq *RoundStatsQuery) sqlAll(ctx context.Context) ([]*RoundStats, error) {
return nodes, nil
}
if query := rsq.withStat; query != nil {
if query := rsq.withMatchPlayer; query != nil {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*RoundStats)
for i := range nodes {
if nodes[i].stats_round_stats == nil {
if nodes[i].match_player_round_stats == nil {
continue
}
fk := *nodes[i].stats_round_stats
fk := *nodes[i].match_player_round_stats
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
query.Where(stats.IDIn(ids...))
query.Where(matchplayer.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return nil, err
@@ -406,10 +406,10 @@ func (rsq *RoundStatsQuery) sqlAll(ctx context.Context) ([]*RoundStats, error) {
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return nil, fmt.Errorf(`unexpected foreign-key "stats_round_stats" returned %v`, n.ID)
return nil, fmt.Errorf(`unexpected foreign-key "match_player_round_stats" returned %v`, n.ID)
}
for i := range nodes {
nodes[i].Edges.Stat = n
nodes[i].Edges.MatchPlayer = n
}
}
}

View File

@@ -4,9 +4,9 @@ package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/predicate"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"fmt"
"entgo.io/ent/dialect/sql"
@@ -79,23 +79,23 @@ func (rsu *RoundStatsUpdate) AddSpent(u uint) *RoundStatsUpdate {
return rsu
}
// SetStatID sets the "stat" edge to the Stats entity by ID.
func (rsu *RoundStatsUpdate) SetStatID(id int) *RoundStatsUpdate {
rsu.mutation.SetStatID(id)
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
func (rsu *RoundStatsUpdate) SetMatchPlayerID(id int) *RoundStatsUpdate {
rsu.mutation.SetMatchPlayerID(id)
return rsu
}
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
func (rsu *RoundStatsUpdate) SetNillableStatID(id *int) *RoundStatsUpdate {
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
func (rsu *RoundStatsUpdate) SetNillableMatchPlayerID(id *int) *RoundStatsUpdate {
if id != nil {
rsu = rsu.SetStatID(*id)
rsu = rsu.SetMatchPlayerID(*id)
}
return rsu
}
// SetStat sets the "stat" edge to the Stats entity.
func (rsu *RoundStatsUpdate) SetStat(s *Stats) *RoundStatsUpdate {
return rsu.SetStatID(s.ID)
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
func (rsu *RoundStatsUpdate) SetMatchPlayer(m *MatchPlayer) *RoundStatsUpdate {
return rsu.SetMatchPlayerID(m.ID)
}
// Mutation returns the RoundStatsMutation object of the builder.
@@ -103,9 +103,9 @@ func (rsu *RoundStatsUpdate) Mutation() *RoundStatsMutation {
return rsu.mutation
}
// ClearStat clears the "stat" edge to the Stats entity.
func (rsu *RoundStatsUpdate) ClearStat() *RoundStatsUpdate {
rsu.mutation.ClearStat()
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
func (rsu *RoundStatsUpdate) ClearMatchPlayer() *RoundStatsUpdate {
rsu.mutation.ClearMatchPlayer()
return rsu
}
@@ -237,33 +237,33 @@ func (rsu *RoundStatsUpdate) sqlSave(ctx context.Context) (n int, err error) {
Column: roundstats.FieldSpent,
})
}
if rsu.mutation.StatCleared() {
if rsu.mutation.MatchPlayerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.StatTable,
Columns: []string{roundstats.StatColumn},
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := rsu.mutation.StatIDs(); len(nodes) > 0 {
if nodes := rsu.mutation.MatchPlayerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.StatTable,
Columns: []string{roundstats.StatColumn},
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
@@ -343,23 +343,23 @@ func (rsuo *RoundStatsUpdateOne) AddSpent(u uint) *RoundStatsUpdateOne {
return rsuo
}
// SetStatID sets the "stat" edge to the Stats entity by ID.
func (rsuo *RoundStatsUpdateOne) SetStatID(id int) *RoundStatsUpdateOne {
rsuo.mutation.SetStatID(id)
// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID.
func (rsuo *RoundStatsUpdateOne) SetMatchPlayerID(id int) *RoundStatsUpdateOne {
rsuo.mutation.SetMatchPlayerID(id)
return rsuo
}
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
func (rsuo *RoundStatsUpdateOne) SetNillableStatID(id *int) *RoundStatsUpdateOne {
// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil.
func (rsuo *RoundStatsUpdateOne) SetNillableMatchPlayerID(id *int) *RoundStatsUpdateOne {
if id != nil {
rsuo = rsuo.SetStatID(*id)
rsuo = rsuo.SetMatchPlayerID(*id)
}
return rsuo
}
// SetStat sets the "stat" edge to the Stats entity.
func (rsuo *RoundStatsUpdateOne) SetStat(s *Stats) *RoundStatsUpdateOne {
return rsuo.SetStatID(s.ID)
// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity.
func (rsuo *RoundStatsUpdateOne) SetMatchPlayer(m *MatchPlayer) *RoundStatsUpdateOne {
return rsuo.SetMatchPlayerID(m.ID)
}
// Mutation returns the RoundStatsMutation object of the builder.
@@ -367,9 +367,9 @@ func (rsuo *RoundStatsUpdateOne) Mutation() *RoundStatsMutation {
return rsuo.mutation
}
// ClearStat clears the "stat" edge to the Stats entity.
func (rsuo *RoundStatsUpdateOne) ClearStat() *RoundStatsUpdateOne {
rsuo.mutation.ClearStat()
// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity.
func (rsuo *RoundStatsUpdateOne) ClearMatchPlayer() *RoundStatsUpdateOne {
rsuo.mutation.ClearMatchPlayer()
return rsuo
}
@@ -525,33 +525,33 @@ func (rsuo *RoundStatsUpdateOne) sqlSave(ctx context.Context) (_node *RoundStats
Column: roundstats.FieldSpent,
})
}
if rsuo.mutation.StatCleared() {
if rsuo.mutation.MatchPlayerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.StatTable,
Columns: []string{roundstats.StatColumn},
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := rsuo.mutation.StatIDs(); len(nodes) > 0 {
if nodes := rsuo.mutation.MatchPlayerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: roundstats.StatTable,
Columns: []string{roundstats.StatColumn},
Table: roundstats.MatchPlayerTable,
Columns: []string{roundstats.MatchPlayerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: matchplayer.FieldID,
},
},
}

View File

@@ -33,7 +33,7 @@ func (Match) Fields() []ent.Field {
// Edges of the Match.
func (Match) Edges() []ent.Edge {
return []ent.Edge{
edge.To("stats", Stats.Type),
edge.To("stats", MatchPlayer.Type),
edge.From("players", Player.Type).Ref("matches"),
}
}

View File

@@ -6,13 +6,13 @@ import (
"entgo.io/ent/schema/field"
)
// Stats holds the schema definition for the Stats entity.
type Stats struct {
// MatchPlayer holds the schema definition for the MatchPlayer entity.
type MatchPlayer struct {
ent.Schema
}
// Fields of the Stats.
func (Stats) Fields() []ent.Field {
func (MatchPlayer) Fields() []ent.Field {
return []ent.Field{
field.Int("team_id"),
field.Int("kills"),
@@ -45,15 +45,17 @@ func (Stats) Fields() []ent.Field {
field.Uint("flash_total_enemy").Optional(),
field.Uint64("match_stats").Optional(),
field.Uint64("player_stats").Optional(),
field.Int("flash_assists").Optional(),
}
}
// Edges of the Stats.
func (Stats) Edges() []ent.Edge {
// Edges of the MatchPlayer.
func (MatchPlayer) Edges() []ent.Edge {
return []ent.Edge{
edge.From("matches", Match.Type).Ref("stats").Unique().Field("match_stats"),
edge.From("players", Player.Type).Ref("stats").Unique().Field("player_stats"),
edge.To("weapon_stats", WeaponStats.Type),
edge.To("weapon_stats", Weapon.Type),
edge.To("round_stats", RoundStats.Type),
edge.To("spray", Spray.Type),
}
}

View File

@@ -31,13 +31,16 @@ func (Player) Fields() []ent.Field {
field.String("auth_code").Optional().Sensitive(),
field.Time("profile_created").Optional(),
field.String("oldest_sharecode_seen").Optional(),
field.Int("wins").Optional(),
field.Int("looses").Optional(),
field.Int("ties").Optional(),
}
}
// Edges of the Player.
func (Player) Edges() []ent.Edge {
return []ent.Edge{
edge.To("stats", Stats.Type),
edge.To("stats", MatchPlayer.Type),
edge.To("matches", Match.Type),
}
}

View File

@@ -24,6 +24,6 @@ func (RoundStats) Fields() []ent.Field {
// Edges of the RoundStats.
func (RoundStats) Edges() []ent.Edge {
return []ent.Edge{
edge.From("stat", Stats.Type).Ref("round_stats").Unique(),
edge.From("match_player", MatchPlayer.Type).Ref("round_stats").Unique(),
}
}

27
ent/schema/spray.go Normal file
View File

@@ -0,0 +1,27 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Spray holds the schema definition for the Spray entity.
type Spray struct {
ent.Schema
}
// Fields of the Spray.
func (Spray) Fields() []ent.Field {
return []ent.Field{
field.Int("weapon"),
field.Bytes("spray"),
}
}
// Edges of the Spray.
func (Spray) Edges() []ent.Edge {
return []ent.Edge{
edge.From("match_players", MatchPlayer.Type).Ref("spray").Unique(),
}
}

29
ent/schema/weapon.go Normal file
View File

@@ -0,0 +1,29 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Weapon holds the schema definition for the Weapon entity.
type Weapon struct {
ent.Schema
}
// Fields of the Weapon.
func (Weapon) Fields() []ent.Field {
return []ent.Field{
field.Uint64("victim"),
field.Uint("dmg"),
field.Int("eq_type"),
field.Int("hit_group"),
}
}
// Edges of the Weapon.
func (Weapon) Edges() []ent.Edge {
return []ent.Edge{
edge.From("stat", MatchPlayer.Type).Ref("weapon_stats").Unique(),
}
}

View File

@@ -1,29 +0,0 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// WeaponStats holds the schema definition for the WeaponStats entity.
type WeaponStats struct {
ent.Schema
}
// Fields of the WeaponStats.
func (WeaponStats) Fields() []ent.Field {
return []ent.Field{
field.Uint64("victim"),
field.Uint("dmg"),
field.Int("eq_type"),
field.Int("hit_group"),
}
}
// Edges of the WeaponStats.
func (WeaponStats) Edges() []ent.Edge {
return []ent.Edge{
edge.From("stat", Stats.Type).Ref("weapon_stats").Unique(),
}
}

151
ent/spray.go Normal file
View File

@@ -0,0 +1,151 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/spray"
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
)
// Spray is the model entity for the Spray schema.
type Spray struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Weapon holds the value of the "weapon" field.
Weapon int `json:"weapon,omitempty"`
// Spray holds the value of the "spray" field.
Spray []byte `json:"spray,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SprayQuery when eager-loading is set.
Edges SprayEdges `json:"edges"`
match_player_spray *int
}
// SprayEdges holds the relations/edges for other nodes in the graph.
type SprayEdges struct {
// MatchPlayers holds the value of the match_players edge.
MatchPlayers *MatchPlayer `json:"match_players,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// MatchPlayersOrErr returns the MatchPlayers value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SprayEdges) MatchPlayersOrErr() (*MatchPlayer, error) {
if e.loadedTypes[0] {
if e.MatchPlayers == nil {
// The edge match_players was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: matchplayer.Label}
}
return e.MatchPlayers, nil
}
return nil, &NotLoadedError{edge: "match_players"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Spray) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case spray.FieldSpray:
values[i] = new([]byte)
case spray.FieldID, spray.FieldWeapon:
values[i] = new(sql.NullInt64)
case spray.ForeignKeys[0]: // match_player_spray
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type Spray", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Spray fields.
func (s *Spray) assignValues(columns []string, values []interface{}) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case spray.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
s.ID = int(value.Int64)
case spray.FieldWeapon:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field weapon", values[i])
} else if value.Valid {
s.Weapon = int(value.Int64)
}
case spray.FieldSpray:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field spray", values[i])
} else if value != nil {
s.Spray = *value
}
case spray.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field match_player_spray", value)
} else if value.Valid {
s.match_player_spray = new(int)
*s.match_player_spray = int(value.Int64)
}
}
}
return nil
}
// QueryMatchPlayers queries the "match_players" edge of the Spray entity.
func (s *Spray) QueryMatchPlayers() *MatchPlayerQuery {
return (&SprayClient{config: s.config}).QueryMatchPlayers(s)
}
// Update returns a builder for updating this Spray.
// Note that you need to call Spray.Unwrap() before calling this method if this Spray
// was returned from a transaction, and the transaction was committed or rolled back.
func (s *Spray) Update() *SprayUpdateOne {
return (&SprayClient{config: s.config}).UpdateOne(s)
}
// Unwrap unwraps the Spray entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (s *Spray) Unwrap() *Spray {
tx, ok := s.config.driver.(*txDriver)
if !ok {
panic("ent: Spray is not a transactional entity")
}
s.config.driver = tx.drv
return s
}
// String implements the fmt.Stringer.
func (s *Spray) String() string {
var builder strings.Builder
builder.WriteString("Spray(")
builder.WriteString(fmt.Sprintf("id=%v", s.ID))
builder.WriteString(", weapon=")
builder.WriteString(fmt.Sprintf("%v", s.Weapon))
builder.WriteString(", spray=")
builder.WriteString(fmt.Sprintf("%v", s.Spray))
builder.WriteByte(')')
return builder.String()
}
// Sprays is a parsable slice of Spray.
type Sprays []*Spray
func (s Sprays) config(cfg config) {
for _i := range s {
s[_i].config = cfg
}
}

53
ent/spray/spray.go Normal file
View File

@@ -0,0 +1,53 @@
// Code generated by entc, DO NOT EDIT.
package spray
const (
// Label holds the string label denoting the spray type in the database.
Label = "spray"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldWeapon holds the string denoting the weapon field in the database.
FieldWeapon = "weapon"
// FieldSpray holds the string denoting the spray field in the database.
FieldSpray = "spray"
// EdgeMatchPlayers holds the string denoting the match_players edge name in mutations.
EdgeMatchPlayers = "match_players"
// Table holds the table name of the spray in the database.
Table = "sprays"
// MatchPlayersTable is the table that holds the match_players relation/edge.
MatchPlayersTable = "sprays"
// MatchPlayersInverseTable is the table name for the MatchPlayer entity.
// It exists in this package in order to avoid circular dependency with the "matchplayer" package.
MatchPlayersInverseTable = "match_players"
// MatchPlayersColumn is the table column denoting the match_players relation/edge.
MatchPlayersColumn = "match_player_spray"
)
// Columns holds all SQL columns for spray fields.
var Columns = []string{
FieldID,
FieldWeapon,
FieldSpray,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "sprays"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"match_player_spray",
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
for i := range ForeignKeys {
if column == ForeignKeys[i] {
return true
}
}
return false
}

319
ent/spray/where.go Normal file
View File

@@ -0,0 +1,319 @@
// Code generated by entc, DO NOT EDIT.
package spray
import (
"csgowtfd/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
})
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.In(s.C(FieldID), v...))
})
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.NotIn(s.C(FieldID), v...))
})
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldID), id))
})
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldID), id))
})
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldID), id))
})
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
})
}
// Weapon applies equality check predicate on the "weapon" field. It's identical to WeaponEQ.
func Weapon(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldWeapon), v))
})
}
// Spray applies equality check predicate on the "spray" field. It's identical to SprayEQ.
func Spray(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldSpray), v))
})
}
// WeaponEQ applies the EQ predicate on the "weapon" field.
func WeaponEQ(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldWeapon), v))
})
}
// WeaponNEQ applies the NEQ predicate on the "weapon" field.
func WeaponNEQ(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldWeapon), v))
})
}
// WeaponIn applies the In predicate on the "weapon" field.
func WeaponIn(vs ...int) predicate.Spray {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Spray(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldWeapon), v...))
})
}
// WeaponNotIn applies the NotIn predicate on the "weapon" field.
func WeaponNotIn(vs ...int) predicate.Spray {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Spray(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldWeapon), v...))
})
}
// WeaponGT applies the GT predicate on the "weapon" field.
func WeaponGT(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldWeapon), v))
})
}
// WeaponGTE applies the GTE predicate on the "weapon" field.
func WeaponGTE(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldWeapon), v))
})
}
// WeaponLT applies the LT predicate on the "weapon" field.
func WeaponLT(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldWeapon), v))
})
}
// WeaponLTE applies the LTE predicate on the "weapon" field.
func WeaponLTE(v int) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldWeapon), v))
})
}
// SprayEQ applies the EQ predicate on the "spray" field.
func SprayEQ(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldSpray), v))
})
}
// SprayNEQ applies the NEQ predicate on the "spray" field.
func SprayNEQ(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldSpray), v))
})
}
// SprayIn applies the In predicate on the "spray" field.
func SprayIn(vs ...[]byte) predicate.Spray {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Spray(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldSpray), v...))
})
}
// SprayNotIn applies the NotIn predicate on the "spray" field.
func SprayNotIn(vs ...[]byte) predicate.Spray {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Spray(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldSpray), v...))
})
}
// SprayGT applies the GT predicate on the "spray" field.
func SprayGT(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldSpray), v))
})
}
// SprayGTE applies the GTE predicate on the "spray" field.
func SprayGTE(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldSpray), v))
})
}
// SprayLT applies the LT predicate on the "spray" field.
func SprayLT(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldSpray), v))
})
}
// SprayLTE applies the LTE predicate on the "spray" field.
func SprayLTE(v []byte) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldSpray), v))
})
}
// HasMatchPlayers applies the HasEdge predicate on the "match_players" edge.
func HasMatchPlayers() predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(MatchPlayersTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, MatchPlayersTable, MatchPlayersColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasMatchPlayersWith applies the HasEdge predicate on the "match_players" edge with a given conditions (other predicates).
func HasMatchPlayersWith(preds ...predicate.MatchPlayer) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(MatchPlayersInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, MatchPlayersTable, MatchPlayersColumn),
)
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Spray) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
})
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Spray) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
}
s.Where(s1.P())
})
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Spray) predicate.Spray {
return predicate.Spray(func(s *sql.Selector) {
p(s.Not())
})
}

277
ent/spray_create.go Normal file
View 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)
}
}

View File

@@ -5,7 +5,7 @@ package ent
import (
"context"
"csgowtfd/ent/predicate"
"csgowtfd/ent/stats"
"csgowtfd/ent/spray"
"fmt"
"entgo.io/ent/dialect/sql"
@@ -13,21 +13,21 @@ import (
"entgo.io/ent/schema/field"
)
// StatsDelete is the builder for deleting a Stats entity.
type StatsDelete struct {
// SprayDelete is the builder for deleting a Spray entity.
type SprayDelete struct {
config
hooks []Hook
mutation *StatsMutation
mutation *SprayMutation
}
// Where appends a list predicates to the StatsDelete builder.
func (sd *StatsDelete) Where(ps ...predicate.Stats) *StatsDelete {
// Where appends a list predicates to the SprayDelete builder.
func (sd *SprayDelete) Where(ps ...predicate.Spray) *SprayDelete {
sd.mutation.Where(ps...)
return sd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (sd *StatsDelete) Exec(ctx context.Context) (int, error) {
func (sd *SprayDelete) Exec(ctx context.Context) (int, error) {
var (
err error
affected int
@@ -36,7 +36,7 @@ func (sd *StatsDelete) Exec(ctx context.Context) (int, error) {
affected, err = sd.sqlExec(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*StatsMutation)
mutation, ok := m.(*SprayMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
@@ -59,7 +59,7 @@ func (sd *StatsDelete) Exec(ctx context.Context) (int, error) {
}
// ExecX is like Exec, but panics if an error occurs.
func (sd *StatsDelete) ExecX(ctx context.Context) int {
func (sd *SprayDelete) ExecX(ctx context.Context) int {
n, err := sd.Exec(ctx)
if err != nil {
panic(err)
@@ -67,13 +67,13 @@ func (sd *StatsDelete) ExecX(ctx context.Context) int {
return n
}
func (sd *StatsDelete) sqlExec(ctx context.Context) (int, error) {
func (sd *SprayDelete) sqlExec(ctx context.Context) (int, error) {
_spec := &sqlgraph.DeleteSpec{
Node: &sqlgraph.NodeSpec{
Table: stats.Table,
Table: spray.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
Column: spray.FieldID,
},
},
}
@@ -87,25 +87,25 @@ func (sd *StatsDelete) sqlExec(ctx context.Context) (int, error) {
return sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
}
// StatsDeleteOne is the builder for deleting a single Stats entity.
type StatsDeleteOne struct {
sd *StatsDelete
// SprayDeleteOne is the builder for deleting a single Spray entity.
type SprayDeleteOne struct {
sd *SprayDelete
}
// Exec executes the deletion query.
func (sdo *StatsDeleteOne) Exec(ctx context.Context) error {
func (sdo *SprayDeleteOne) Exec(ctx context.Context) error {
n, err := sdo.sd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{stats.Label}
return &NotFoundError{spray.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (sdo *StatsDeleteOne) ExecX(ctx context.Context) {
func (sdo *SprayDeleteOne) ExecX(ctx context.Context) {
sdo.sd.ExecX(ctx)
}

File diff suppressed because it is too large Load Diff

439
ent/spray_update.go Normal file
View File

@@ -0,0 +1,439 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/predicate"
"csgowtfd/ent/spray"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// SprayUpdate is the builder for updating Spray entities.
type SprayUpdate struct {
config
hooks []Hook
mutation *SprayMutation
}
// Where appends a list predicates to the SprayUpdate builder.
func (su *SprayUpdate) Where(ps ...predicate.Spray) *SprayUpdate {
su.mutation.Where(ps...)
return su
}
// SetWeapon sets the "weapon" field.
func (su *SprayUpdate) SetWeapon(i int) *SprayUpdate {
su.mutation.ResetWeapon()
su.mutation.SetWeapon(i)
return su
}
// AddWeapon adds i to the "weapon" field.
func (su *SprayUpdate) AddWeapon(i int) *SprayUpdate {
su.mutation.AddWeapon(i)
return su
}
// SetSpray sets the "spray" field.
func (su *SprayUpdate) SetSpray(b []byte) *SprayUpdate {
su.mutation.SetSpray(b)
return su
}
// SetMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID.
func (su *SprayUpdate) SetMatchPlayersID(id int) *SprayUpdate {
su.mutation.SetMatchPlayersID(id)
return su
}
// SetNillableMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID if the given value is not nil.
func (su *SprayUpdate) SetNillableMatchPlayersID(id *int) *SprayUpdate {
if id != nil {
su = su.SetMatchPlayersID(*id)
}
return su
}
// SetMatchPlayers sets the "match_players" edge to the MatchPlayer entity.
func (su *SprayUpdate) SetMatchPlayers(m *MatchPlayer) *SprayUpdate {
return su.SetMatchPlayersID(m.ID)
}
// Mutation returns the SprayMutation object of the builder.
func (su *SprayUpdate) Mutation() *SprayMutation {
return su.mutation
}
// ClearMatchPlayers clears the "match_players" edge to the MatchPlayer entity.
func (su *SprayUpdate) ClearMatchPlayers() *SprayUpdate {
su.mutation.ClearMatchPlayers()
return su
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (su *SprayUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(su.hooks) == 0 {
affected, err = su.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)
}
su.mutation = mutation
affected, err = su.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(su.hooks) - 1; i >= 0; i-- {
if su.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = su.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, su.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (su *SprayUpdate) SaveX(ctx context.Context) int {
affected, err := su.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (su *SprayUpdate) Exec(ctx context.Context) error {
_, err := su.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (su *SprayUpdate) ExecX(ctx context.Context) {
if err := su.Exec(ctx); err != nil {
panic(err)
}
}
func (su *SprayUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: spray.Table,
Columns: spray.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: spray.FieldID,
},
},
}
if ps := su.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := su.mutation.Weapon(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: spray.FieldWeapon,
})
}
if value, ok := su.mutation.AddedWeapon(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: spray.FieldWeapon,
})
}
if value, ok := su.mutation.Spray(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeBytes,
Value: value,
Column: spray.FieldSpray,
})
}
if su.mutation.MatchPlayersCleared() {
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,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := su.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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{spray.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return 0, err
}
return n, nil
}
// SprayUpdateOne is the builder for updating a single Spray entity.
type SprayUpdateOne struct {
config
fields []string
hooks []Hook
mutation *SprayMutation
}
// SetWeapon sets the "weapon" field.
func (suo *SprayUpdateOne) SetWeapon(i int) *SprayUpdateOne {
suo.mutation.ResetWeapon()
suo.mutation.SetWeapon(i)
return suo
}
// AddWeapon adds i to the "weapon" field.
func (suo *SprayUpdateOne) AddWeapon(i int) *SprayUpdateOne {
suo.mutation.AddWeapon(i)
return suo
}
// SetSpray sets the "spray" field.
func (suo *SprayUpdateOne) SetSpray(b []byte) *SprayUpdateOne {
suo.mutation.SetSpray(b)
return suo
}
// SetMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID.
func (suo *SprayUpdateOne) SetMatchPlayersID(id int) *SprayUpdateOne {
suo.mutation.SetMatchPlayersID(id)
return suo
}
// SetNillableMatchPlayersID sets the "match_players" edge to the MatchPlayer entity by ID if the given value is not nil.
func (suo *SprayUpdateOne) SetNillableMatchPlayersID(id *int) *SprayUpdateOne {
if id != nil {
suo = suo.SetMatchPlayersID(*id)
}
return suo
}
// SetMatchPlayers sets the "match_players" edge to the MatchPlayer entity.
func (suo *SprayUpdateOne) SetMatchPlayers(m *MatchPlayer) *SprayUpdateOne {
return suo.SetMatchPlayersID(m.ID)
}
// Mutation returns the SprayMutation object of the builder.
func (suo *SprayUpdateOne) Mutation() *SprayMutation {
return suo.mutation
}
// ClearMatchPlayers clears the "match_players" edge to the MatchPlayer entity.
func (suo *SprayUpdateOne) ClearMatchPlayers() *SprayUpdateOne {
suo.mutation.ClearMatchPlayers()
return suo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (suo *SprayUpdateOne) Select(field string, fields ...string) *SprayUpdateOne {
suo.fields = append([]string{field}, fields...)
return suo
}
// Save executes the query and returns the updated Spray entity.
func (suo *SprayUpdateOne) Save(ctx context.Context) (*Spray, error) {
var (
err error
node *Spray
)
if len(suo.hooks) == 0 {
node, err = suo.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)
}
suo.mutation = mutation
node, err = suo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(suo.hooks) - 1; i >= 0; i-- {
if suo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = suo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, suo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (suo *SprayUpdateOne) SaveX(ctx context.Context) *Spray {
node, err := suo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (suo *SprayUpdateOne) Exec(ctx context.Context) error {
_, err := suo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (suo *SprayUpdateOne) ExecX(ctx context.Context) {
if err := suo.Exec(ctx); err != nil {
panic(err)
}
}
func (suo *SprayUpdateOne) sqlSave(ctx context.Context) (_node *Spray, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: spray.Table,
Columns: spray.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: spray.FieldID,
},
},
}
id, ok := suo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Spray.ID for update")}
}
_spec.Node.ID.Value = id
if fields := suo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, spray.FieldID)
for _, f := range fields {
if !spray.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != spray.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := suo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := suo.mutation.Weapon(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: spray.FieldWeapon,
})
}
if value, ok := suo.mutation.AddedWeapon(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: spray.FieldWeapon,
})
}
if value, ok := suo.mutation.Spray(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeBytes,
Value: value,
Column: spray.FieldSpray,
})
}
if suo.mutation.MatchPlayersCleared() {
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,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := suo.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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Spray{config: suo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{spray.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}
return _node, nil
}

View File

@@ -1,989 +0,0 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/match"
"csgowtfd/ent/player"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"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(u uint) *StatsCreate {
sc.mutation.SetMvp(u)
return sc
}
// SetScore sets the "score" field.
func (sc *StatsCreate) SetScore(i int) *StatsCreate {
sc.mutation.SetScore(i)
return sc
}
// SetRankNew sets the "rank_new" field.
func (sc *StatsCreate) SetRankNew(i int) *StatsCreate {
sc.mutation.SetRankNew(i)
return sc
}
// SetNillableRankNew sets the "rank_new" field if the given value is not nil.
func (sc *StatsCreate) SetNillableRankNew(i *int) *StatsCreate {
if i != nil {
sc.SetRankNew(*i)
}
return sc
}
// SetRankOld sets the "rank_old" field.
func (sc *StatsCreate) SetRankOld(i int) *StatsCreate {
sc.mutation.SetRankOld(i)
return sc
}
// SetNillableRankOld sets the "rank_old" field if the given value is not nil.
func (sc *StatsCreate) SetNillableRankOld(i *int) *StatsCreate {
if i != nil {
sc.SetRankOld(*i)
}
return sc
}
// SetMk2 sets the "mk_2" field.
func (sc *StatsCreate) SetMk2(u uint) *StatsCreate {
sc.mutation.SetMk2(u)
return sc
}
// SetNillableMk2 sets the "mk_2" field if the given value is not nil.
func (sc *StatsCreate) SetNillableMk2(u *uint) *StatsCreate {
if u != nil {
sc.SetMk2(*u)
}
return sc
}
// SetMk3 sets the "mk_3" field.
func (sc *StatsCreate) SetMk3(u uint) *StatsCreate {
sc.mutation.SetMk3(u)
return sc
}
// SetNillableMk3 sets the "mk_3" field if the given value is not nil.
func (sc *StatsCreate) SetNillableMk3(u *uint) *StatsCreate {
if u != nil {
sc.SetMk3(*u)
}
return sc
}
// SetMk4 sets the "mk_4" field.
func (sc *StatsCreate) SetMk4(u uint) *StatsCreate {
sc.mutation.SetMk4(u)
return sc
}
// SetNillableMk4 sets the "mk_4" field if the given value is not nil.
func (sc *StatsCreate) SetNillableMk4(u *uint) *StatsCreate {
if u != nil {
sc.SetMk4(*u)
}
return sc
}
// SetMk5 sets the "mk_5" field.
func (sc *StatsCreate) SetMk5(u uint) *StatsCreate {
sc.mutation.SetMk5(u)
return sc
}
// SetNillableMk5 sets the "mk_5" field if the given value is not nil.
func (sc *StatsCreate) SetNillableMk5(u *uint) *StatsCreate {
if u != nil {
sc.SetMk5(*u)
}
return sc
}
// SetDmgEnemy sets the "dmg_enemy" field.
func (sc *StatsCreate) SetDmgEnemy(u uint) *StatsCreate {
sc.mutation.SetDmgEnemy(u)
return sc
}
// SetNillableDmgEnemy sets the "dmg_enemy" field if the given value is not nil.
func (sc *StatsCreate) SetNillableDmgEnemy(u *uint) *StatsCreate {
if u != nil {
sc.SetDmgEnemy(*u)
}
return sc
}
// SetDmgTeam sets the "dmg_team" field.
func (sc *StatsCreate) SetDmgTeam(u uint) *StatsCreate {
sc.mutation.SetDmgTeam(u)
return sc
}
// SetNillableDmgTeam sets the "dmg_team" field if the given value is not nil.
func (sc *StatsCreate) SetNillableDmgTeam(u *uint) *StatsCreate {
if u != nil {
sc.SetDmgTeam(*u)
}
return sc
}
// SetUdHe sets the "ud_he" field.
func (sc *StatsCreate) SetUdHe(u uint) *StatsCreate {
sc.mutation.SetUdHe(u)
return sc
}
// SetNillableUdHe sets the "ud_he" field if the given value is not nil.
func (sc *StatsCreate) SetNillableUdHe(u *uint) *StatsCreate {
if u != nil {
sc.SetUdHe(*u)
}
return sc
}
// SetUdFlames sets the "ud_flames" field.
func (sc *StatsCreate) SetUdFlames(u uint) *StatsCreate {
sc.mutation.SetUdFlames(u)
return sc
}
// SetNillableUdFlames sets the "ud_flames" field if the given value is not nil.
func (sc *StatsCreate) SetNillableUdFlames(u *uint) *StatsCreate {
if u != nil {
sc.SetUdFlames(*u)
}
return sc
}
// SetUdFlash sets the "ud_flash" field.
func (sc *StatsCreate) SetUdFlash(u uint) *StatsCreate {
sc.mutation.SetUdFlash(u)
return sc
}
// SetNillableUdFlash sets the "ud_flash" field if the given value is not nil.
func (sc *StatsCreate) SetNillableUdFlash(u *uint) *StatsCreate {
if u != nil {
sc.SetUdFlash(*u)
}
return sc
}
// SetUdDecoy sets the "ud_decoy" field.
func (sc *StatsCreate) SetUdDecoy(u uint) *StatsCreate {
sc.mutation.SetUdDecoy(u)
return sc
}
// SetNillableUdDecoy sets the "ud_decoy" field if the given value is not nil.
func (sc *StatsCreate) SetNillableUdDecoy(u *uint) *StatsCreate {
if u != nil {
sc.SetUdDecoy(*u)
}
return sc
}
// SetUdSmoke sets the "ud_smoke" field.
func (sc *StatsCreate) SetUdSmoke(u uint) *StatsCreate {
sc.mutation.SetUdSmoke(u)
return sc
}
// SetNillableUdSmoke sets the "ud_smoke" field if the given value is not nil.
func (sc *StatsCreate) SetNillableUdSmoke(u *uint) *StatsCreate {
if u != nil {
sc.SetUdSmoke(*u)
}
return sc
}
// SetCrosshair sets the "crosshair" field.
func (sc *StatsCreate) SetCrosshair(s string) *StatsCreate {
sc.mutation.SetCrosshair(s)
return sc
}
// SetNillableCrosshair sets the "crosshair" field if the given value is not nil.
func (sc *StatsCreate) SetNillableCrosshair(s *string) *StatsCreate {
if s != nil {
sc.SetCrosshair(*s)
}
return sc
}
// SetColor sets the "color" field.
func (sc *StatsCreate) SetColor(s stats.Color) *StatsCreate {
sc.mutation.SetColor(s)
return sc
}
// SetNillableColor sets the "color" field if the given value is not nil.
func (sc *StatsCreate) SetNillableColor(s *stats.Color) *StatsCreate {
if s != nil {
sc.SetColor(*s)
}
return sc
}
// SetKast sets the "kast" field.
func (sc *StatsCreate) SetKast(i int) *StatsCreate {
sc.mutation.SetKast(i)
return sc
}
// SetNillableKast sets the "kast" field if the given value is not nil.
func (sc *StatsCreate) SetNillableKast(i *int) *StatsCreate {
if i != nil {
sc.SetKast(*i)
}
return sc
}
// SetFlashDurationSelf sets the "flash_duration_self" field.
func (sc *StatsCreate) SetFlashDurationSelf(f float32) *StatsCreate {
sc.mutation.SetFlashDurationSelf(f)
return sc
}
// SetNillableFlashDurationSelf sets the "flash_duration_self" field if the given value is not nil.
func (sc *StatsCreate) SetNillableFlashDurationSelf(f *float32) *StatsCreate {
if f != nil {
sc.SetFlashDurationSelf(*f)
}
return sc
}
// SetFlashDurationTeam sets the "flash_duration_team" field.
func (sc *StatsCreate) SetFlashDurationTeam(f float32) *StatsCreate {
sc.mutation.SetFlashDurationTeam(f)
return sc
}
// SetNillableFlashDurationTeam sets the "flash_duration_team" field if the given value is not nil.
func (sc *StatsCreate) SetNillableFlashDurationTeam(f *float32) *StatsCreate {
if f != nil {
sc.SetFlashDurationTeam(*f)
}
return sc
}
// SetFlashDurationEnemy sets the "flash_duration_enemy" field.
func (sc *StatsCreate) SetFlashDurationEnemy(f float32) *StatsCreate {
sc.mutation.SetFlashDurationEnemy(f)
return sc
}
// SetNillableFlashDurationEnemy sets the "flash_duration_enemy" field if the given value is not nil.
func (sc *StatsCreate) SetNillableFlashDurationEnemy(f *float32) *StatsCreate {
if f != nil {
sc.SetFlashDurationEnemy(*f)
}
return sc
}
// SetFlashTotalSelf sets the "flash_total_self" field.
func (sc *StatsCreate) SetFlashTotalSelf(u uint) *StatsCreate {
sc.mutation.SetFlashTotalSelf(u)
return sc
}
// SetNillableFlashTotalSelf sets the "flash_total_self" field if the given value is not nil.
func (sc *StatsCreate) SetNillableFlashTotalSelf(u *uint) *StatsCreate {
if u != nil {
sc.SetFlashTotalSelf(*u)
}
return sc
}
// SetFlashTotalTeam sets the "flash_total_team" field.
func (sc *StatsCreate) SetFlashTotalTeam(u uint) *StatsCreate {
sc.mutation.SetFlashTotalTeam(u)
return sc
}
// SetNillableFlashTotalTeam sets the "flash_total_team" field if the given value is not nil.
func (sc *StatsCreate) SetNillableFlashTotalTeam(u *uint) *StatsCreate {
if u != nil {
sc.SetFlashTotalTeam(*u)
}
return sc
}
// SetFlashTotalEnemy sets the "flash_total_enemy" field.
func (sc *StatsCreate) SetFlashTotalEnemy(u uint) *StatsCreate {
sc.mutation.SetFlashTotalEnemy(u)
return sc
}
// SetNillableFlashTotalEnemy sets the "flash_total_enemy" field if the given value is not nil.
func (sc *StatsCreate) SetNillableFlashTotalEnemy(u *uint) *StatsCreate {
if u != nil {
sc.SetFlashTotalEnemy(*u)
}
return sc
}
// SetMatchStats sets the "match_stats" field.
func (sc *StatsCreate) SetMatchStats(u uint64) *StatsCreate {
sc.mutation.SetMatchStats(u)
return sc
}
// SetNillableMatchStats sets the "match_stats" field if the given value is not nil.
func (sc *StatsCreate) SetNillableMatchStats(u *uint64) *StatsCreate {
if u != nil {
sc.SetMatchStats(*u)
}
return sc
}
// SetPlayerStats sets the "player_stats" field.
func (sc *StatsCreate) SetPlayerStats(u uint64) *StatsCreate {
sc.mutation.SetPlayerStats(u)
return sc
}
// SetNillablePlayerStats sets the "player_stats" field if the given value is not nil.
func (sc *StatsCreate) SetNillablePlayerStats(u *uint64) *StatsCreate {
if u != nil {
sc.SetPlayerStats(*u)
}
return sc
}
// SetMatchesID sets the "matches" edge to the Match entity by ID.
func (sc *StatsCreate) SetMatchesID(id uint64) *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 *uint64) *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 uint64) *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 *uint64) *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)
}
// AddWeaponStatIDs adds the "weapon_stats" edge to the WeaponStats entity by IDs.
func (sc *StatsCreate) AddWeaponStatIDs(ids ...int) *StatsCreate {
sc.mutation.AddWeaponStatIDs(ids...)
return sc
}
// AddWeaponStats adds the "weapon_stats" edges to the WeaponStats entity.
func (sc *StatsCreate) AddWeaponStats(w ...*WeaponStats) *StatsCreate {
ids := make([]int, len(w))
for i := range w {
ids[i] = w[i].ID
}
return sc.AddWeaponStatIDs(ids...)
}
// AddRoundStatIDs adds the "round_stats" edge to the RoundStats entity by IDs.
func (sc *StatsCreate) AddRoundStatIDs(ids ...int) *StatsCreate {
sc.mutation.AddRoundStatIDs(ids...)
return sc
}
// AddRoundStats adds the "round_stats" edges to the RoundStats entity.
func (sc *StatsCreate) AddRoundStats(r ...*RoundStats) *StatsCreate {
ids := make([]int, len(r))
for i := range r {
ids[i] = r[i].ID
}
return sc.AddRoundStatIDs(ids...)
}
// 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"`)}
}
if v, ok := sc.mutation.Color(); ok {
if err := stats.ColorValidator(v); err != nil {
return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "color": %w`, err)}
}
}
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.TypeUint,
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.RankNew(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: stats.FieldRankNew,
})
_node.RankNew = value
}
if value, ok := sc.mutation.RankOld(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: stats.FieldRankOld,
})
_node.RankOld = value
}
if value, ok := sc.mutation.Mk2(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldMk2,
})
_node.Mk2 = value
}
if value, ok := sc.mutation.Mk3(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldMk3,
})
_node.Mk3 = value
}
if value, ok := sc.mutation.Mk4(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldMk4,
})
_node.Mk4 = value
}
if value, ok := sc.mutation.Mk5(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldMk5,
})
_node.Mk5 = value
}
if value, ok := sc.mutation.DmgEnemy(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldDmgEnemy,
})
_node.DmgEnemy = value
}
if value, ok := sc.mutation.DmgTeam(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldDmgTeam,
})
_node.DmgTeam = value
}
if value, ok := sc.mutation.UdHe(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldUdHe,
})
_node.UdHe = value
}
if value, ok := sc.mutation.UdFlames(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldUdFlames,
})
_node.UdFlames = value
}
if value, ok := sc.mutation.UdFlash(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldUdFlash,
})
_node.UdFlash = value
}
if value, ok := sc.mutation.UdDecoy(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldUdDecoy,
})
_node.UdDecoy = value
}
if value, ok := sc.mutation.UdSmoke(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldUdSmoke,
})
_node.UdSmoke = value
}
if value, ok := sc.mutation.Crosshair(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: stats.FieldCrosshair,
})
_node.Crosshair = value
}
if value, ok := sc.mutation.Color(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeEnum,
Value: value,
Column: stats.FieldColor,
})
_node.Color = value
}
if value, ok := sc.mutation.Kast(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: stats.FieldKast,
})
_node.Kast = value
}
if value, ok := sc.mutation.FlashDurationSelf(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeFloat32,
Value: value,
Column: stats.FieldFlashDurationSelf,
})
_node.FlashDurationSelf = value
}
if value, ok := sc.mutation.FlashDurationTeam(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeFloat32,
Value: value,
Column: stats.FieldFlashDurationTeam,
})
_node.FlashDurationTeam = value
}
if value, ok := sc.mutation.FlashDurationEnemy(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeFloat32,
Value: value,
Column: stats.FieldFlashDurationEnemy,
})
_node.FlashDurationEnemy = value
}
if value, ok := sc.mutation.FlashTotalSelf(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldFlashTotalSelf,
})
_node.FlashTotalSelf = value
}
if value, ok := sc.mutation.FlashTotalTeam(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldFlashTotalTeam,
})
_node.FlashTotalTeam = value
}
if value, ok := sc.mutation.FlashTotalEnemy(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: stats.FieldFlashTotalEnemy,
})
_node.FlashTotalEnemy = 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.TypeUint64,
Column: match.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.MatchStats = 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.TypeUint64,
Column: player.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.PlayerStats = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := sc.mutation.WeaponStatsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: stats.WeaponStatsTable,
Columns: []string{stats.WeaponStatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weaponstats.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := sc.mutation.RoundStatsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: stats.RoundStatsTable,
Columns: []string{stats.RoundStatsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: roundstats.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_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)
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -14,14 +14,16 @@ type Tx struct {
config
// Match is the client for interacting with the Match builders.
Match *MatchClient
// MatchPlayer is the client for interacting with the MatchPlayer builders.
MatchPlayer *MatchPlayerClient
// Player is the client for interacting with the Player builders.
Player *PlayerClient
// RoundStats is the client for interacting with the RoundStats builders.
RoundStats *RoundStatsClient
// Stats is the client for interacting with the Stats builders.
Stats *StatsClient
// WeaponStats is the client for interacting with the WeaponStats builders.
WeaponStats *WeaponStatsClient
// Spray is the client for interacting with the Spray builders.
Spray *SprayClient
// Weapon is the client for interacting with the Weapon builders.
Weapon *WeaponClient
// lazily loaded.
client *Client
@@ -158,10 +160,11 @@ func (tx *Tx) Client() *Client {
func (tx *Tx) init() {
tx.Match = NewMatchClient(tx.config)
tx.MatchPlayer = NewMatchPlayerClient(tx.config)
tx.Player = NewPlayerClient(tx.config)
tx.RoundStats = NewRoundStatsClient(tx.config)
tx.Stats = NewStatsClient(tx.config)
tx.WeaponStats = NewWeaponStatsClient(tx.config)
tx.Spray = NewSprayClient(tx.config)
tx.Weapon = NewWeaponClient(tx.config)
}
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.

View File

@@ -3,16 +3,16 @@
package ent
import (
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/weapon"
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
)
// WeaponStats is the model entity for the WeaponStats schema.
type WeaponStats struct {
// Weapon is the model entity for the Weapon schema.
type Weapon struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
@@ -25,15 +25,15 @@ type WeaponStats struct {
// HitGroup holds the value of the "hit_group" field.
HitGroup int `json:"hit_group,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the WeaponStatsQuery when eager-loading is set.
Edges WeaponStatsEdges `json:"edges"`
stats_weapon_stats *int
// The values are being populated by the WeaponQuery when eager-loading is set.
Edges WeaponEdges `json:"edges"`
match_player_weapon_stats *int
}
// WeaponStatsEdges holds the relations/edges for other nodes in the graph.
type WeaponStatsEdges struct {
// WeaponEdges holds the relations/edges for other nodes in the graph.
type WeaponEdges struct {
// Stat holds the value of the stat edge.
Stat *Stats `json:"stat,omitempty"`
Stat *MatchPlayer `json:"stat,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
@@ -41,12 +41,12 @@ type WeaponStatsEdges struct {
// StatOrErr returns the Stat value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WeaponStatsEdges) StatOrErr() (*Stats, error) {
func (e WeaponEdges) StatOrErr() (*MatchPlayer, error) {
if e.loadedTypes[0] {
if e.Stat == nil {
// The edge stat was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: stats.Label}
return nil, &NotFoundError{label: matchplayer.Label}
}
return e.Stat, nil
}
@@ -54,116 +54,116 @@ func (e WeaponStatsEdges) StatOrErr() (*Stats, error) {
}
// scanValues returns the types for scanning values from sql.Rows.
func (*WeaponStats) scanValues(columns []string) ([]interface{}, error) {
func (*Weapon) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case weaponstats.FieldID, weaponstats.FieldVictim, weaponstats.FieldDmg, weaponstats.FieldEqType, weaponstats.FieldHitGroup:
case weapon.FieldID, weapon.FieldVictim, weapon.FieldDmg, weapon.FieldEqType, weapon.FieldHitGroup:
values[i] = new(sql.NullInt64)
case weaponstats.ForeignKeys[0]: // stats_weapon_stats
case weapon.ForeignKeys[0]: // match_player_weapon_stats
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type WeaponStats", columns[i])
return nil, fmt.Errorf("unexpected column %q for type Weapon", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the WeaponStats fields.
func (ws *WeaponStats) assignValues(columns []string, values []interface{}) error {
// to the Weapon fields.
func (w *Weapon) assignValues(columns []string, values []interface{}) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case weaponstats.FieldID:
case weapon.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
ws.ID = int(value.Int64)
case weaponstats.FieldVictim:
w.ID = int(value.Int64)
case weapon.FieldVictim:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field victim", values[i])
} else if value.Valid {
ws.Victim = uint64(value.Int64)
w.Victim = uint64(value.Int64)
}
case weaponstats.FieldDmg:
case weapon.FieldDmg:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field dmg", values[i])
} else if value.Valid {
ws.Dmg = uint(value.Int64)
w.Dmg = uint(value.Int64)
}
case weaponstats.FieldEqType:
case weapon.FieldEqType:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field eq_type", values[i])
} else if value.Valid {
ws.EqType = int(value.Int64)
w.EqType = int(value.Int64)
}
case weaponstats.FieldHitGroup:
case weapon.FieldHitGroup:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field hit_group", values[i])
} else if value.Valid {
ws.HitGroup = int(value.Int64)
w.HitGroup = int(value.Int64)
}
case weaponstats.ForeignKeys[0]:
case weapon.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field stats_weapon_stats", value)
return fmt.Errorf("unexpected type %T for edge-field match_player_weapon_stats", value)
} else if value.Valid {
ws.stats_weapon_stats = new(int)
*ws.stats_weapon_stats = int(value.Int64)
w.match_player_weapon_stats = new(int)
*w.match_player_weapon_stats = int(value.Int64)
}
}
}
return nil
}
// QueryStat queries the "stat" edge of the WeaponStats entity.
func (ws *WeaponStats) QueryStat() *StatsQuery {
return (&WeaponStatsClient{config: ws.config}).QueryStat(ws)
// QueryStat queries the "stat" edge of the Weapon entity.
func (w *Weapon) QueryStat() *MatchPlayerQuery {
return (&WeaponClient{config: w.config}).QueryStat(w)
}
// Update returns a builder for updating this WeaponStats.
// Note that you need to call WeaponStats.Unwrap() before calling this method if this WeaponStats
// Update returns a builder for updating this Weapon.
// Note that you need to call Weapon.Unwrap() before calling this method if this Weapon
// was returned from a transaction, and the transaction was committed or rolled back.
func (ws *WeaponStats) Update() *WeaponStatsUpdateOne {
return (&WeaponStatsClient{config: ws.config}).UpdateOne(ws)
func (w *Weapon) Update() *WeaponUpdateOne {
return (&WeaponClient{config: w.config}).UpdateOne(w)
}
// Unwrap unwraps the WeaponStats entity that was returned from a transaction after it was closed,
// Unwrap unwraps the Weapon entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (ws *WeaponStats) Unwrap() *WeaponStats {
tx, ok := ws.config.driver.(*txDriver)
func (w *Weapon) Unwrap() *Weapon {
tx, ok := w.config.driver.(*txDriver)
if !ok {
panic("ent: WeaponStats is not a transactional entity")
panic("ent: Weapon is not a transactional entity")
}
ws.config.driver = tx.drv
return ws
w.config.driver = tx.drv
return w
}
// String implements the fmt.Stringer.
func (ws *WeaponStats) String() string {
func (w *Weapon) String() string {
var builder strings.Builder
builder.WriteString("WeaponStats(")
builder.WriteString(fmt.Sprintf("id=%v", ws.ID))
builder.WriteString("Weapon(")
builder.WriteString(fmt.Sprintf("id=%v", w.ID))
builder.WriteString(", victim=")
builder.WriteString(fmt.Sprintf("%v", ws.Victim))
builder.WriteString(fmt.Sprintf("%v", w.Victim))
builder.WriteString(", dmg=")
builder.WriteString(fmt.Sprintf("%v", ws.Dmg))
builder.WriteString(fmt.Sprintf("%v", w.Dmg))
builder.WriteString(", eq_type=")
builder.WriteString(fmt.Sprintf("%v", ws.EqType))
builder.WriteString(fmt.Sprintf("%v", w.EqType))
builder.WriteString(", hit_group=")
builder.WriteString(fmt.Sprintf("%v", ws.HitGroup))
builder.WriteString(fmt.Sprintf("%v", w.HitGroup))
builder.WriteByte(')')
return builder.String()
}
// WeaponStatsSlice is a parsable slice of WeaponStats.
type WeaponStatsSlice []*WeaponStats
// Weapons is a parsable slice of Weapon.
type Weapons []*Weapon
func (ws WeaponStatsSlice) config(cfg config) {
for _i := range ws {
ws[_i].config = cfg
func (w Weapons) config(cfg config) {
for _i := range w {
w[_i].config = cfg
}
}

View File

@@ -1,10 +1,10 @@
// Code generated by entc, DO NOT EDIT.
package weaponstats
package weapon
const (
// Label holds the string label denoting the weaponstats type in the database.
Label = "weapon_stats"
// Label holds the string label denoting the weapon type in the database.
Label = "weapon"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldVictim holds the string denoting the victim field in the database.
@@ -17,18 +17,18 @@ const (
FieldHitGroup = "hit_group"
// EdgeStat holds the string denoting the stat edge name in mutations.
EdgeStat = "stat"
// Table holds the table name of the weaponstats in the database.
Table = "weapon_stats"
// Table holds the table name of the weapon in the database.
Table = "weapons"
// StatTable is the table that holds the stat relation/edge.
StatTable = "weapon_stats"
// StatInverseTable is the table name for the Stats entity.
// It exists in this package in order to avoid circular dependency with the "stats" package.
StatInverseTable = "stats"
StatTable = "weapons"
// StatInverseTable is the table name for the MatchPlayer entity.
// It exists in this package in order to avoid circular dependency with the "matchplayer" package.
StatInverseTable = "match_players"
// StatColumn is the table column denoting the stat relation/edge.
StatColumn = "stats_weapon_stats"
StatColumn = "match_player_weapon_stats"
)
// Columns holds all SQL columns for weaponstats fields.
// Columns holds all SQL columns for weapon fields.
var Columns = []string{
FieldID,
FieldVictim,
@@ -37,10 +37,10 @@ var Columns = []string{
FieldHitGroup,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "weapon_stats"
// ForeignKeys holds the SQL foreign-keys that are owned by the "weapons"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"stats_weapon_stats",
"match_player_weapon_stats",
}
// ValidColumn reports if the column name is valid (part of the table columns).

View File

@@ -1,6 +1,6 @@
// Code generated by entc, DO NOT EDIT.
package weaponstats
package weapon
import (
"csgowtfd/ent/predicate"
@@ -10,29 +10,29 @@ import (
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func ID(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDEQ(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDNEQ(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
})
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDIn(ids ...int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
@@ -48,8 +48,8 @@ func IDIn(ids ...int) predicate.WeaponStats {
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDNotIn(ids ...int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
@@ -65,82 +65,82 @@ func IDNotIn(ids ...int) predicate.WeaponStats {
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDGT(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldID), id))
})
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDGTE(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldID), id))
})
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDLT(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldID), id))
})
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func IDLTE(id int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
})
}
// Victim applies equality check predicate on the "victim" field. It's identical to VictimEQ.
func Victim(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func Victim(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldVictim), v))
})
}
// Dmg applies equality check predicate on the "dmg" field. It's identical to DmgEQ.
func Dmg(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func Dmg(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldDmg), v))
})
}
// EqType applies equality check predicate on the "eq_type" field. It's identical to EqTypeEQ.
func EqType(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqType(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldEqType), v))
})
}
// HitGroup applies equality check predicate on the "hit_group" field. It's identical to HitGroupEQ.
func HitGroup(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroup(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldHitGroup), v))
})
}
// VictimEQ applies the EQ predicate on the "victim" field.
func VictimEQ(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func VictimEQ(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldVictim), v))
})
}
// VictimNEQ applies the NEQ predicate on the "victim" field.
func VictimNEQ(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func VictimNEQ(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldVictim), v))
})
}
// VictimIn applies the In predicate on the "victim" field.
func VictimIn(vs ...uint64) predicate.WeaponStats {
func VictimIn(vs ...uint64) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -152,12 +152,12 @@ func VictimIn(vs ...uint64) predicate.WeaponStats {
}
// VictimNotIn applies the NotIn predicate on the "victim" field.
func VictimNotIn(vs ...uint64) predicate.WeaponStats {
func VictimNotIn(vs ...uint64) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -169,54 +169,54 @@ func VictimNotIn(vs ...uint64) predicate.WeaponStats {
}
// VictimGT applies the GT predicate on the "victim" field.
func VictimGT(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func VictimGT(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldVictim), v))
})
}
// VictimGTE applies the GTE predicate on the "victim" field.
func VictimGTE(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func VictimGTE(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldVictim), v))
})
}
// VictimLT applies the LT predicate on the "victim" field.
func VictimLT(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func VictimLT(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldVictim), v))
})
}
// VictimLTE applies the LTE predicate on the "victim" field.
func VictimLTE(v uint64) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func VictimLTE(v uint64) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldVictim), v))
})
}
// DmgEQ applies the EQ predicate on the "dmg" field.
func DmgEQ(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func DmgEQ(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldDmg), v))
})
}
// DmgNEQ applies the NEQ predicate on the "dmg" field.
func DmgNEQ(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func DmgNEQ(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldDmg), v))
})
}
// DmgIn applies the In predicate on the "dmg" field.
func DmgIn(vs ...uint) predicate.WeaponStats {
func DmgIn(vs ...uint) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -228,12 +228,12 @@ func DmgIn(vs ...uint) predicate.WeaponStats {
}
// DmgNotIn applies the NotIn predicate on the "dmg" field.
func DmgNotIn(vs ...uint) predicate.WeaponStats {
func DmgNotIn(vs ...uint) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -245,54 +245,54 @@ func DmgNotIn(vs ...uint) predicate.WeaponStats {
}
// DmgGT applies the GT predicate on the "dmg" field.
func DmgGT(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func DmgGT(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldDmg), v))
})
}
// DmgGTE applies the GTE predicate on the "dmg" field.
func DmgGTE(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func DmgGTE(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldDmg), v))
})
}
// DmgLT applies the LT predicate on the "dmg" field.
func DmgLT(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func DmgLT(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldDmg), v))
})
}
// DmgLTE applies the LTE predicate on the "dmg" field.
func DmgLTE(v uint) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func DmgLTE(v uint) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldDmg), v))
})
}
// EqTypeEQ applies the EQ predicate on the "eq_type" field.
func EqTypeEQ(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqTypeEQ(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldEqType), v))
})
}
// EqTypeNEQ applies the NEQ predicate on the "eq_type" field.
func EqTypeNEQ(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqTypeNEQ(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldEqType), v))
})
}
// EqTypeIn applies the In predicate on the "eq_type" field.
func EqTypeIn(vs ...int) predicate.WeaponStats {
func EqTypeIn(vs ...int) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -304,12 +304,12 @@ func EqTypeIn(vs ...int) predicate.WeaponStats {
}
// EqTypeNotIn applies the NotIn predicate on the "eq_type" field.
func EqTypeNotIn(vs ...int) predicate.WeaponStats {
func EqTypeNotIn(vs ...int) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -321,54 +321,54 @@ func EqTypeNotIn(vs ...int) predicate.WeaponStats {
}
// EqTypeGT applies the GT predicate on the "eq_type" field.
func EqTypeGT(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqTypeGT(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldEqType), v))
})
}
// EqTypeGTE applies the GTE predicate on the "eq_type" field.
func EqTypeGTE(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqTypeGTE(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldEqType), v))
})
}
// EqTypeLT applies the LT predicate on the "eq_type" field.
func EqTypeLT(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqTypeLT(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldEqType), v))
})
}
// EqTypeLTE applies the LTE predicate on the "eq_type" field.
func EqTypeLTE(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func EqTypeLTE(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldEqType), v))
})
}
// HitGroupEQ applies the EQ predicate on the "hit_group" field.
func HitGroupEQ(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroupEQ(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldHitGroup), v))
})
}
// HitGroupNEQ applies the NEQ predicate on the "hit_group" field.
func HitGroupNEQ(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroupNEQ(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldHitGroup), v))
})
}
// HitGroupIn applies the In predicate on the "hit_group" field.
func HitGroupIn(vs ...int) predicate.WeaponStats {
func HitGroupIn(vs ...int) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -380,12 +380,12 @@ func HitGroupIn(vs ...int) predicate.WeaponStats {
}
// HitGroupNotIn applies the NotIn predicate on the "hit_group" field.
func HitGroupNotIn(vs ...int) predicate.WeaponStats {
func HitGroupNotIn(vs ...int) predicate.Weapon {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.WeaponStats(func(s *sql.Selector) {
return predicate.Weapon(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
@@ -397,36 +397,36 @@ func HitGroupNotIn(vs ...int) predicate.WeaponStats {
}
// HitGroupGT applies the GT predicate on the "hit_group" field.
func HitGroupGT(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroupGT(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldHitGroup), v))
})
}
// HitGroupGTE applies the GTE predicate on the "hit_group" field.
func HitGroupGTE(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroupGTE(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldHitGroup), v))
})
}
// HitGroupLT applies the LT predicate on the "hit_group" field.
func HitGroupLT(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroupLT(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldHitGroup), v))
})
}
// HitGroupLTE applies the LTE predicate on the "hit_group" field.
func HitGroupLTE(v int) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HitGroupLTE(v int) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldHitGroup), v))
})
}
// HasStat applies the HasEdge predicate on the "stat" edge.
func HasStat() predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HasStat() predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(StatTable, FieldID),
@@ -437,8 +437,8 @@ func HasStat() predicate.WeaponStats {
}
// HasStatWith applies the HasEdge predicate on the "stat" edge with a given conditions (other predicates).
func HasStatWith(preds ...predicate.Stats) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func HasStatWith(preds ...predicate.MatchPlayer) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(StatInverseTable, FieldID),
@@ -453,8 +453,8 @@ func HasStatWith(preds ...predicate.Stats) predicate.WeaponStats {
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.WeaponStats) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func And(predicates ...predicate.Weapon) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
@@ -464,8 +464,8 @@ func And(predicates ...predicate.WeaponStats) predicate.WeaponStats {
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.WeaponStats) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func Or(predicates ...predicate.Weapon) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
@@ -478,8 +478,8 @@ func Or(predicates ...predicate.WeaponStats) predicate.WeaponStats {
}
// Not applies the not operator on the given predicate.
func Not(p predicate.WeaponStats) predicate.WeaponStats {
return predicate.WeaponStats(func(s *sql.Selector) {
func Not(p predicate.Weapon) predicate.Weapon {
return predicate.Weapon(func(s *sql.Selector) {
p(s.Not())
})
}

311
ent/weapon_create.go Normal file
View File

@@ -0,0 +1,311 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/weapon"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// 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)
}
if _, err := mut.Mutate(ctx, wc.mutation); err != nil {
return nil, err
}
}
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 "victim"`)}
}
if _, ok := wc.mutation.Dmg(); !ok {
return &ValidationError{Name: "dmg", err: errors.New(`ent: missing required field "dmg"`)}
}
if _, ok := wc.mutation.EqType(); !ok {
return &ValidationError{Name: "eq_type", err: errors.New(`ent: missing required field "eq_type"`)}
}
if _, ok := wc.mutation.HitGroup(); !ok {
return &ValidationError{Name: "hit_group", err: errors.New(`ent: missing required field "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{err.Error(), 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.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
_node.Victim = value
}
if value, ok := wc.mutation.Dmg(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
_node.Dmg = value
}
if value, ok := wc.mutation.EqType(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
_node.EqType = value
}
if value, ok := wc.mutation.HitGroup(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
_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{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, 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)
}
}

111
ent/weapon_delete.go Normal file
View File

@@ -0,0 +1,111 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/predicate"
"csgowtfd/ent/weapon"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// WeaponDelete is the builder for deleting a Weapon entity.
type WeaponDelete struct {
config
hooks []Hook
mutation *WeaponMutation
}
// Where appends a list predicates to the WeaponDelete builder.
func (wd *WeaponDelete) Where(ps ...predicate.Weapon) *WeaponDelete {
wd.mutation.Where(ps...)
return wd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (wd *WeaponDelete) Exec(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(wd.hooks) == 0 {
affected, err = wd.sqlExec(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)
}
wd.mutation = mutation
affected, err = wd.sqlExec(ctx)
mutation.done = true
return affected, err
})
for i := len(wd.hooks) - 1; i >= 0; i-- {
if wd.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wd.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wd.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// ExecX is like Exec, but panics if an error occurs.
func (wd *WeaponDelete) ExecX(ctx context.Context) int {
n, err := wd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (wd *WeaponDelete) sqlExec(ctx context.Context) (int, error) {
_spec := &sqlgraph.DeleteSpec{
Node: &sqlgraph.NodeSpec{
Table: weapon.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weapon.FieldID,
},
},
}
if ps := wd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return sqlgraph.DeleteNodes(ctx, wd.driver, _spec)
}
// WeaponDeleteOne is the builder for deleting a single Weapon entity.
type WeaponDeleteOne struct {
wd *WeaponDelete
}
// Exec executes the deletion query.
func (wdo *WeaponDeleteOne) Exec(ctx context.Context) error {
n, err := wdo.wd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{weapon.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (wdo *WeaponDeleteOne) ExecX(ctx context.Context) {
wdo.wd.ExecX(ctx)
}

1016
ent/weapon_query.go Normal file

File diff suppressed because it is too large Load Diff

575
ent/weapon_update.go Normal file
View File

@@ -0,0 +1,575 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/predicate"
"csgowtfd/ent/weapon"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// WeaponUpdate is the builder for updating Weapon entities.
type WeaponUpdate struct {
config
hooks []Hook
mutation *WeaponMutation
}
// Where appends a list predicates to the WeaponUpdate builder.
func (wu *WeaponUpdate) Where(ps ...predicate.Weapon) *WeaponUpdate {
wu.mutation.Where(ps...)
return wu
}
// SetVictim sets the "victim" field.
func (wu *WeaponUpdate) SetVictim(u uint64) *WeaponUpdate {
wu.mutation.ResetVictim()
wu.mutation.SetVictim(u)
return wu
}
// AddVictim adds u to the "victim" field.
func (wu *WeaponUpdate) AddVictim(u uint64) *WeaponUpdate {
wu.mutation.AddVictim(u)
return wu
}
// SetDmg sets the "dmg" field.
func (wu *WeaponUpdate) SetDmg(u uint) *WeaponUpdate {
wu.mutation.ResetDmg()
wu.mutation.SetDmg(u)
return wu
}
// AddDmg adds u to the "dmg" field.
func (wu *WeaponUpdate) AddDmg(u uint) *WeaponUpdate {
wu.mutation.AddDmg(u)
return wu
}
// SetEqType sets the "eq_type" field.
func (wu *WeaponUpdate) SetEqType(i int) *WeaponUpdate {
wu.mutation.ResetEqType()
wu.mutation.SetEqType(i)
return wu
}
// AddEqType adds i to the "eq_type" field.
func (wu *WeaponUpdate) AddEqType(i int) *WeaponUpdate {
wu.mutation.AddEqType(i)
return wu
}
// SetHitGroup sets the "hit_group" field.
func (wu *WeaponUpdate) SetHitGroup(i int) *WeaponUpdate {
wu.mutation.ResetHitGroup()
wu.mutation.SetHitGroup(i)
return wu
}
// AddHitGroup adds i to the "hit_group" field.
func (wu *WeaponUpdate) AddHitGroup(i int) *WeaponUpdate {
wu.mutation.AddHitGroup(i)
return wu
}
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
func (wu *WeaponUpdate) SetStatID(id int) *WeaponUpdate {
wu.mutation.SetStatID(id)
return wu
}
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
func (wu *WeaponUpdate) SetNillableStatID(id *int) *WeaponUpdate {
if id != nil {
wu = wu.SetStatID(*id)
}
return wu
}
// SetStat sets the "stat" edge to the MatchPlayer entity.
func (wu *WeaponUpdate) SetStat(m *MatchPlayer) *WeaponUpdate {
return wu.SetStatID(m.ID)
}
// Mutation returns the WeaponMutation object of the builder.
func (wu *WeaponUpdate) Mutation() *WeaponMutation {
return wu.mutation
}
// ClearStat clears the "stat" edge to the MatchPlayer entity.
func (wu *WeaponUpdate) ClearStat() *WeaponUpdate {
wu.mutation.ClearStat()
return wu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (wu *WeaponUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(wu.hooks) == 0 {
affected, err = wu.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)
}
wu.mutation = mutation
affected, err = wu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(wu.hooks) - 1; i >= 0; i-- {
if wu.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (wu *WeaponUpdate) SaveX(ctx context.Context) int {
affected, err := wu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (wu *WeaponUpdate) Exec(ctx context.Context) error {
_, err := wu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wu *WeaponUpdate) ExecX(ctx context.Context) {
if err := wu.Exec(ctx); err != nil {
panic(err)
}
}
func (wu *WeaponUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: weapon.Table,
Columns: weapon.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weapon.FieldID,
},
},
}
if ps := wu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := wu.mutation.Victim(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wu.mutation.AddedVictim(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wu.mutation.Dmg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wu.mutation.AddedDmg(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wu.mutation.EqType(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wu.mutation.AddedEqType(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wu.mutation.HitGroup(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
if value, ok := wu.mutation.AddedHitGroup(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
if wu.mutation.StatCleared() {
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,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := wu.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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{weapon.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return 0, err
}
return n, nil
}
// WeaponUpdateOne is the builder for updating a single Weapon entity.
type WeaponUpdateOne struct {
config
fields []string
hooks []Hook
mutation *WeaponMutation
}
// SetVictim sets the "victim" field.
func (wuo *WeaponUpdateOne) SetVictim(u uint64) *WeaponUpdateOne {
wuo.mutation.ResetVictim()
wuo.mutation.SetVictim(u)
return wuo
}
// AddVictim adds u to the "victim" field.
func (wuo *WeaponUpdateOne) AddVictim(u uint64) *WeaponUpdateOne {
wuo.mutation.AddVictim(u)
return wuo
}
// SetDmg sets the "dmg" field.
func (wuo *WeaponUpdateOne) SetDmg(u uint) *WeaponUpdateOne {
wuo.mutation.ResetDmg()
wuo.mutation.SetDmg(u)
return wuo
}
// AddDmg adds u to the "dmg" field.
func (wuo *WeaponUpdateOne) AddDmg(u uint) *WeaponUpdateOne {
wuo.mutation.AddDmg(u)
return wuo
}
// SetEqType sets the "eq_type" field.
func (wuo *WeaponUpdateOne) SetEqType(i int) *WeaponUpdateOne {
wuo.mutation.ResetEqType()
wuo.mutation.SetEqType(i)
return wuo
}
// AddEqType adds i to the "eq_type" field.
func (wuo *WeaponUpdateOne) AddEqType(i int) *WeaponUpdateOne {
wuo.mutation.AddEqType(i)
return wuo
}
// SetHitGroup sets the "hit_group" field.
func (wuo *WeaponUpdateOne) SetHitGroup(i int) *WeaponUpdateOne {
wuo.mutation.ResetHitGroup()
wuo.mutation.SetHitGroup(i)
return wuo
}
// AddHitGroup adds i to the "hit_group" field.
func (wuo *WeaponUpdateOne) AddHitGroup(i int) *WeaponUpdateOne {
wuo.mutation.AddHitGroup(i)
return wuo
}
// SetStatID sets the "stat" edge to the MatchPlayer entity by ID.
func (wuo *WeaponUpdateOne) SetStatID(id int) *WeaponUpdateOne {
wuo.mutation.SetStatID(id)
return wuo
}
// SetNillableStatID sets the "stat" edge to the MatchPlayer entity by ID if the given value is not nil.
func (wuo *WeaponUpdateOne) SetNillableStatID(id *int) *WeaponUpdateOne {
if id != nil {
wuo = wuo.SetStatID(*id)
}
return wuo
}
// SetStat sets the "stat" edge to the MatchPlayer entity.
func (wuo *WeaponUpdateOne) SetStat(m *MatchPlayer) *WeaponUpdateOne {
return wuo.SetStatID(m.ID)
}
// Mutation returns the WeaponMutation object of the builder.
func (wuo *WeaponUpdateOne) Mutation() *WeaponMutation {
return wuo.mutation
}
// ClearStat clears the "stat" edge to the MatchPlayer entity.
func (wuo *WeaponUpdateOne) ClearStat() *WeaponUpdateOne {
wuo.mutation.ClearStat()
return wuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (wuo *WeaponUpdateOne) Select(field string, fields ...string) *WeaponUpdateOne {
wuo.fields = append([]string{field}, fields...)
return wuo
}
// Save executes the query and returns the updated Weapon entity.
func (wuo *WeaponUpdateOne) Save(ctx context.Context) (*Weapon, error) {
var (
err error
node *Weapon
)
if len(wuo.hooks) == 0 {
node, err = wuo.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)
}
wuo.mutation = mutation
node, err = wuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(wuo.hooks) - 1; i >= 0; i-- {
if wuo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (wuo *WeaponUpdateOne) SaveX(ctx context.Context) *Weapon {
node, err := wuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (wuo *WeaponUpdateOne) Exec(ctx context.Context) error {
_, err := wuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wuo *WeaponUpdateOne) ExecX(ctx context.Context) {
if err := wuo.Exec(ctx); err != nil {
panic(err)
}
}
func (wuo *WeaponUpdateOne) sqlSave(ctx context.Context) (_node *Weapon, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: weapon.Table,
Columns: weapon.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weapon.FieldID,
},
},
}
id, ok := wuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Weapon.ID for update")}
}
_spec.Node.ID.Value = id
if fields := wuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, weapon.FieldID)
for _, f := range fields {
if !weapon.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != weapon.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := wuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := wuo.mutation.Victim(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wuo.mutation.AddedVictim(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weapon.FieldVictim,
})
}
if value, ok := wuo.mutation.Dmg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wuo.mutation.AddedDmg(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weapon.FieldDmg,
})
}
if value, ok := wuo.mutation.EqType(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wuo.mutation.AddedEqType(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldEqType,
})
}
if value, ok := wuo.mutation.HitGroup(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
if value, ok := wuo.mutation.AddedHitGroup(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weapon.FieldHitGroup,
})
}
if wuo.mutation.StatCleared() {
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,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := wuo.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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Weapon{config: wuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{weapon.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}
return _node, nil
}

View File

@@ -1,311 +0,0 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// WeaponStatsCreate is the builder for creating a WeaponStats entity.
type WeaponStatsCreate struct {
config
mutation *WeaponStatsMutation
hooks []Hook
}
// SetVictim sets the "victim" field.
func (wsc *WeaponStatsCreate) SetVictim(u uint64) *WeaponStatsCreate {
wsc.mutation.SetVictim(u)
return wsc
}
// SetDmg sets the "dmg" field.
func (wsc *WeaponStatsCreate) SetDmg(u uint) *WeaponStatsCreate {
wsc.mutation.SetDmg(u)
return wsc
}
// SetEqType sets the "eq_type" field.
func (wsc *WeaponStatsCreate) SetEqType(i int) *WeaponStatsCreate {
wsc.mutation.SetEqType(i)
return wsc
}
// SetHitGroup sets the "hit_group" field.
func (wsc *WeaponStatsCreate) SetHitGroup(i int) *WeaponStatsCreate {
wsc.mutation.SetHitGroup(i)
return wsc
}
// SetStatID sets the "stat" edge to the Stats entity by ID.
func (wsc *WeaponStatsCreate) SetStatID(id int) *WeaponStatsCreate {
wsc.mutation.SetStatID(id)
return wsc
}
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
func (wsc *WeaponStatsCreate) SetNillableStatID(id *int) *WeaponStatsCreate {
if id != nil {
wsc = wsc.SetStatID(*id)
}
return wsc
}
// SetStat sets the "stat" edge to the Stats entity.
func (wsc *WeaponStatsCreate) SetStat(s *Stats) *WeaponStatsCreate {
return wsc.SetStatID(s.ID)
}
// Mutation returns the WeaponStatsMutation object of the builder.
func (wsc *WeaponStatsCreate) Mutation() *WeaponStatsMutation {
return wsc.mutation
}
// Save creates the WeaponStats in the database.
func (wsc *WeaponStatsCreate) Save(ctx context.Context) (*WeaponStats, error) {
var (
err error
node *WeaponStats
)
if len(wsc.hooks) == 0 {
if err = wsc.check(); err != nil {
return nil, err
}
node, err = wsc.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponStatsMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = wsc.check(); err != nil {
return nil, err
}
wsc.mutation = mutation
if node, err = wsc.sqlSave(ctx); err != nil {
return nil, err
}
mutation.id = &node.ID
mutation.done = true
return node, err
})
for i := len(wsc.hooks) - 1; i >= 0; i-- {
if wsc.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wsc.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wsc.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX calls Save and panics if Save returns an error.
func (wsc *WeaponStatsCreate) SaveX(ctx context.Context) *WeaponStats {
v, err := wsc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (wsc *WeaponStatsCreate) Exec(ctx context.Context) error {
_, err := wsc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wsc *WeaponStatsCreate) ExecX(ctx context.Context) {
if err := wsc.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (wsc *WeaponStatsCreate) check() error {
if _, ok := wsc.mutation.Victim(); !ok {
return &ValidationError{Name: "victim", err: errors.New(`ent: missing required field "victim"`)}
}
if _, ok := wsc.mutation.Dmg(); !ok {
return &ValidationError{Name: "dmg", err: errors.New(`ent: missing required field "dmg"`)}
}
if _, ok := wsc.mutation.EqType(); !ok {
return &ValidationError{Name: "eq_type", err: errors.New(`ent: missing required field "eq_type"`)}
}
if _, ok := wsc.mutation.HitGroup(); !ok {
return &ValidationError{Name: "hit_group", err: errors.New(`ent: missing required field "hit_group"`)}
}
return nil
}
func (wsc *WeaponStatsCreate) sqlSave(ctx context.Context) (*WeaponStats, error) {
_node, _spec := wsc.createSpec()
if err := sqlgraph.CreateNode(ctx, wsc.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 (wsc *WeaponStatsCreate) createSpec() (*WeaponStats, *sqlgraph.CreateSpec) {
var (
_node = &WeaponStats{config: wsc.config}
_spec = &sqlgraph.CreateSpec{
Table: weaponstats.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weaponstats.FieldID,
},
}
)
if value, ok := wsc.mutation.Victim(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weaponstats.FieldVictim,
})
_node.Victim = value
}
if value, ok := wsc.mutation.Dmg(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weaponstats.FieldDmg,
})
_node.Dmg = value
}
if value, ok := wsc.mutation.EqType(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldEqType,
})
_node.EqType = value
}
if value, ok := wsc.mutation.HitGroup(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldHitGroup,
})
_node.HitGroup = value
}
if nodes := wsc.mutation.StatIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weaponstats.StatTable,
Columns: []string{weaponstats.StatColumn},
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)
}
_node.stats_weapon_stats = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// WeaponStatsCreateBulk is the builder for creating many WeaponStats entities in bulk.
type WeaponStatsCreateBulk struct {
config
builders []*WeaponStatsCreate
}
// Save creates the WeaponStats entities in the database.
func (wscb *WeaponStatsCreateBulk) Save(ctx context.Context) ([]*WeaponStats, error) {
specs := make([]*sqlgraph.CreateSpec, len(wscb.builders))
nodes := make([]*WeaponStats, len(wscb.builders))
mutators := make([]Mutator, len(wscb.builders))
for i := range wscb.builders {
func(i int, root context.Context) {
builder := wscb.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponStatsMutation)
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, wscb.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, wscb.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, wscb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (wscb *WeaponStatsCreateBulk) SaveX(ctx context.Context) []*WeaponStats {
v, err := wscb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (wscb *WeaponStatsCreateBulk) Exec(ctx context.Context) error {
_, err := wscb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wscb *WeaponStatsCreateBulk) ExecX(ctx context.Context) {
if err := wscb.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -1,111 +0,0 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/predicate"
"csgowtfd/ent/weaponstats"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// WeaponStatsDelete is the builder for deleting a WeaponStats entity.
type WeaponStatsDelete struct {
config
hooks []Hook
mutation *WeaponStatsMutation
}
// Where appends a list predicates to the WeaponStatsDelete builder.
func (wsd *WeaponStatsDelete) Where(ps ...predicate.WeaponStats) *WeaponStatsDelete {
wsd.mutation.Where(ps...)
return wsd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (wsd *WeaponStatsDelete) Exec(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(wsd.hooks) == 0 {
affected, err = wsd.sqlExec(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponStatsMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
wsd.mutation = mutation
affected, err = wsd.sqlExec(ctx)
mutation.done = true
return affected, err
})
for i := len(wsd.hooks) - 1; i >= 0; i-- {
if wsd.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wsd.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wsd.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// ExecX is like Exec, but panics if an error occurs.
func (wsd *WeaponStatsDelete) ExecX(ctx context.Context) int {
n, err := wsd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (wsd *WeaponStatsDelete) sqlExec(ctx context.Context) (int, error) {
_spec := &sqlgraph.DeleteSpec{
Node: &sqlgraph.NodeSpec{
Table: weaponstats.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weaponstats.FieldID,
},
},
}
if ps := wsd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return sqlgraph.DeleteNodes(ctx, wsd.driver, _spec)
}
// WeaponStatsDeleteOne is the builder for deleting a single WeaponStats entity.
type WeaponStatsDeleteOne struct {
wsd *WeaponStatsDelete
}
// Exec executes the deletion query.
func (wsdo *WeaponStatsDeleteOne) Exec(ctx context.Context) error {
n, err := wsdo.wsd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{weaponstats.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (wsdo *WeaponStatsDeleteOne) ExecX(ctx context.Context) {
wsdo.wsd.ExecX(ctx)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,575 +0,0 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"csgowtfd/ent/predicate"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// WeaponStatsUpdate is the builder for updating WeaponStats entities.
type WeaponStatsUpdate struct {
config
hooks []Hook
mutation *WeaponStatsMutation
}
// Where appends a list predicates to the WeaponStatsUpdate builder.
func (wsu *WeaponStatsUpdate) Where(ps ...predicate.WeaponStats) *WeaponStatsUpdate {
wsu.mutation.Where(ps...)
return wsu
}
// SetVictim sets the "victim" field.
func (wsu *WeaponStatsUpdate) SetVictim(u uint64) *WeaponStatsUpdate {
wsu.mutation.ResetVictim()
wsu.mutation.SetVictim(u)
return wsu
}
// AddVictim adds u to the "victim" field.
func (wsu *WeaponStatsUpdate) AddVictim(u uint64) *WeaponStatsUpdate {
wsu.mutation.AddVictim(u)
return wsu
}
// SetDmg sets the "dmg" field.
func (wsu *WeaponStatsUpdate) SetDmg(u uint) *WeaponStatsUpdate {
wsu.mutation.ResetDmg()
wsu.mutation.SetDmg(u)
return wsu
}
// AddDmg adds u to the "dmg" field.
func (wsu *WeaponStatsUpdate) AddDmg(u uint) *WeaponStatsUpdate {
wsu.mutation.AddDmg(u)
return wsu
}
// SetEqType sets the "eq_type" field.
func (wsu *WeaponStatsUpdate) SetEqType(i int) *WeaponStatsUpdate {
wsu.mutation.ResetEqType()
wsu.mutation.SetEqType(i)
return wsu
}
// AddEqType adds i to the "eq_type" field.
func (wsu *WeaponStatsUpdate) AddEqType(i int) *WeaponStatsUpdate {
wsu.mutation.AddEqType(i)
return wsu
}
// SetHitGroup sets the "hit_group" field.
func (wsu *WeaponStatsUpdate) SetHitGroup(i int) *WeaponStatsUpdate {
wsu.mutation.ResetHitGroup()
wsu.mutation.SetHitGroup(i)
return wsu
}
// AddHitGroup adds i to the "hit_group" field.
func (wsu *WeaponStatsUpdate) AddHitGroup(i int) *WeaponStatsUpdate {
wsu.mutation.AddHitGroup(i)
return wsu
}
// SetStatID sets the "stat" edge to the Stats entity by ID.
func (wsu *WeaponStatsUpdate) SetStatID(id int) *WeaponStatsUpdate {
wsu.mutation.SetStatID(id)
return wsu
}
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
func (wsu *WeaponStatsUpdate) SetNillableStatID(id *int) *WeaponStatsUpdate {
if id != nil {
wsu = wsu.SetStatID(*id)
}
return wsu
}
// SetStat sets the "stat" edge to the Stats entity.
func (wsu *WeaponStatsUpdate) SetStat(s *Stats) *WeaponStatsUpdate {
return wsu.SetStatID(s.ID)
}
// Mutation returns the WeaponStatsMutation object of the builder.
func (wsu *WeaponStatsUpdate) Mutation() *WeaponStatsMutation {
return wsu.mutation
}
// ClearStat clears the "stat" edge to the Stats entity.
func (wsu *WeaponStatsUpdate) ClearStat() *WeaponStatsUpdate {
wsu.mutation.ClearStat()
return wsu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (wsu *WeaponStatsUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(wsu.hooks) == 0 {
affected, err = wsu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponStatsMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
wsu.mutation = mutation
affected, err = wsu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(wsu.hooks) - 1; i >= 0; i-- {
if wsu.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wsu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wsu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (wsu *WeaponStatsUpdate) SaveX(ctx context.Context) int {
affected, err := wsu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (wsu *WeaponStatsUpdate) Exec(ctx context.Context) error {
_, err := wsu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wsu *WeaponStatsUpdate) ExecX(ctx context.Context) {
if err := wsu.Exec(ctx); err != nil {
panic(err)
}
}
func (wsu *WeaponStatsUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: weaponstats.Table,
Columns: weaponstats.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weaponstats.FieldID,
},
},
}
if ps := wsu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := wsu.mutation.Victim(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weaponstats.FieldVictim,
})
}
if value, ok := wsu.mutation.AddedVictim(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weaponstats.FieldVictim,
})
}
if value, ok := wsu.mutation.Dmg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weaponstats.FieldDmg,
})
}
if value, ok := wsu.mutation.AddedDmg(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weaponstats.FieldDmg,
})
}
if value, ok := wsu.mutation.EqType(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldEqType,
})
}
if value, ok := wsu.mutation.AddedEqType(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldEqType,
})
}
if value, ok := wsu.mutation.HitGroup(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldHitGroup,
})
}
if value, ok := wsu.mutation.AddedHitGroup(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldHitGroup,
})
}
if wsu.mutation.StatCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weaponstats.StatTable,
Columns: []string{weaponstats.StatColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := wsu.mutation.StatIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weaponstats.StatTable,
Columns: []string{weaponstats.StatColumn},
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.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, wsu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{weaponstats.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return 0, err
}
return n, nil
}
// WeaponStatsUpdateOne is the builder for updating a single WeaponStats entity.
type WeaponStatsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *WeaponStatsMutation
}
// SetVictim sets the "victim" field.
func (wsuo *WeaponStatsUpdateOne) SetVictim(u uint64) *WeaponStatsUpdateOne {
wsuo.mutation.ResetVictim()
wsuo.mutation.SetVictim(u)
return wsuo
}
// AddVictim adds u to the "victim" field.
func (wsuo *WeaponStatsUpdateOne) AddVictim(u uint64) *WeaponStatsUpdateOne {
wsuo.mutation.AddVictim(u)
return wsuo
}
// SetDmg sets the "dmg" field.
func (wsuo *WeaponStatsUpdateOne) SetDmg(u uint) *WeaponStatsUpdateOne {
wsuo.mutation.ResetDmg()
wsuo.mutation.SetDmg(u)
return wsuo
}
// AddDmg adds u to the "dmg" field.
func (wsuo *WeaponStatsUpdateOne) AddDmg(u uint) *WeaponStatsUpdateOne {
wsuo.mutation.AddDmg(u)
return wsuo
}
// SetEqType sets the "eq_type" field.
func (wsuo *WeaponStatsUpdateOne) SetEqType(i int) *WeaponStatsUpdateOne {
wsuo.mutation.ResetEqType()
wsuo.mutation.SetEqType(i)
return wsuo
}
// AddEqType adds i to the "eq_type" field.
func (wsuo *WeaponStatsUpdateOne) AddEqType(i int) *WeaponStatsUpdateOne {
wsuo.mutation.AddEqType(i)
return wsuo
}
// SetHitGroup sets the "hit_group" field.
func (wsuo *WeaponStatsUpdateOne) SetHitGroup(i int) *WeaponStatsUpdateOne {
wsuo.mutation.ResetHitGroup()
wsuo.mutation.SetHitGroup(i)
return wsuo
}
// AddHitGroup adds i to the "hit_group" field.
func (wsuo *WeaponStatsUpdateOne) AddHitGroup(i int) *WeaponStatsUpdateOne {
wsuo.mutation.AddHitGroup(i)
return wsuo
}
// SetStatID sets the "stat" edge to the Stats entity by ID.
func (wsuo *WeaponStatsUpdateOne) SetStatID(id int) *WeaponStatsUpdateOne {
wsuo.mutation.SetStatID(id)
return wsuo
}
// SetNillableStatID sets the "stat" edge to the Stats entity by ID if the given value is not nil.
func (wsuo *WeaponStatsUpdateOne) SetNillableStatID(id *int) *WeaponStatsUpdateOne {
if id != nil {
wsuo = wsuo.SetStatID(*id)
}
return wsuo
}
// SetStat sets the "stat" edge to the Stats entity.
func (wsuo *WeaponStatsUpdateOne) SetStat(s *Stats) *WeaponStatsUpdateOne {
return wsuo.SetStatID(s.ID)
}
// Mutation returns the WeaponStatsMutation object of the builder.
func (wsuo *WeaponStatsUpdateOne) Mutation() *WeaponStatsMutation {
return wsuo.mutation
}
// ClearStat clears the "stat" edge to the Stats entity.
func (wsuo *WeaponStatsUpdateOne) ClearStat() *WeaponStatsUpdateOne {
wsuo.mutation.ClearStat()
return wsuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (wsuo *WeaponStatsUpdateOne) Select(field string, fields ...string) *WeaponStatsUpdateOne {
wsuo.fields = append([]string{field}, fields...)
return wsuo
}
// Save executes the query and returns the updated WeaponStats entity.
func (wsuo *WeaponStatsUpdateOne) Save(ctx context.Context) (*WeaponStats, error) {
var (
err error
node *WeaponStats
)
if len(wsuo.hooks) == 0 {
node, err = wsuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*WeaponStatsMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
wsuo.mutation = mutation
node, err = wsuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(wsuo.hooks) - 1; i >= 0; i-- {
if wsuo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = wsuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, wsuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (wsuo *WeaponStatsUpdateOne) SaveX(ctx context.Context) *WeaponStats {
node, err := wsuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (wsuo *WeaponStatsUpdateOne) Exec(ctx context.Context) error {
_, err := wsuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (wsuo *WeaponStatsUpdateOne) ExecX(ctx context.Context) {
if err := wsuo.Exec(ctx); err != nil {
panic(err)
}
}
func (wsuo *WeaponStatsUpdateOne) sqlSave(ctx context.Context) (_node *WeaponStats, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: weaponstats.Table,
Columns: weaponstats.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: weaponstats.FieldID,
},
},
}
id, ok := wsuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing WeaponStats.ID for update")}
}
_spec.Node.ID.Value = id
if fields := wsuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, weaponstats.FieldID)
for _, f := range fields {
if !weaponstats.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != weaponstats.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := wsuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := wsuo.mutation.Victim(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weaponstats.FieldVictim,
})
}
if value, ok := wsuo.mutation.AddedVictim(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: weaponstats.FieldVictim,
})
}
if value, ok := wsuo.mutation.Dmg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weaponstats.FieldDmg,
})
}
if value, ok := wsuo.mutation.AddedDmg(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint,
Value: value,
Column: weaponstats.FieldDmg,
})
}
if value, ok := wsuo.mutation.EqType(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldEqType,
})
}
if value, ok := wsuo.mutation.AddedEqType(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldEqType,
})
}
if value, ok := wsuo.mutation.HitGroup(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldHitGroup,
})
}
if value, ok := wsuo.mutation.AddedHitGroup(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: weaponstats.FieldHitGroup,
})
}
if wsuo.mutation.StatCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weaponstats.StatTable,
Columns: []string{weaponstats.StatColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := wsuo.mutation.StatIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: weaponstats.StatTable,
Columns: []string{weaponstats.StatColumn},
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.Add = append(_spec.Edges.Add, edge)
}
_node = &WeaponStats{config: wsuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, wsuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{weaponstats.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{err.Error(), err}
}
return nil, err
}
return _node, nil
}

4
go.mod
View File

@@ -45,8 +45,8 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/exp v0.0.0-20211025140241-8418b01e8c3b // indirect
golang.org/x/exp v0.0.0-20211029182501-9b944d235b9d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/text v0.3.7 // indirect
)

18
go.sum
View File

@@ -53,7 +53,6 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
@@ -120,6 +119,7 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
github.com/go-redis/cache/v8 v8.4.3 h1:+RZ0pQM+zOd6h/oWCsOl3+nsCgii9rn26oCYmU87kN8=
github.com/go-redis/cache/v8 v8.4.3/go.mod h1:5lQPQ63uyBt4aZuRmdvUJOJRRjPxfLtJtlcJ/z8o1jA=
@@ -228,7 +228,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@@ -249,7 +248,6 @@ github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5W
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
@@ -331,6 +329,7 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -363,6 +362,7 @@ github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtb
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -449,10 +449,12 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
@@ -541,8 +543,8 @@ golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9t
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
golang.org/x/exp v0.0.0-20210916165020-5cb4fee858ee/go.mod h1:a3o/VtDNHN+dCVLEpzjjUHOzR+Ln3DHX056ZPzoZGGA=
golang.org/x/exp v0.0.0-20211025140241-8418b01e8c3b h1:AHIXEGqpPGg/yJCO803Q+UbBiq/vkCe/OPwMSVE7psI=
golang.org/x/exp v0.0.0-20211025140241-8418b01e8c3b/go.mod h1:a3o/VtDNHN+dCVLEpzjjUHOzR+Ln3DHX056ZPzoZGGA=
golang.org/x/exp v0.0.0-20211029182501-9b944d235b9d h1:MKwb3mzSy4CTpgAm10+7Ru8Hq8ZnHOGgWAjo9fNVK+o=
golang.org/x/exp v0.0.0-20211029182501-9b944d235b9d/go.mod h1:OyI624f2tQ/aU3IMa7GB16Hk54CHURAfHfj6tMqtyhA=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
@@ -564,6 +566,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 h1:LQmS1nU0twXLA96Kt7U9qtHJEbBk3z6Q0V4UXjZkpr4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -640,8 +643,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 h1:M69LAlWZCshgp0QSzyDcSsSIejIEeuaCVpmwcKwyLMk=
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -688,6 +691,7 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023 h1:0c3L82FDQ5rt1bjTBlchS8t6RQ6299/+5bWMnRLh+uI=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

89
main.go
View File

@@ -1,14 +1,16 @@
package main
import (
"bytes"
"context"
"csgowtfd/csgo"
"csgowtfd/ent"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/migrate"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"csgowtfd/utils"
"encoding/gob"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"flag"
@@ -304,6 +306,11 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
GameBanDate: tPlayer.GameBanDate.Unix(),
VanityURL: tPlayer.VanityURLReal,
Tracked: tPlayer.AuthCode != "",
MatchStats: &utils.MatchStats{
Win: tPlayer.Wins,
Tie: tPlayer.Ties,
Loss: tPlayer.Looses,
},
Matches: []*utils.MatchResponse{},
}
@@ -324,44 +331,6 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
return
}
metaStats := new(utils.MatchStats)
err = rdc.Get(context.Background(), fmt.Sprintf(utils.MatchMetaCacheKey, tPlayer.ID), &metaStats)
if err != nil {
wins, ties, losses, err := utils.GetMatchStats(tPlayer)
if err != nil {
log.Errorf("[GP] Error retrieving match-stats for player %s: %v", id, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
response.MatchStats = &utils.MatchStats{
Win: wins,
Loss: losses,
Tie: ties,
}
err = rdc.Set(&cache.Item{
Ctx: context.Background(),
Key: fmt.Sprintf(utils.MatchMetaCacheKey, tPlayer.ID),
Value: response.MatchStats,
TTL: time.Hour * 24 * 30,
})
if err != nil {
log.Errorf("[GP] Failure saving to cache: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
log.Debugf("[GP] Metastats for %d saved to cache", tPlayer.ID)
} else {
log.Debugf("[GP] Metastats for %d from cache", tPlayer.ID)
response.MatchStats = &utils.MatchStats{
Win: metaStats.Win,
Tie: metaStats.Tie,
Loss: metaStats.Loss,
}
}
for _, iMatch := range tMatches {
mResponse := &utils.MatchResponse{
MatchId: iMatch.ID,
@@ -377,10 +346,10 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
}
tStats, err := iMatch.QueryStats().Modify(func(s *sql.Selector) {
s.Select(stats.FieldTeamID, stats.FieldKills, stats.FieldDeaths, stats.FieldAssists, stats.FieldHeadshot,
stats.FieldMvp, stats.FieldScore, stats.FieldMk2, stats.FieldMk3, stats.FieldMk4, stats.FieldMk5,
stats.FieldRankOld, stats.FieldRankNew, stats.FieldDmgTeam, stats.FieldDmgEnemy)
s.Where(sql.EQ(s.C(stats.PlayersColumn), tPlayer.ID))
s.Select(matchplayer.FieldTeamID, matchplayer.FieldKills, matchplayer.FieldDeaths, matchplayer.FieldAssists, matchplayer.FieldHeadshot,
matchplayer.FieldMvp, matchplayer.FieldScore, matchplayer.FieldMk2, matchplayer.FieldMk3, matchplayer.FieldMk4, matchplayer.FieldMk5,
matchplayer.FieldRankOld, matchplayer.FieldRankNew, matchplayer.FieldDmgTeam, matchplayer.FieldDmgEnemy)
s.Where(sql.EQ(s.C(matchplayer.PlayersColumn), tPlayer.ID))
}).Only(context.Background())
if err != nil {
response.Matches = append(response.Matches, mResponse)
@@ -571,7 +540,7 @@ func getMatchRounds(w http.ResponseWriter, r *http.Request) {
return
}
tStats, err := db.Stats.Query().Where(stats.HasMatchesWith(match.ID(matchId))).All(context.Background())
tStats, err := db.MatchPlayer.Query().Where(matchplayer.HasMatchesWith(match.ID(matchId))).All(context.Background())
if err != nil {
log.Infof("[GMR] match %d not found: %+v", matchId, err)
w.WriteHeader(http.StatusNotFound)
@@ -618,7 +587,7 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
return
}
tStats, err := db.Stats.Query().Where(stats.HasMatchesWith(match.ID(matchId))).All(context.Background())
tStats, err := db.MatchPlayer.Query().Where(matchplayer.HasMatchesWith(match.ID(matchId))).All(context.Background())
if err != nil {
log.Infof("[GMW] match %d not found: %+v", matchId, err)
w.WriteHeader(http.StatusNotFound)
@@ -628,9 +597,11 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
mResponse := struct {
EquipmentMap map[int]string `json:"equipment_map,omitempty"`
Stats []map[string]map[string][][]int `json:"stats,omitempty"`
Spray []map[string]map[int][][]float32 `json:"spray,omitempty"`
}{
EquipmentMap: map[int]string{},
Stats: []map[string]map[string][][]int{},
Spray: []map[string]map[int][][]float32{},
}
for _, stat := range tStats {
@@ -644,7 +615,7 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
playerId := strconv.FormatUint(stat.PlayerStats, 10)
for _, wr := range mWs {
if _, exists := mWr[strconv.FormatUint(stat.PlayerStats, 10)]; !exists {
if _, exists := mWr[playerId]; !exists {
mWr[playerId] = map[string][][]int{}
}
@@ -656,6 +627,32 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
}
}
mResponse.Stats = append(mResponse.Stats, mWr)
mSprays, err := stat.QuerySpray().All(context.Background())
if err != nil {
log.Warningf("[GMW] Unable to get Sprays for player %d: %v", stat.PlayerStats, err)
continue
}
rSprays := map[string]map[int][][]float32{}
for _, spray := range mSprays {
if _, exists := rSprays[playerId]; !exists {
rSprays[playerId] = map[int][][]float32{}
}
bBuf := bytes.NewBuffer(spray.Spray)
dec := gob.NewDecoder(bBuf)
var dSpray [][]float32
err := dec.Decode(&dSpray)
if err != nil {
log.Warningf("[GMW] Unable to decode Sprays for player %d: %v", stat.PlayerStats, err)
continue
}
log.Debugf("%+v", dSpray)
rSprays[playerId][spray.Weapon] = dSpray
}
mResponse.Spray = append(mResponse.Spray, rSprays)
}
err = utils.SendJSON(mResponse, w)

View File

@@ -4,9 +4,9 @@ import (
"context"
"csgowtfd/ent"
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"csgowtfd/ent/weapon"
"encoding/json"
"entgo.io/ent/dialect/sql"
"errors"
@@ -198,7 +198,6 @@ type (
const (
shareCodeURLEntry = "https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=%s&steamid=%d&steamidkey=%s&knowncode=%s"
SideMetaCacheKey = "csgowtfd_side_meta_%d"
MatchMetaCacheKey = "csgowtfd_match_meta_%d"
)
//goland:noinspection SpellCheckingInspection
@@ -222,15 +221,6 @@ func SendJSON(data interface{}, w http.ResponseWriter) error {
return nil
}
func GetMatchStats(dbPlayer *ent.Player) (int, int, int, error) {
wins, loss, ties, err := getWinLossTieFromPlayer(dbPlayer)
if err != nil {
return 0, 0, 0, err
}
return wins, ties, loss, nil
}
func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
mResponse := new(MetaStatsResponse)
mResponse.Player = &PlayerResponse{SteamID64: dbPlayer.ID}
@@ -267,7 +257,7 @@ func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
Select(match.FieldID, match.FieldMatchResult, match.FieldMap).
Where(match.IDIn(matchIDs...)).
WithStats().
Where(match.HasStatsWith(stats.Or(stats.PlayerStats(dbPlayer.ID), stats.PlayerStats(s.ID)))).
Where(match.HasStatsWith(matchplayer.Or(matchplayer.PlayerStats(dbPlayer.ID), matchplayer.PlayerStats(s.ID)))).
All(context.Background())
if err != nil {
return nil, err
@@ -278,8 +268,8 @@ func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
var ties int
for _, pm := range pMatches {
var subjectStats *ent.Stats
var currentStats *ent.Stats
var subjectStats *ent.MatchPlayer
var currentStats *ent.MatchPlayer
for _, ps := range pm.Edges.Stats {
if ps.PlayerStats == dbPlayer.ID {
@@ -303,7 +293,7 @@ func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
}
wSs, err := subjectStats.QueryWeaponStats().
Select(weaponstats.FieldEqType, weaponstats.FieldDmg).All(context.Background())
Select(weapon.FieldEqType, weapon.FieldDmg).All(context.Background())
if err != nil {
return nil, err
}
@@ -389,41 +379,36 @@ func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
return mResponse, nil
}
func getWinLossTieFromPlayer(dbPlayer *ent.Player) (int, int, int, error) {
func GetWinLossTieForPlayer(dbPlayer *ent.Player) (wins int, looses int, ties int, err error) {
var res []struct {
MatchResult int `json:"match_result"`
Count int `json:"count"`
}
err := dbPlayer.QueryMatches().GroupBy(match.FieldMatchResult).Aggregate(func(s *sql.Selector) string {
sT := sql.Table(stats.Table)
err = dbPlayer.QueryMatches().GroupBy(match.FieldMatchResult).Aggregate(func(s *sql.Selector) string {
sT := sql.Table(matchplayer.Table)
s.Join(sT).On(s.C(match.FieldID), sT.C(stats.MatchesColumn))
s.Join(sT).On(s.C(match.FieldID), sT.C(matchplayer.MatchesColumn))
s.Where(sql.And(
sql.Or(
sql.ColumnsEQ(match.FieldMatchResult, stats.FieldTeamID),
sql.ColumnsEQ(match.FieldMatchResult, matchplayer.FieldTeamID),
sql.EQ(s.C(match.FieldMatchResult), 0),
),
sql.EQ(sT.C(stats.PlayersColumn), dbPlayer.ID),
sql.EQ(sT.C(matchplayer.PlayersColumn), dbPlayer.ID),
))
return sql.Count("*")
}).Scan(context.Background(), &res)
if err != nil {
return 0, 0, 0, err
return
}
total, err := dbPlayer.QueryMatches().Modify(func(s *sql.Selector) {
s.Select("COUNT(*)")
}).Int(context.Background())
if err != nil {
return 0, 0, 0, err
return
}
var (
wins int
ties int
)
for _, r := range res {
switch r.MatchResult {
case 0:
@@ -432,8 +417,9 @@ func getWinLossTieFromPlayer(dbPlayer *ent.Player) (int, int, int, error) {
wins += r.Count
}
}
looses = total - wins - ties
return wins, total - wins - ties, ties, nil
return
}
func IsAuthCodeValid(player *ent.Player, apiKey string, shareCode string, authCode string, rl ratelimit.Limiter) (bool, error) {