[FEATURE] Detailed stats about player weapon usage and hitgroups (#1)
Reviewed-on: https://git.harting.dev/CSGOWTF/csgowtfd/pulls/1 Co-authored-by: Giovanni Harting <539@idlegandalf.com> Co-committed-by: Giovanni Harting <539@idlegandalf.com>
This commit is contained in:
147
ent/client.go
147
ent/client.go
@@ -12,6 +12,7 @@ import (
|
||||
"csgowtfd/ent/match"
|
||||
"csgowtfd/ent/player"
|
||||
"csgowtfd/ent/stats"
|
||||
"csgowtfd/ent/weaponstats"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -29,6 +30,8 @@ type Client struct {
|
||||
Player *PlayerClient
|
||||
// Stats is the client for interacting with the Stats builders.
|
||||
Stats *StatsClient
|
||||
// WeaponStats is the client for interacting with the WeaponStats builders.
|
||||
WeaponStats *WeaponStatsClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
@@ -45,6 +48,7 @@ func (c *Client) init() {
|
||||
c.Match = NewMatchClient(c.config)
|
||||
c.Player = NewPlayerClient(c.config)
|
||||
c.Stats = NewStatsClient(c.config)
|
||||
c.WeaponStats = NewWeaponStatsClient(c.config)
|
||||
}
|
||||
|
||||
// Open opens a database/sql.DB specified by the driver name and
|
||||
@@ -76,11 +80,12 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Match: NewMatchClient(cfg),
|
||||
Player: NewPlayerClient(cfg),
|
||||
Stats: NewStatsClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Match: NewMatchClient(cfg),
|
||||
Player: NewPlayerClient(cfg),
|
||||
Stats: NewStatsClient(cfg),
|
||||
WeaponStats: NewWeaponStatsClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -98,10 +103,11 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
cfg := c.config
|
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||
return &Tx{
|
||||
config: cfg,
|
||||
Match: NewMatchClient(cfg),
|
||||
Player: NewPlayerClient(cfg),
|
||||
Stats: NewStatsClient(cfg),
|
||||
config: cfg,
|
||||
Match: NewMatchClient(cfg),
|
||||
Player: NewPlayerClient(cfg),
|
||||
Stats: NewStatsClient(cfg),
|
||||
WeaponStats: NewWeaponStatsClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -134,6 +140,7 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
c.Match.Use(hooks...)
|
||||
c.Player.Use(hooks...)
|
||||
c.Stats.Use(hooks...)
|
||||
c.WeaponStats.Use(hooks...)
|
||||
}
|
||||
|
||||
// MatchClient is a client for the Match schema.
|
||||
@@ -497,7 +504,129 @@ func (c *StatsClient) QueryPlayers(s *Stats) *PlayerQuery {
|
||||
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
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *StatsClient) Hooks() []Hook {
|
||||
return c.hooks.Stats
|
||||
}
|
||||
|
||||
// WeaponStatsClient is a client for the WeaponStats schema.
|
||||
type WeaponStatsClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewWeaponStatsClient returns a client for the WeaponStats from the given config.
|
||||
func NewWeaponStatsClient(c config) *WeaponStatsClient {
|
||||
return &WeaponStatsClient{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...)
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *WeaponStatsClient) DeleteOne(ws *WeaponStats) *WeaponStatsDeleteOne {
|
||||
return c.DeleteOneID(ws.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *WeaponStatsClient) DeleteOneID(id int) *WeaponStatsDeleteOne {
|
||||
builder := c.Delete().Where(weaponstats.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &WeaponStatsDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for WeaponStats.
|
||||
func (c *WeaponStatsClient) Query() *WeaponStatsQuery {
|
||||
return &WeaponStatsQuery{
|
||||
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)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *WeaponStatsClient) GetX(ctx context.Context, id int) *WeaponStats {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryStat queries the stat edge of a WeaponStats.
|
||||
func (c *WeaponStatsClient) QueryStat(ws *WeaponStats) *StatsQuery {
|
||||
query := &StatsQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := ws.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),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(ws.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *WeaponStatsClient) Hooks() []Hook {
|
||||
return c.hooks.WeaponStats
|
||||
}
|
||||
|
Reference in New Issue
Block a user