import from unified repo

This commit is contained in:
2021-10-03 16:24:20 +02:00
commit 79d1df4cf3
50 changed files with 21269 additions and 0 deletions

503
ent/client.go Normal file
View File

@@ -0,0 +1,503 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"log"
"csgowtfd/ent/migrate"
"csgowtfd/ent/match"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// Client is the client that holds all ent builders.
type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// Match is the client for interacting with the Match builders.
Match *MatchClient
// Player is the client for interacting with the Player builders.
Player *PlayerClient
// Stats is the client for interacting with the Stats builders.
Stats *StatsClient
}
// NewClient creates a new client configured with the given options.
func NewClient(opts ...Option) *Client {
cfg := config{log: log.Println, hooks: &hooks{}}
cfg.options(opts...)
client := &Client{config: cfg}
client.init()
return client
}
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.Match = NewMatchClient(c.config)
c.Player = NewPlayerClient(c.config)
c.Stats = NewStatsClient(c.config)
}
// Open opens a database/sql.DB specified by the driver name and
// the data source name, and returns a new client attached to it.
// Optional parameters can be added for configuring the client.
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
switch driverName {
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
drv, err := sql.Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
return NewClient(append(options, Driver(drv))...), nil
default:
return nil, fmt.Errorf("unsupported driver: %q", driverName)
}
}
// Tx returns a new transactional client. The provided context
// is used until the transaction is committed or rolled back.
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
}
tx, err := newTx(ctx, c.driver)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = tx
return &Tx{
ctx: ctx,
config: cfg,
Match: NewMatchClient(cfg),
Player: NewPlayerClient(cfg),
Stats: NewStatsClient(cfg),
}, nil
}
// BeginTx returns a transactional client with specified options.
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
}
tx, err := c.driver.(interface {
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
}).BeginTx(ctx, opts)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = &txDriver{tx: tx, drv: c.driver}
return &Tx{
config: cfg,
Match: NewMatchClient(cfg),
Player: NewPlayerClient(cfg),
Stats: NewStatsClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// Match.
// Query().
// Count(ctx)
//
func (c *Client) Debug() *Client {
if c.debug {
return c
}
cfg := c.config
cfg.driver = dialect.Debug(c.driver, c.log)
client := &Client{config: cfg}
client.init()
return client
}
// Close closes the database connection and prevents new queries from starting.
func (c *Client) Close() error {
return c.driver.Close()
}
// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
c.Match.Use(hooks...)
c.Player.Use(hooks...)
c.Stats.Use(hooks...)
}
// MatchClient is a client for the Match schema.
type MatchClient struct {
config
}
// NewMatchClient returns a client for the Match from the given config.
func NewMatchClient(c config) *MatchClient {
return &MatchClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `match.Hooks(f(g(h())))`.
func (c *MatchClient) Use(hooks ...Hook) {
c.hooks.Match = append(c.hooks.Match, hooks...)
}
// Create returns a create builder for Match.
func (c *MatchClient) Create() *MatchCreate {
mutation := newMatchMutation(c.config, OpCreate)
return &MatchCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Match entities.
func (c *MatchClient) CreateBulk(builders ...*MatchCreate) *MatchCreateBulk {
return &MatchCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Match.
func (c *MatchClient) Update() *MatchUpdate {
mutation := newMatchMutation(c.config, OpUpdate)
return &MatchUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *MatchClient) UpdateOne(m *Match) *MatchUpdateOne {
mutation := newMatchMutation(c.config, OpUpdateOne, withMatch(m))
return &MatchUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *MatchClient) UpdateOneID(id int) *MatchUpdateOne {
mutation := newMatchMutation(c.config, OpUpdateOne, withMatchID(id))
return &MatchUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Match.
func (c *MatchClient) Delete() *MatchDelete {
mutation := newMatchMutation(c.config, OpDelete)
return &MatchDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a delete builder for the given entity.
func (c *MatchClient) DeleteOne(m *Match) *MatchDeleteOne {
return c.DeleteOneID(m.ID)
}
// DeleteOneID returns a delete builder for the given id.
func (c *MatchClient) DeleteOneID(id int) *MatchDeleteOne {
builder := c.Delete().Where(match.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &MatchDeleteOne{builder}
}
// Query returns a query builder for Match.
func (c *MatchClient) Query() *MatchQuery {
return &MatchQuery{
config: c.config,
}
}
// Get returns a Match entity by its id.
func (c *MatchClient) Get(ctx context.Context, id int) (*Match, error) {
return c.Query().Where(match.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *MatchClient) GetX(ctx context.Context, id int) *Match {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryStats queries the stats edge of a Match.
func (c *MatchClient) QueryStats(m *Match) *StatsQuery {
query := &StatsQuery{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.Edge(sqlgraph.O2M, false, match.StatsTable, match.StatsColumn),
)
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryPlayers queries the players edge of a Match.
func (c *MatchClient) QueryPlayers(m *Match) *PlayerQuery {
query := &PlayerQuery{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(player.Table, player.FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, match.PlayersTable, match.PlayersPrimaryKey...),
)
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *MatchClient) Hooks() []Hook {
return c.hooks.Match
}
// PlayerClient is a client for the Player schema.
type PlayerClient struct {
config
}
// NewPlayerClient returns a client for the Player from the given config.
func NewPlayerClient(c config) *PlayerClient {
return &PlayerClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `player.Hooks(f(g(h())))`.
func (c *PlayerClient) Use(hooks ...Hook) {
c.hooks.Player = append(c.hooks.Player, hooks...)
}
// Create returns a create builder for Player.
func (c *PlayerClient) Create() *PlayerCreate {
mutation := newPlayerMutation(c.config, OpCreate)
return &PlayerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Player entities.
func (c *PlayerClient) CreateBulk(builders ...*PlayerCreate) *PlayerCreateBulk {
return &PlayerCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Player.
func (c *PlayerClient) Update() *PlayerUpdate {
mutation := newPlayerMutation(c.config, OpUpdate)
return &PlayerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *PlayerClient) UpdateOne(pl *Player) *PlayerUpdateOne {
mutation := newPlayerMutation(c.config, OpUpdateOne, withPlayer(pl))
return &PlayerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *PlayerClient) UpdateOneID(id int) *PlayerUpdateOne {
mutation := newPlayerMutation(c.config, OpUpdateOne, withPlayerID(id))
return &PlayerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Player.
func (c *PlayerClient) Delete() *PlayerDelete {
mutation := newPlayerMutation(c.config, OpDelete)
return &PlayerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a delete builder for the given entity.
func (c *PlayerClient) DeleteOne(pl *Player) *PlayerDeleteOne {
return c.DeleteOneID(pl.ID)
}
// DeleteOneID returns a delete builder for the given id.
func (c *PlayerClient) DeleteOneID(id int) *PlayerDeleteOne {
builder := c.Delete().Where(player.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &PlayerDeleteOne{builder}
}
// Query returns a query builder for Player.
func (c *PlayerClient) Query() *PlayerQuery {
return &PlayerQuery{
config: c.config,
}
}
// Get returns a Player entity by its id.
func (c *PlayerClient) Get(ctx context.Context, id int) (*Player, error) {
return c.Query().Where(player.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *PlayerClient) GetX(ctx context.Context, id int) *Player {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryStats queries the stats edge of a Player.
func (c *PlayerClient) QueryStats(pl *Player) *StatsQuery {
query := &StatsQuery{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.Edge(sqlgraph.O2M, false, player.StatsTable, player.StatsColumn),
)
fromV = sqlgraph.Neighbors(pl.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryMatches queries the matches edge of a Player.
func (c *PlayerClient) QueryMatches(pl *Player) *MatchQuery {
query := &MatchQuery{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(match.Table, match.FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, player.MatchesTable, player.MatchesPrimaryKey...),
)
fromV = sqlgraph.Neighbors(pl.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *PlayerClient) Hooks() []Hook {
return c.hooks.Player
}
// StatsClient is a client for the Stats schema.
type StatsClient struct {
config
}
// NewStatsClient returns a client for the Stats from the given config.
func NewStatsClient(c config) *StatsClient {
return &StatsClient{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...)
}
// 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}
}
// 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}
}
// 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}
}
// 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}
}
// 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}
}
// 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}
}
// DeleteOne returns a delete builder for the given entity.
func (c *StatsClient) DeleteOne(s *Stats) *StatsDeleteOne {
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))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &StatsDeleteOne{builder}
}
// Query returns a query builder for Stats.
func (c *StatsClient) Query() *StatsQuery {
return &StatsQuery{
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)
}
// GetX is like Get, but panics if an error occurs.
func (c *StatsClient) GetX(ctx context.Context, id int) *Stats {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryMatches queries the matches edge of a Stats.
func (c *StatsClient) QueryMatches(s *Stats) *MatchQuery {
query := &MatchQuery{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
}
// Hooks returns the client hooks.
func (c *StatsClient) Hooks() []Hook {
return c.hooks.Stats
}

61
ent/config.go Normal file
View File

@@ -0,0 +1,61 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"entgo.io/ent"
"entgo.io/ent/dialect"
)
// Option function to configure the client.
type Option func(*config)
// Config is the configuration for the client and its builder.
type config struct {
// driver used for executing database requests.
driver dialect.Driver
// debug enable a debug logging.
debug bool
// log used for logging on debug mode.
log func(...interface{})
// hooks to execute on mutations.
hooks *hooks
}
// hooks per client, for fast access.
type hooks struct {
Match []ent.Hook
Player []ent.Hook
Stats []ent.Hook
}
// Options applies the options on the config object.
func (c *config) options(opts ...Option) {
for _, opt := range opts {
opt(c)
}
if c.debug {
c.driver = dialect.Debug(c.driver, c.log)
}
}
// Debug enables debug logging on the ent.Driver.
func Debug() Option {
return func(c *config) {
c.debug = true
}
}
// Log sets the logging function for debug mode.
func Log(fn func(...interface{})) Option {
return func(c *config) {
c.log = fn
}
}
// Driver configures the client driver.
func Driver(driver dialect.Driver) Option {
return func(c *config) {
c.driver = driver
}
}

33
ent/context.go Normal file
View File

@@ -0,0 +1,33 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
)
type clientCtxKey struct{}
// FromContext returns a Client stored inside a context, or nil if there isn't one.
func FromContext(ctx context.Context) *Client {
c, _ := ctx.Value(clientCtxKey{}).(*Client)
return c
}
// NewContext returns a new context with the given Client attached.
func NewContext(parent context.Context, c *Client) context.Context {
return context.WithValue(parent, clientCtxKey{}, c)
}
type txCtxKey struct{}
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
func TxFromContext(ctx context.Context) *Tx {
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
return tx
}
// NewTxContext returns a new context with the given Tx attached.
func NewTxContext(parent context.Context, tx *Tx) context.Context {
return context.WithValue(parent, txCtxKey{}, tx)
}

263
ent/ent.go Normal file
View File

@@ -0,0 +1,263 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"csgowtfd/ent/match"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"errors"
"fmt"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// ent aliases to avoid import conflicts in user's code.
type (
Op = ent.Op
Hook = ent.Hook
Value = ent.Value
Query = ent.Query
Policy = ent.Policy
Mutator = ent.Mutator
Mutation = ent.Mutation
MutateFunc = ent.MutateFunc
)
// OrderFunc applies an ordering on the sql selector.
type OrderFunc func(*sql.Selector)
// columnChecker returns a function indicates if the column exists in the given column.
func columnChecker(table string) func(string) error {
checks := map[string]func(string) bool{
match.Table: match.ValidColumn,
player.Table: player.ValidColumn,
stats.Table: stats.ValidColumn,
}
check, ok := checks[table]
if !ok {
return func(string) error {
return fmt.Errorf("unknown table %q", table)
}
}
return func(column string) error {
if !check(column) {
return fmt.Errorf("unknown column %q for table %q", column, table)
}
return nil
}
}
// Asc applies the given fields in ASC order.
func Asc(fields ...string) OrderFunc {
return func(s *sql.Selector) {
check := columnChecker(s.TableName())
for _, f := range fields {
if err := check(f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
}
s.OrderBy(sql.Asc(s.C(f)))
}
}
}
// Desc applies the given fields in DESC order.
func Desc(fields ...string) OrderFunc {
return func(s *sql.Selector) {
check := columnChecker(s.TableName())
for _, f := range fields {
if err := check(f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
}
s.OrderBy(sql.Desc(s.C(f)))
}
}
}
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
type AggregateFunc func(*sql.Selector) string
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
//
// GroupBy(field1, field2).
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
// Scan(ctx, &v)
//
func As(fn AggregateFunc, end string) AggregateFunc {
return func(s *sql.Selector) string {
return sql.As(fn(s), end)
}
}
// Count applies the "count" aggregation function on each group.
func Count() AggregateFunc {
return func(s *sql.Selector) string {
return sql.Count("*")
}
}
// Max applies the "max" aggregation function on the given field of each group.
func Max(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Max(s.C(field))
}
}
// Mean applies the "mean" aggregation function on the given field of each group.
func Mean(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Avg(s.C(field))
}
}
// Min applies the "min" aggregation function on the given field of each group.
func Min(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Min(s.C(field))
}
}
// Sum applies the "sum" aggregation function on the given field of each group.
func Sum(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Sum(s.C(field))
}
}
// ValidationError returns when validating a field fails.
type ValidationError struct {
Name string // Field or edge name.
err error
}
// Error implements the error interface.
func (e *ValidationError) Error() string {
return e.err.Error()
}
// Unwrap implements the errors.Wrapper interface.
func (e *ValidationError) Unwrap() error {
return e.err
}
// IsValidationError returns a boolean indicating whether the error is a validation error.
func IsValidationError(err error) bool {
if err == nil {
return false
}
var e *ValidationError
return errors.As(err, &e)
}
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
type NotFoundError struct {
label string
}
// Error implements the error interface.
func (e *NotFoundError) Error() string {
return "ent: " + e.label + " not found"
}
// IsNotFound returns a boolean indicating whether the error is a not found error.
func IsNotFound(err error) bool {
if err == nil {
return false
}
var e *NotFoundError
return errors.As(err, &e)
}
// MaskNotFound masks not found error.
func MaskNotFound(err error) error {
if IsNotFound(err) {
return nil
}
return err
}
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
type NotSingularError struct {
label string
}
// Error implements the error interface.
func (e *NotSingularError) Error() string {
return "ent: " + e.label + " not singular"
}
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
func IsNotSingular(err error) bool {
if err == nil {
return false
}
var e *NotSingularError
return errors.As(err, &e)
}
// NotLoadedError returns when trying to get a node that was not loaded by the query.
type NotLoadedError struct {
edge string
}
// Error implements the error interface.
func (e *NotLoadedError) Error() string {
return "ent: " + e.edge + " edge was not loaded"
}
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
func IsNotLoaded(err error) bool {
if err == nil {
return false
}
var e *NotLoadedError
return errors.As(err, &e)
}
// ConstraintError returns when trying to create/update one or more entities and
// one or more of their constraints failed. For example, violation of edge or
// field uniqueness.
type ConstraintError struct {
msg string
wrap error
}
// Error implements the error interface.
func (e ConstraintError) Error() string {
return "ent: constraint failed: " + e.msg
}
// Unwrap implements the errors.Wrapper interface.
func (e *ConstraintError) Unwrap() error {
return e.wrap
}
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
func IsConstraintError(err error) bool {
if err == nil {
return false
}
var e *ConstraintError
return errors.As(err, &e)
}

77
ent/enttest/enttest.go Normal file
View File

@@ -0,0 +1,77 @@
// Code generated by entc, DO NOT EDIT.
package enttest
import (
"context"
"csgowtfd/ent"
// required by schema hooks.
_ "csgowtfd/ent/runtime"
"entgo.io/ent/dialect/sql/schema"
)
type (
// TestingT is the interface that is shared between
// testing.T and testing.B and used by enttest.
TestingT interface {
FailNow()
Error(...interface{})
}
// Option configures client creation.
Option func(*options)
options struct {
opts []ent.Option
migrateOpts []schema.MigrateOption
}
)
// WithOptions forwards options to client creation.
func WithOptions(opts ...ent.Option) Option {
return func(o *options) {
o.opts = append(o.opts, opts...)
}
}
// WithMigrateOptions forwards options to auto migration.
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
return func(o *options) {
o.migrateOpts = append(o.migrateOpts, opts...)
}
}
func newOptions(opts []Option) *options {
o := &options{}
for _, opt := range opts {
opt(o)
}
return o
}
// Open calls ent.Open and auto-run migration.
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
o := newOptions(opts)
c, err := ent.Open(driverName, dataSourceName, o.opts...)
if err != nil {
t.Error(err)
t.FailNow()
}
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
t.Error(err)
t.FailNow()
}
return c
}
// NewClient calls ent.NewClient and auto-run migration.
func NewClient(t TestingT, opts ...Option) *ent.Client {
o := newOptions(opts)
c := ent.NewClient(o.opts...)
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
t.Error(err)
t.FailNow()
}
return c
}

3
ent/generate.go Normal file
View File

@@ -0,0 +1,3 @@
package ent
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema

229
ent/hook/hook.go Normal file
View File

@@ -0,0 +1,229 @@
// Code generated by entc, DO NOT EDIT.
package hook
import (
"context"
"csgowtfd/ent"
"fmt"
)
// The MatchFunc type is an adapter to allow the use of ordinary
// function as Match mutator.
type MatchFunc func(context.Context, *ent.MatchMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f MatchFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.MatchMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MatchMutation", 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)
// Mutate calls f(ctx, m).
func (f PlayerFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.PlayerMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PlayerMutation", m)
}
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)
// Mutate calls f(ctx, m).
func (f StatsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.StatsMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StatsMutation", m)
}
return f(ctx, mv)
}
// Condition is a hook condition function.
type Condition func(context.Context, ent.Mutation) bool
// And groups conditions with the AND operator.
func And(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if !first(ctx, m) || !second(ctx, m) {
return false
}
for _, cond := range rest {
if !cond(ctx, m) {
return false
}
}
return true
}
}
// Or groups conditions with the OR operator.
func Or(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if first(ctx, m) || second(ctx, m) {
return true
}
for _, cond := range rest {
if cond(ctx, m) {
return true
}
}
return false
}
}
// Not negates a given condition.
func Not(cond Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
return !cond(ctx, m)
}
}
// HasOp is a condition testing mutation operation.
func HasOp(op ent.Op) Condition {
return func(_ context.Context, m ent.Mutation) bool {
return m.Op().Is(op)
}
}
// HasAddedFields is a condition validating `.AddedField` on fields.
func HasAddedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.AddedField(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.AddedField(field); !exists {
return false
}
}
return true
}
}
// HasClearedFields is a condition validating `.FieldCleared` on fields.
func HasClearedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if exists := m.FieldCleared(field); !exists {
return false
}
for _, field := range fields {
if exists := m.FieldCleared(field); !exists {
return false
}
}
return true
}
}
// HasFields is a condition validating `.Field` on fields.
func HasFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.Field(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.Field(field); !exists {
return false
}
}
return true
}
}
// If executes the given hook under condition.
//
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
//
func If(hk ent.Hook, cond Condition) ent.Hook {
return func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if cond(ctx, m) {
return hk(next).Mutate(ctx, m)
}
return next.Mutate(ctx, m)
})
}
}
// On executes the given hook only for the given operation.
//
// hook.On(Log, ent.Delete|ent.Create)
//
func On(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, HasOp(op))
}
// Unless skips the given hook only for the given operation.
//
// hook.Unless(Log, ent.Update|ent.UpdateOne)
//
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, Not(HasOp(op)))
}
// FixedError is a hook returning a fixed error.
func FixedError(err error) ent.Hook {
return func(ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
return nil, err
})
}
}
// Reject returns a hook that rejects all operations that match op.
//
// func (T) Hooks() []ent.Hook {
// return []ent.Hook{
// Reject(ent.Delete|ent.Update),
// }
// }
//
func Reject(op ent.Op) ent.Hook {
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
return On(hk, op)
}
// Chain acts as a list of hooks and is effectively immutable.
// Once created, it will always hold the same set of hooks in the same order.
type Chain struct {
hooks []ent.Hook
}
// NewChain creates a new chain of hooks.
func NewChain(hooks ...ent.Hook) Chain {
return Chain{append([]ent.Hook(nil), hooks...)}
}
// Hook chains the list of hooks and returns the final hook.
func (c Chain) Hook() ent.Hook {
return func(mutator ent.Mutator) ent.Mutator {
for i := len(c.hooks) - 1; i >= 0; i-- {
mutator = c.hooks[i](mutator)
}
return mutator
}
}
// Append extends a chain, adding the specified hook
// as the last ones in the mutation flow.
func (c Chain) Append(hooks ...ent.Hook) Chain {
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
newHooks = append(newHooks, c.hooks...)
newHooks = append(newHooks, hooks...)
return Chain{newHooks}
}
// Extend extends a chain, adding the specified chain
// as the last ones in the mutation flow.
func (c Chain) Extend(chain Chain) Chain {
return c.Append(chain.hooks...)
}

277
ent/match.go Normal file
View File

@@ -0,0 +1,277 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"csgowtfd/ent/match"
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent/dialect/sql"
)
// Match is the model entity for the Match schema.
type Match struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// MatchID holds the value of the "match_id" field.
MatchID uint64 `json:"match_id,string"`
// ShareCode holds the value of the "share_code" field.
ShareCode string `json:"share_code,omitempty"`
// Map holds the value of the "map" field.
Map string `json:"map,omitempty"`
// Date holds the value of the "date" field.
Date time.Time `json:"date,omitempty"`
// ScoreTeamA holds the value of the "score_team_a" field.
ScoreTeamA int `json:"score_team_a,omitempty"`
// ScoreTeamB holds the value of the "score_team_b" field.
ScoreTeamB int `json:"score_team_b,omitempty"`
// ReplayURL holds the value of the "replay_url" field.
ReplayURL string `json:"-"`
// Duration holds the value of the "duration" field.
Duration int `json:"duration,omitempty"`
// MatchResult holds the value of the "match_result" field.
MatchResult int `json:"match_result,omitempty"`
// MaxRounds holds the value of the "max_rounds" field.
MaxRounds int `json:"max_rounds,omitempty"`
// DemoExpired holds the value of the "demo_expired" field.
DemoExpired bool `json:"demo_expired,omitempty"`
// DemoParsed holds the value of the "demo_parsed" field.
DemoParsed bool `json:"demo_parsed,omitempty"`
// Eco holds the value of the "eco" field.
Eco struct {
Rounds []*struct {
Team int "json:\"team\""
Bank int "json:\"bank\""
Equipment int "json:\"equipment\""
} "json:\"rounds\""
} `json:"eco,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MatchQuery when eager-loading is set.
Edges MatchEdges `json:"edges"`
}
// 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"`
// Players holds the value of the players edge.
Players []*Player `json:"players,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// StatsOrErr returns the Stats value or an error if the edge
// was not loaded in eager-loading.
func (e MatchEdges) StatsOrErr() ([]*Stats, error) {
if e.loadedTypes[0] {
return e.Stats, nil
}
return nil, &NotLoadedError{edge: "stats"}
}
// PlayersOrErr returns the Players value or an error if the edge
// was not loaded in eager-loading.
func (e MatchEdges) PlayersOrErr() ([]*Player, error) {
if e.loadedTypes[1] {
return e.Players, nil
}
return nil, &NotLoadedError{edge: "players"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Match) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case match.FieldEco:
values[i] = new([]byte)
case match.FieldDemoExpired, match.FieldDemoParsed:
values[i] = new(sql.NullBool)
case match.FieldID, match.FieldMatchID, match.FieldScoreTeamA, match.FieldScoreTeamB, match.FieldDuration, match.FieldMatchResult, match.FieldMaxRounds:
values[i] = new(sql.NullInt64)
case match.FieldShareCode, match.FieldMap, match.FieldReplayURL:
values[i] = new(sql.NullString)
case match.FieldDate:
values[i] = new(sql.NullTime)
default:
return nil, fmt.Errorf("unexpected column %q for type Match", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Match fields.
func (m *Match) 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 match.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
m.ID = int(value.Int64)
case match.FieldMatchID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field match_id", values[i])
} else if value.Valid {
m.MatchID = uint64(value.Int64)
}
case match.FieldShareCode:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field share_code", values[i])
} else if value.Valid {
m.ShareCode = value.String
}
case match.FieldMap:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field map", values[i])
} else if value.Valid {
m.Map = value.String
}
case match.FieldDate:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field date", values[i])
} else if value.Valid {
m.Date = value.Time
}
case match.FieldScoreTeamA:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field score_team_a", values[i])
} else if value.Valid {
m.ScoreTeamA = int(value.Int64)
}
case match.FieldScoreTeamB:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field score_team_b", values[i])
} else if value.Valid {
m.ScoreTeamB = int(value.Int64)
}
case match.FieldReplayURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field replay_url", values[i])
} else if value.Valid {
m.ReplayURL = value.String
}
case match.FieldDuration:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field duration", values[i])
} else if value.Valid {
m.Duration = int(value.Int64)
}
case match.FieldMatchResult:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field match_result", values[i])
} else if value.Valid {
m.MatchResult = int(value.Int64)
}
case match.FieldMaxRounds:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field max_rounds", values[i])
} else if value.Valid {
m.MaxRounds = int(value.Int64)
}
case match.FieldDemoExpired:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field demo_expired", values[i])
} else if value.Valid {
m.DemoExpired = value.Bool
}
case match.FieldDemoParsed:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field demo_parsed", values[i])
} else if value.Valid {
m.DemoParsed = value.Bool
}
case match.FieldEco:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field eco", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &m.Eco); err != nil {
return fmt.Errorf("unmarshal field eco: %w", err)
}
}
}
}
return nil
}
// QueryStats queries the "stats" edge of the Match entity.
func (m *Match) QueryStats() *StatsQuery {
return (&MatchClient{config: m.config}).QueryStats(m)
}
// QueryPlayers queries the "players" edge of the Match entity.
func (m *Match) QueryPlayers() *PlayerQuery {
return (&MatchClient{config: m.config}).QueryPlayers(m)
}
// Update returns a builder for updating this Match.
// Note that you need to call Match.Unwrap() before calling this method if this Match
// was returned from a transaction, and the transaction was committed or rolled back.
func (m *Match) Update() *MatchUpdateOne {
return (&MatchClient{config: m.config}).UpdateOne(m)
}
// Unwrap unwraps the Match 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 (m *Match) Unwrap() *Match {
tx, ok := m.config.driver.(*txDriver)
if !ok {
panic("ent: Match is not a transactional entity")
}
m.config.driver = tx.drv
return m
}
// String implements the fmt.Stringer.
func (m *Match) String() string {
var builder strings.Builder
builder.WriteString("Match(")
builder.WriteString(fmt.Sprintf("id=%v", m.ID))
builder.WriteString(", match_id=")
builder.WriteString(fmt.Sprintf("%v", m.MatchID))
builder.WriteString(", share_code=")
builder.WriteString(m.ShareCode)
builder.WriteString(", map=")
builder.WriteString(m.Map)
builder.WriteString(", date=")
builder.WriteString(m.Date.Format(time.ANSIC))
builder.WriteString(", score_team_a=")
builder.WriteString(fmt.Sprintf("%v", m.ScoreTeamA))
builder.WriteString(", score_team_b=")
builder.WriteString(fmt.Sprintf("%v", m.ScoreTeamB))
builder.WriteString(", replay_url=")
builder.WriteString(m.ReplayURL)
builder.WriteString(", duration=")
builder.WriteString(fmt.Sprintf("%v", m.Duration))
builder.WriteString(", match_result=")
builder.WriteString(fmt.Sprintf("%v", m.MatchResult))
builder.WriteString(", max_rounds=")
builder.WriteString(fmt.Sprintf("%v", m.MaxRounds))
builder.WriteString(", demo_expired=")
builder.WriteString(fmt.Sprintf("%v", m.DemoExpired))
builder.WriteString(", demo_parsed=")
builder.WriteString(fmt.Sprintf("%v", m.DemoParsed))
builder.WriteString(", eco=")
builder.WriteString(fmt.Sprintf("%v", m.Eco))
builder.WriteByte(')')
return builder.String()
}
// Matches is a parsable slice of Match.
type Matches []*Match
func (m Matches) config(cfg config) {
for _i := range m {
m[_i].config = cfg
}
}

95
ent/match/match.go Normal file
View File

@@ -0,0 +1,95 @@
// Code generated by entc, DO NOT EDIT.
package match
const (
// Label holds the string label denoting the match type in the database.
Label = "match"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldMatchID holds the string denoting the match_id field in the database.
FieldMatchID = "match_id"
// FieldShareCode holds the string denoting the share_code field in the database.
FieldShareCode = "share_code"
// FieldMap holds the string denoting the map field in the database.
FieldMap = "map"
// FieldDate holds the string denoting the date field in the database.
FieldDate = "date"
// FieldScoreTeamA holds the string denoting the score_team_a field in the database.
FieldScoreTeamA = "score_team_a"
// FieldScoreTeamB holds the string denoting the score_team_b field in the database.
FieldScoreTeamB = "score_team_b"
// FieldReplayURL holds the string denoting the replay_url field in the database.
FieldReplayURL = "replay_url"
// FieldDuration holds the string denoting the duration field in the database.
FieldDuration = "duration"
// FieldMatchResult holds the string denoting the match_result field in the database.
FieldMatchResult = "match_result"
// FieldMaxRounds holds the string denoting the max_rounds field in the database.
FieldMaxRounds = "max_rounds"
// FieldDemoExpired holds the string denoting the demo_expired field in the database.
FieldDemoExpired = "demo_expired"
// FieldDemoParsed holds the string denoting the demo_parsed field in the database.
FieldDemoParsed = "demo_parsed"
// FieldEco holds the string denoting the eco field in the database.
FieldEco = "eco"
// EdgeStats holds the string denoting the stats edge name in mutations.
EdgeStats = "stats"
// EdgePlayers holds the string denoting the players edge name in mutations.
EdgePlayers = "players"
// 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"
// 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.
PlayersTable = "player_matches"
// 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"
)
// Columns holds all SQL columns for match fields.
var Columns = []string{
FieldID,
FieldMatchID,
FieldShareCode,
FieldMap,
FieldDate,
FieldScoreTeamA,
FieldScoreTeamB,
FieldReplayURL,
FieldDuration,
FieldMatchResult,
FieldMaxRounds,
FieldDemoExpired,
FieldDemoParsed,
FieldEco,
}
var (
// PlayersPrimaryKey and PlayersColumn2 are the table columns denoting the
// primary key for the players relation (M2M).
PlayersPrimaryKey = []string{"player_id", "match_id"}
)
// 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
}
}
return false
}
var (
// DefaultDemoExpired holds the default value on creation for the "demo_expired" field.
DefaultDemoExpired bool
// DefaultDemoParsed holds the default value on creation for the "demo_parsed" field.
DefaultDemoParsed bool
)

1201
ent/match/where.go Normal file

File diff suppressed because it is too large Load Diff

552
ent/match_create.go Normal file
View File

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

111
ent/match_delete.go Normal file
View File

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

1089
ent/match_query.go Normal file

File diff suppressed because it is too large Load Diff

1229
ent/match_update.go Normal file

File diff suppressed because it is too large Load Diff

72
ent/migrate/migrate.go Normal file
View File

@@ -0,0 +1,72 @@
// Code generated by entc, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
var (
// WithGlobalUniqueID sets the universal ids options to the migration.
// If this option is enabled, ent migration will allocate a 1<<32 range
// for the ids of each entity (table).
// Note that this option cannot be applied on tables that already exist.
WithGlobalUniqueID = schema.WithGlobalUniqueID
// WithDropColumn sets the drop column option to the migration.
// If this option is enabled, ent migration will drop old columns
// that were used for both fields and edges. This defaults to false.
WithDropColumn = schema.WithDropColumn
// WithDropIndex sets the drop index option to the migration.
// If this option is enabled, ent migration will drop old indexes
// that were defined in the schema. This defaults to false.
// Note that unique constraints are defined using `UNIQUE INDEX`,
// and therefore, it's recommended to enable this option to get more
// flexibility in the schema changes.
WithDropIndex = schema.WithDropIndex
// WithFixture sets the foreign-key renaming option to the migration when upgrading
// ent from v0.1.0 (issue-#285). Defaults to false.
WithFixture = schema.WithFixture
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
WithForeignKeys = schema.WithForeignKeys
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
universalID bool
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, Tables...)
}
// WriteTo writes the schema changes to w instead of running them against the database.
//
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
// log.Fatal(err)
// }
//
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
drv := &schema.WriteDriver{
Writer: w,
Driver: s.drv,
}
migrate, err := schema.NewMigrate(drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, Tables...)
}

128
ent/migrate/schema.go Normal file
View File

@@ -0,0 +1,128 @@
// Code generated by entc, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// MatchesColumns holds the columns for the "matches" table.
MatchesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "match_id", Type: field.TypeUint64, Unique: true},
{Name: "share_code", Type: field.TypeString},
{Name: "map", Type: field.TypeString, Nullable: true},
{Name: "date", Type: field.TypeTime},
{Name: "score_team_a", Type: field.TypeInt},
{Name: "score_team_b", Type: field.TypeInt},
{Name: "replay_url", Type: field.TypeString, Nullable: true},
{Name: "duration", Type: field.TypeInt},
{Name: "match_result", Type: field.TypeInt},
{Name: "max_rounds", Type: field.TypeInt},
{Name: "demo_expired", Type: field.TypeBool, Default: false},
{Name: "demo_parsed", Type: field.TypeBool, Default: false},
{Name: "eco", Type: field.TypeJSON, Nullable: true},
}
// MatchesTable holds the schema information for the "matches" table.
MatchesTable = &schema.Table{
Name: "matches",
Columns: MatchesColumns,
PrimaryKey: []*schema.Column{MatchesColumns[0]},
}
// PlayersColumns holds the columns for the "players" table.
PlayersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "steamid", Type: field.TypeUint64, Unique: true},
{Name: "name", Type: field.TypeString, Nullable: true},
{Name: "avatar_url", Type: field.TypeString, Nullable: true},
{Name: "vanity_url", Type: field.TypeString, Nullable: true},
{Name: "vanity_url_real", Type: field.TypeString, Nullable: true},
{Name: "vac", Type: field.TypeBool, Default: false},
{Name: "vac_date", Type: field.TypeTime, Nullable: true},
{Name: "vac_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},
}
// PlayersTable holds the schema information for the "players" table.
PlayersTable = &schema.Table{
Name: "players",
Columns: PlayersColumns,
PrimaryKey: []*schema.Column{PlayersColumns[0]},
}
// StatsColumns holds the columns for the "stats" table.
StatsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "team_id", Type: field.TypeInt},
{Name: "kills", Type: field.TypeInt},
{Name: "deaths", Type: field.TypeInt},
{Name: "assists", Type: field.TypeInt},
{Name: "headshot", Type: field.TypeInt},
{Name: "mvp", Type: field.TypeInt},
{Name: "score", Type: field.TypeInt},
{Name: "extended", Type: field.TypeJSON, Nullable: true},
{Name: "match_stats", Type: field.TypeInt, Nullable: true},
{Name: "player_stats", Type: field.TypeInt, Nullable: true},
}
// StatsTable holds the schema information for the "stats" table.
StatsTable = &schema.Table{
Name: "stats",
Columns: StatsColumns,
PrimaryKey: []*schema.Column{StatsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "stats_matches_stats",
Columns: []*schema.Column{StatsColumns[9]},
RefColumns: []*schema.Column{MatchesColumns[0]},
OnDelete: schema.SetNull,
},
{
Symbol: "stats_players_stats",
Columns: []*schema.Column{StatsColumns[10]},
RefColumns: []*schema.Column{PlayersColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// PlayerMatchesColumns holds the columns for the "player_matches" table.
PlayerMatchesColumns = []*schema.Column{
{Name: "player_id", Type: field.TypeInt},
{Name: "match_id", Type: field.TypeInt},
}
// PlayerMatchesTable holds the schema information for the "player_matches" table.
PlayerMatchesTable = &schema.Table{
Name: "player_matches",
Columns: PlayerMatchesColumns,
PrimaryKey: []*schema.Column{PlayerMatchesColumns[0], PlayerMatchesColumns[1]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "player_matches_player_id",
Columns: []*schema.Column{PlayerMatchesColumns[0]},
RefColumns: []*schema.Column{PlayersColumns[0]},
OnDelete: schema.Cascade,
},
{
Symbol: "player_matches_match_id",
Columns: []*schema.Column{PlayerMatchesColumns[1]},
RefColumns: []*schema.Column{MatchesColumns[0]},
OnDelete: schema.Cascade,
},
},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
MatchesTable,
PlayersTable,
StatsTable,
PlayerMatchesTable,
}
)
func init() {
StatsTable.ForeignKeys[0].RefTable = MatchesTable
StatsTable.ForeignKeys[1].RefTable = PlayersTable
PlayerMatchesTable.ForeignKeys[0].RefTable = PlayersTable
PlayerMatchesTable.ForeignKeys[1].RefTable = MatchesTable
}

3959
ent/mutation.go Normal file

File diff suppressed because it is too large Load Diff

245
ent/player.go Normal file
View File

@@ -0,0 +1,245 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"csgowtfd/ent/player"
"fmt"
"strings"
"time"
"entgo.io/ent/dialect/sql"
)
// Player is the model entity for the Player schema.
type Player struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Steamid holds the value of the "steamid" field.
Steamid uint64 `json:",string"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// AvatarURL holds the value of the "avatar_url" field.
AvatarURL string `json:"avatar_url,omitempty"`
// VanityURL holds the value of the "vanity_url" field.
VanityURL string `json:"vanity_url,omitempty"`
// VanityURLReal holds the value of the "vanity_url_real" field.
VanityURLReal string `json:"vanity_url_real,omitempty"`
// Vac holds the value of the "vac" field.
Vac bool `json:"vac,omitempty"`
// VacDate holds the value of the "vac_date" field.
VacDate time.Time `json:"vac_date,omitempty"`
// VacCount holds the value of the "vac_count" field.
VacCount int `json:"vac_count,omitempty"`
// SteamUpdated holds the value of the "steam_updated" field.
SteamUpdated time.Time `json:"-"`
// SharecodeUpdated holds the value of the "sharecode_updated" field.
SharecodeUpdated time.Time `json:"-"`
// AuthCode holds the value of the "auth_code" field.
AuthCode string `json:"-"`
// 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"`
}
// 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"`
// Matches holds the value of the matches edge.
Matches []*Match `json:"matches,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// StatsOrErr returns the Stats value or an error if the edge
// was not loaded in eager-loading.
func (e PlayerEdges) StatsOrErr() ([]*Stats, error) {
if e.loadedTypes[0] {
return e.Stats, nil
}
return nil, &NotLoadedError{edge: "stats"}
}
// MatchesOrErr returns the Matches value or an error if the edge
// was not loaded in eager-loading.
func (e PlayerEdges) MatchesOrErr() ([]*Match, error) {
if e.loadedTypes[1] {
return e.Matches, nil
}
return nil, &NotLoadedError{edge: "matches"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Player) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case player.FieldVac:
values[i] = new(sql.NullBool)
case player.FieldID, player.FieldSteamid, player.FieldVacCount:
values[i] = new(sql.NullInt64)
case player.FieldName, player.FieldAvatarURL, player.FieldVanityURL, player.FieldVanityURLReal, player.FieldAuthCode:
values[i] = new(sql.NullString)
case player.FieldVacDate, player.FieldSteamUpdated, player.FieldSharecodeUpdated:
values[i] = new(sql.NullTime)
default:
return nil, fmt.Errorf("unexpected column %q for type Player", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Player fields.
func (pl *Player) 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 player.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
pl.ID = int(value.Int64)
case player.FieldSteamid:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field steamid", values[i])
} else if value.Valid {
pl.Steamid = uint64(value.Int64)
}
case player.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
pl.Name = value.String
}
case player.FieldAvatarURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field avatar_url", values[i])
} else if value.Valid {
pl.AvatarURL = value.String
}
case player.FieldVanityURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field vanity_url", values[i])
} else if value.Valid {
pl.VanityURL = value.String
}
case player.FieldVanityURLReal:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field vanity_url_real", values[i])
} else if value.Valid {
pl.VanityURLReal = value.String
}
case player.FieldVac:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field vac", values[i])
} else if value.Valid {
pl.Vac = value.Bool
}
case player.FieldVacDate:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field vac_date", values[i])
} else if value.Valid {
pl.VacDate = value.Time
}
case player.FieldVacCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field vac_count", values[i])
} else if value.Valid {
pl.VacCount = int(value.Int64)
}
case player.FieldSteamUpdated:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field steam_updated", values[i])
} else if value.Valid {
pl.SteamUpdated = value.Time
}
case player.FieldSharecodeUpdated:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field sharecode_updated", values[i])
} else if value.Valid {
pl.SharecodeUpdated = value.Time
}
case player.FieldAuthCode:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field auth_code", values[i])
} else if value.Valid {
pl.AuthCode = value.String
}
}
}
return nil
}
// QueryStats queries the "stats" edge of the Player entity.
func (pl *Player) QueryStats() *StatsQuery {
return (&PlayerClient{config: pl.config}).QueryStats(pl)
}
// QueryMatches queries the "matches" edge of the Player entity.
func (pl *Player) QueryMatches() *MatchQuery {
return (&PlayerClient{config: pl.config}).QueryMatches(pl)
}
// Update returns a builder for updating this Player.
// Note that you need to call Player.Unwrap() before calling this method if this Player
// was returned from a transaction, and the transaction was committed or rolled back.
func (pl *Player) Update() *PlayerUpdateOne {
return (&PlayerClient{config: pl.config}).UpdateOne(pl)
}
// Unwrap unwraps the Player 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 (pl *Player) Unwrap() *Player {
tx, ok := pl.config.driver.(*txDriver)
if !ok {
panic("ent: Player is not a transactional entity")
}
pl.config.driver = tx.drv
return pl
}
// String implements the fmt.Stringer.
func (pl *Player) String() string {
var builder strings.Builder
builder.WriteString("Player(")
builder.WriteString(fmt.Sprintf("id=%v", pl.ID))
builder.WriteString(", steamid=")
builder.WriteString(fmt.Sprintf("%v", pl.Steamid))
builder.WriteString(", name=")
builder.WriteString(pl.Name)
builder.WriteString(", avatar_url=")
builder.WriteString(pl.AvatarURL)
builder.WriteString(", vanity_url=")
builder.WriteString(pl.VanityURL)
builder.WriteString(", vanity_url_real=")
builder.WriteString(pl.VanityURLReal)
builder.WriteString(", vac=")
builder.WriteString(fmt.Sprintf("%v", pl.Vac))
builder.WriteString(", vac_date=")
builder.WriteString(pl.VacDate.Format(time.ANSIC))
builder.WriteString(", vac_count=")
builder.WriteString(fmt.Sprintf("%v", pl.VacCount))
builder.WriteString(", steam_updated=")
builder.WriteString(pl.SteamUpdated.Format(time.ANSIC))
builder.WriteString(", sharecode_updated=")
builder.WriteString(pl.SharecodeUpdated.Format(time.ANSIC))
builder.WriteString(", auth_code=<sensitive>")
builder.WriteByte(')')
return builder.String()
}
// Players is a parsable slice of Player.
type Players []*Player
func (pl Players) config(cfg config) {
for _i := range pl {
pl[_i].config = cfg
}
}

93
ent/player/player.go Normal file
View File

@@ -0,0 +1,93 @@
// Code generated by entc, DO NOT EDIT.
package player
import (
"time"
)
const (
// Label holds the string label denoting the player type in the database.
Label = "player"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldSteamid holds the string denoting the steamid field in the database.
FieldSteamid = "steamid"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldAvatarURL holds the string denoting the avatar_url field in the database.
FieldAvatarURL = "avatar_url"
// FieldVanityURL holds the string denoting the vanity_url field in the database.
FieldVanityURL = "vanity_url"
// FieldVanityURLReal holds the string denoting the vanity_url_real field in the database.
FieldVanityURLReal = "vanity_url_real"
// FieldVac holds the string denoting the vac field in the database.
FieldVac = "vac"
// FieldVacDate holds the string denoting the vac_date field in the database.
FieldVacDate = "vac_date"
// FieldVacCount holds the string denoting the vac_count field in the database.
FieldVacCount = "vac_count"
// FieldSteamUpdated holds the string denoting the steam_updated field in the database.
FieldSteamUpdated = "steam_updated"
// FieldSharecodeUpdated holds the string denoting the sharecode_updated field in the database.
FieldSharecodeUpdated = "sharecode_updated"
// FieldAuthCode holds the string denoting the auth_code field in the database.
FieldAuthCode = "auth_code"
// EdgeStats holds the string denoting the stats edge name in mutations.
EdgeStats = "stats"
// EdgeMatches holds the string denoting the matches edge name in mutations.
EdgeMatches = "matches"
// 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"
// 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.
MatchesTable = "player_matches"
// 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"
)
// Columns holds all SQL columns for player fields.
var Columns = []string{
FieldID,
FieldSteamid,
FieldName,
FieldAvatarURL,
FieldVanityURL,
FieldVanityURLReal,
FieldVac,
FieldVacDate,
FieldVacCount,
FieldSteamUpdated,
FieldSharecodeUpdated,
FieldAuthCode,
}
var (
// MatchesPrimaryKey and MatchesColumn2 are the table columns denoting the
// primary key for the matches relation (M2M).
MatchesPrimaryKey = []string{"player_id", "match_id"}
)
// 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
}
}
return false
}
var (
// DefaultVac holds the default value on creation for the "vac" field.
DefaultVac bool
// DefaultSteamUpdated holds the default value on creation for the "steam_updated" field.
DefaultSteamUpdated func() time.Time
)

1320
ent/player/where.go Normal file

File diff suppressed because it is too large Load Diff

531
ent/player_create.go Normal file
View File

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

111
ent/player_delete.go Normal file
View File

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

1089
ent/player_query.go Normal file

File diff suppressed because it is too large Load Diff

1241
ent/player_update.go Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
// Code generated by entc, DO NOT EDIT.
package predicate
import (
"entgo.io/ent/dialect/sql"
)
// Match is the predicate function for match builders.
type Match func(*sql.Selector)
// Player is the predicate function for player builders.
type Player func(*sql.Selector)
// Stats is the predicate function for stats builders.
type Stats func(*sql.Selector)

36
ent/runtime.go Normal file
View File

@@ -0,0 +1,36 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"csgowtfd/ent/match"
"csgowtfd/ent/player"
"csgowtfd/ent/schema"
"time"
)
// The init function reads all schema descriptors with runtime code
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func init() {
matchFields := schema.Match{}.Fields()
_ = matchFields
// matchDescDemoExpired is the schema descriptor for demo_expired field.
matchDescDemoExpired := matchFields[10].Descriptor()
// match.DefaultDemoExpired holds the default value on creation for the demo_expired field.
match.DefaultDemoExpired = matchDescDemoExpired.Default.(bool)
// matchDescDemoParsed is the schema descriptor for demo_parsed field.
matchDescDemoParsed := matchFields[11].Descriptor()
// match.DefaultDemoParsed holds the default value on creation for the demo_parsed field.
match.DefaultDemoParsed = matchDescDemoParsed.Default.(bool)
playerFields := schema.Player{}.Fields()
_ = playerFields
// playerDescVac is the schema descriptor for vac field.
playerDescVac := playerFields[5].Descriptor()
// player.DefaultVac holds the default value on creation for the vac field.
player.DefaultVac = playerDescVac.Default.(bool)
// playerDescSteamUpdated is the schema descriptor for steam_updated field.
playerDescSteamUpdated := playerFields[8].Descriptor()
// player.DefaultSteamUpdated holds the default value on creation for the steam_updated field.
player.DefaultSteamUpdated = playerDescSteamUpdated.Default.(func() time.Time)
}

10
ent/runtime/runtime.go Normal file
View File

@@ -0,0 +1,10 @@
// Code generated by entc, DO NOT EDIT.
package runtime
// The schema-stitching logic is generated in csgowtfd/ent/runtime.go
const (
Version = "v0.9.1" // Version of ent codegen.
Sum = "h1:IG8andyeD79GG24U8Q+1Y45hQXj6gY5evSBcva5gtBk=" // Sum of ent codegen.
)

45
ent/schema/match.go Normal file
View File

@@ -0,0 +1,45 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Match holds the schema definition for the Match entity.
type Match struct {
ent.Schema
}
// Fields of the Match.
func (Match) Fields() []ent.Field {
return []ent.Field{
field.Uint64("match_id").Unique().Immutable().StructTag(`json:"match_id,string"`),
field.String("share_code"),
field.String("map").Optional(),
field.Time("date"),
field.Int("score_team_a"),
field.Int("score_team_b"),
field.String("replay_url").Optional().StructTag(`json:"-"`),
field.Int("duration"),
field.Int("match_result"),
field.Int("max_rounds"),
field.Bool("demo_expired").Default(false),
field.Bool("demo_parsed").Default(false),
field.JSON("eco", struct {
Rounds []*struct {
Team int `json:"team"`
Bank int `json:"bank"`
Equipment int `json:"equipment"`
} `json:"rounds"`
}{}).Optional(),
}
}
// Edges of the Match.
func (Match) Edges() []ent.Edge {
return []ent.Edge{
edge.To("stats", Stats.Type),
edge.From("players", Player.Type).Ref("matches"),
}
}

40
ent/schema/player.go Normal file
View File

@@ -0,0 +1,40 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Player holds the schema definition for the Player entity.
type Player struct {
ent.Schema
}
// Fields of the Player.
func (Player) Fields() []ent.Field {
return []ent.Field{
field.Uint64("steamid").Unique().Immutable().StructTag(`json:",string"`),
field.String("name").Optional(),
field.String("avatar_url").Optional(),
field.String("vanity_url").Optional(),
field.String("vanity_url_real").Optional(),
field.Bool("vac").Default(false),
field.Time("vac_date").Optional(),
field.Int("vac_count").Optional(),
field.Time("steam_updated").Default(func() time.Time {
return time.Now().UTC()
}).StructTag(`json:"-"`),
field.Time("sharecode_updated").Optional().StructTag(`json:"-"`),
field.String("auth_code").Optional().Sensitive(),
}
}
// Edges of the Player.
func (Player) Edges() []ent.Edge {
return []ent.Edge{
edge.To("stats", Stats.Type),
edge.To("matches", Match.Type),
}
}

81
ent/schema/stats.go Normal file
View File

@@ -0,0 +1,81 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Stats holds the schema definition for the Stats entity.
type Stats struct {
ent.Schema
}
// Fields of the Stats.
func (Stats) Fields() []ent.Field {
return []ent.Field{
field.Int("team_id"),
field.Int("kills"),
field.Int("deaths"),
field.Int("assists"),
field.Int("headshot"),
field.Int("mvp"),
field.Int("score"),
field.JSON("extended", struct {
MultiKills struct {
Duo int `json:"duo,omitempty"`
Triple int `json:"triple,omitempty"`
Quad int `json:"quad,omitempty"`
Pent int `json:"pent,omitempty"`
} `json:"multi_kills,omitempty"`
Dmg struct {
Enemy int `json:"enemy,omitempty"`
Team int `json:"team,omitempty"`
UD struct {
HE int `json:"he,omitempty"`
Flames int `json:"flames,omitempty"`
Flash int `json:"flash,omitempty"`
Decoy int `json:"decoy,omitempty"`
Smoke int `json:"smoke,omitempty"`
} `json:"ud,omitempty"`
HitGroup struct {
Head int `json:"head,omitempty"`
Chest int `json:"chest,omitempty"`
Stomach int `json:"stomach,omitempty"`
LeftArm int `json:"left_arm,omitempty"`
RightArm int `json:"right_arm,omitempty"`
LeftLeg int `json:"left_leg,omitempty"`
RightLeg int `json:"right_leg,omitempty"`
Gear int `json:"gear,omitempty"`
} `json:"hit_group,omitempty"`
} `json:"dmg,omitempty"`
Crosshair string `json:"crosshair,omitempty"`
Color int `json:"color,omitempty"`
KAST int `json:"kast,omitempty"`
Rank struct {
Old int `json:"old,omitempty"`
New int `json:"new,omitempty"`
} `json:"rank,omitempty"`
Flash struct {
Duration struct {
Self float32 `json:"self,omitempty"`
Team float32 `json:"team,omitempty"`
Enemy float32 `json:"enemy,omitempty"`
} `json:"duration,omitempty"`
Total struct {
Team int `json:"team,omitempty"`
Enemy int `json:"enemy,omitempty"`
Self int `json:"self,omitempty"`
} `json:"total,omitempty"`
} `json:"flash,omitempty"`
}{}).Optional(),
}
}
// Edges of the Stats.
func (Stats) Edges() []ent.Edge {
return []ent.Edge{
edge.From("matches", Match.Type).Ref("stats").Unique(),
edge.From("players", Player.Type).Ref("stats").Unique(),
}
}

293
ent/stats.go Normal file
View File

@@ -0,0 +1,293 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"csgowtfd/ent/match"
"csgowtfd/ent/player"
"csgowtfd/ent/stats"
"encoding/json"
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
)
// Stats is the model entity for the Stats schema.
type Stats struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// TeamID holds the value of the "team_id" field.
TeamID int `json:"team_id,omitempty"`
// Kills holds the value of the "kills" field.
Kills int `json:"kills,omitempty"`
// Deaths holds the value of the "deaths" field.
Deaths int `json:"deaths,omitempty"`
// Assists holds the value of the "assists" field.
Assists int `json:"assists,omitempty"`
// Headshot holds the value of the "headshot" field.
Headshot int `json:"headshot,omitempty"`
// Mvp holds the value of the "mvp" field.
Mvp int `json:"mvp,omitempty"`
// Score holds the value of the "score" field.
Score int `json:"score,omitempty"`
// Extended holds the value of the "extended" field.
Extended struct {
MultiKills struct {
Duo int "json:\"duo,omitempty\""
Triple int "json:\"triple,omitempty\""
Quad int "json:\"quad,omitempty\""
Pent int "json:\"pent,omitempty\""
} "json:\"multi_kills,omitempty\""
Dmg struct {
Enemy int "json:\"enemy,omitempty\""
Team int "json:\"team,omitempty\""
UD struct {
HE int "json:\"he,omitempty\""
Flames int "json:\"flames,omitempty\""
Flash int "json:\"flash,omitempty\""
Decoy int "json:\"decoy,omitempty\""
Smoke int "json:\"smoke,omitempty\""
} "json:\"ud,omitempty\""
HitGroup struct {
Head int "json:\"head,omitempty\""
Chest int "json:\"chest,omitempty\""
Stomach int "json:\"stomach,omitempty\""
LeftArm int "json:\"left_arm,omitempty\""
RightArm int "json:\"right_arm,omitempty\""
LeftLeg int "json:\"left_leg,omitempty\""
RightLeg int "json:\"right_leg,omitempty\""
Gear int "json:\"gear,omitempty\""
} "json:\"hit_group,omitempty\""
} "json:\"dmg,omitempty\""
Crosshair string "json:\"crosshair,omitempty\""
Color int "json:\"color,omitempty\""
KAST int "json:\"kast,omitempty\""
Rank struct {
Old int "json:\"old,omitempty\""
New int "json:\"new,omitempty\""
} "json:\"rank,omitempty\""
Flash struct {
Duration struct {
Self float32 "json:\"self,omitempty\""
Team float32 "json:\"team,omitempty\""
Enemy float32 "json:\"enemy,omitempty\""
} "json:\"duration,omitempty\""
Total struct {
Team int "json:\"team,omitempty\""
Enemy int "json:\"enemy,omitempty\""
Self int "json:\"self,omitempty\""
} "json:\"total,omitempty\""
} "json:\"flash,omitempty\""
} `json:"extended,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"`
match_stats *int
player_stats *int
}
// StatsEdges holds the relations/edges for other nodes in the graph.
type StatsEdges 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"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]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) {
if e.loadedTypes[0] {
if e.Matches == nil {
// The edge matches was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: match.Label}
}
return e.Matches, nil
}
return nil, &NotLoadedError{edge: "matches"}
}
// 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) {
if e.loadedTypes[1] {
if e.Players == nil {
// The edge players was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: player.Label}
}
return e.Players, nil
}
return nil, &NotLoadedError{edge: "players"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Stats) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case stats.FieldExtended:
values[i] = new([]byte)
case stats.FieldID, stats.FieldTeamID, stats.FieldKills, stats.FieldDeaths, stats.FieldAssists, stats.FieldHeadshot, stats.FieldMvp, stats.FieldScore:
values[i] = new(sql.NullInt64)
case stats.ForeignKeys[0]: // match_stats
values[i] = new(sql.NullInt64)
case stats.ForeignKeys[1]: // player_stats
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type Stats", 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 {
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:
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:
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)
}
case stats.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)
}
case stats.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)
}
case stats.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)
}
case stats.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)
}
case stats.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 = int(value.Int64)
}
case stats.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)
}
case stats.FieldExtended:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field extended", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &s.Extended); err != nil {
return fmt.Errorf("unmarshal field extended: %w", err)
}
}
case stats.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field match_stats", value)
} else if value.Valid {
s.match_stats = new(int)
*s.match_stats = int(value.Int64)
}
case stats.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field player_stats", value)
} else if value.Valid {
s.player_stats = new(int)
*s.player_stats = 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)
}
// QueryPlayers queries the "players" edge of the Stats entity.
func (s *Stats) QueryPlayers() *PlayerQuery {
return (&StatsClient{config: s.config}).QueryPlayers(s)
}
// Update returns a builder for updating this Stats.
// Note that you need to call Stats.Unwrap() before calling this method if this Stats
// 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)
}
// Unwrap unwraps the Stats 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)
if !ok {
panic("ent: Stats is not a transactional entity")
}
s.config.driver = tx.drv
return s
}
// String implements the fmt.Stringer.
func (s *Stats) String() string {
var builder strings.Builder
builder.WriteString("Stats(")
builder.WriteString(fmt.Sprintf("id=%v", s.ID))
builder.WriteString(", team_id=")
builder.WriteString(fmt.Sprintf("%v", s.TeamID))
builder.WriteString(", kills=")
builder.WriteString(fmt.Sprintf("%v", s.Kills))
builder.WriteString(", deaths=")
builder.WriteString(fmt.Sprintf("%v", s.Deaths))
builder.WriteString(", assists=")
builder.WriteString(fmt.Sprintf("%v", s.Assists))
builder.WriteString(", headshot=")
builder.WriteString(fmt.Sprintf("%v", s.Headshot))
builder.WriteString(", mvp=")
builder.WriteString(fmt.Sprintf("%v", s.Mvp))
builder.WriteString(", score=")
builder.WriteString(fmt.Sprintf("%v", s.Score))
builder.WriteString(", extended=")
builder.WriteString(fmt.Sprintf("%v", s.Extended))
builder.WriteByte(')')
return builder.String()
}
// StatsSlice is a parsable slice of Stats.
type StatsSlice []*Stats
func (s StatsSlice) config(cfg config) {
for _i := range s {
s[_i].config = cfg
}
}

81
ent/stats/stats.go Normal file
View File

@@ -0,0 +1,81 @@
// Code generated by entc, DO NOT EDIT.
package stats
const (
// Label holds the string label denoting the stats type in the database.
Label = "stats"
// 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.
FieldTeamID = "team_id"
// FieldKills holds the string denoting the kills field in the database.
FieldKills = "kills"
// FieldDeaths holds the string denoting the deaths field in the database.
FieldDeaths = "deaths"
// FieldAssists holds the string denoting the assists field in the database.
FieldAssists = "assists"
// FieldHeadshot holds the string denoting the headshot field in the database.
FieldHeadshot = "headshot"
// FieldMvp holds the string denoting the mvp field in the database.
FieldMvp = "mvp"
// FieldScore holds the string denoting the score field in the database.
FieldScore = "score"
// FieldExtended holds the string denoting the extended field in the database.
FieldExtended = "extended"
// EdgeMatches holds the string denoting the matches edge name in mutations.
EdgeMatches = "matches"
// EdgePlayers holds the string denoting the players edge name in mutations.
EdgePlayers = "players"
// Table holds the table name of the stats in the database.
Table = "stats"
// MatchesTable is the table that holds the matches relation/edge.
MatchesTable = "stats"
// 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"
// 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"
)
// Columns holds all SQL columns for stats fields.
var Columns = []string{
FieldID,
FieldTeamID,
FieldKills,
FieldDeaths,
FieldAssists,
FieldHeadshot,
FieldMvp,
FieldScore,
FieldExtended,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "stats"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"match_stats",
"player_stats",
}
// 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
}

776
ent/stats/where.go Normal file
View File

@@ -0,0 +1,776 @@
// Code generated by entc, DO NOT EDIT.
package stats
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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(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.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
})
}
// TeamID applies equality check predicate on the "team_id" field. It's identical to TeamIDEQ.
func TeamID(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldTeamID), v))
})
}
// Kills applies equality check predicate on the "kills" field. It's identical to KillsEQ.
func Kills(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldKills), v))
})
}
// Deaths applies equality check predicate on the "deaths" field. It's identical to DeathsEQ.
func Deaths(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldDeaths), v))
})
}
// Assists applies equality check predicate on the "assists" field. It's identical to AssistsEQ.
func Assists(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldAssists), v))
})
}
// Headshot applies equality check predicate on the "headshot" field. It's identical to HeadshotEQ.
func Headshot(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldHeadshot), v))
})
}
// Mvp applies equality check predicate on the "mvp" field. It's identical to MvpEQ.
func Mvp(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldMvp), v))
})
}
// Score applies equality check predicate on the "score" field. It's identical to ScoreEQ.
func Score(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldScore), v))
})
}
// TeamIDEQ applies the EQ predicate on the "team_id" field.
func TeamIDEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldTeamID), v))
})
}
// TeamIDNEQ applies the NEQ predicate on the "team_id" field.
func TeamIDNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldTeamID), v))
})
}
// TeamIDIn applies the In predicate on the "team_id" field.
func TeamIDIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldTeamID), v...))
})
}
// TeamIDNotIn applies the NotIn predicate on the "team_id" field.
func TeamIDNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldTeamID), v...))
})
}
// TeamIDGT applies the GT predicate on the "team_id" field.
func TeamIDGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldTeamID), v))
})
}
// TeamIDGTE applies the GTE predicate on the "team_id" field.
func TeamIDGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldTeamID), v))
})
}
// TeamIDLT applies the LT predicate on the "team_id" field.
func TeamIDLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldTeamID), v))
})
}
// TeamIDLTE applies the LTE predicate on the "team_id" field.
func TeamIDLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldTeamID), v))
})
}
// KillsEQ applies the EQ predicate on the "kills" field.
func KillsEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldKills), v))
})
}
// KillsNEQ applies the NEQ predicate on the "kills" field.
func KillsNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldKills), v))
})
}
// KillsIn applies the In predicate on the "kills" field.
func KillsIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldKills), v...))
})
}
// KillsNotIn applies the NotIn predicate on the "kills" field.
func KillsNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldKills), v...))
})
}
// KillsGT applies the GT predicate on the "kills" field.
func KillsGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldKills), v))
})
}
// KillsGTE applies the GTE predicate on the "kills" field.
func KillsGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldKills), v))
})
}
// KillsLT applies the LT predicate on the "kills" field.
func KillsLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldKills), v))
})
}
// KillsLTE applies the LTE predicate on the "kills" field.
func KillsLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldKills), v))
})
}
// DeathsEQ applies the EQ predicate on the "deaths" field.
func DeathsEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldDeaths), v))
})
}
// DeathsNEQ applies the NEQ predicate on the "deaths" field.
func DeathsNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldDeaths), v))
})
}
// DeathsIn applies the In predicate on the "deaths" field.
func DeathsIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldDeaths), v...))
})
}
// DeathsNotIn applies the NotIn predicate on the "deaths" field.
func DeathsNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldDeaths), v...))
})
}
// DeathsGT applies the GT predicate on the "deaths" field.
func DeathsGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldDeaths), v))
})
}
// DeathsGTE applies the GTE predicate on the "deaths" field.
func DeathsGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldDeaths), v))
})
}
// DeathsLT applies the LT predicate on the "deaths" field.
func DeathsLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldDeaths), v))
})
}
// DeathsLTE applies the LTE predicate on the "deaths" field.
func DeathsLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldDeaths), v))
})
}
// AssistsEQ applies the EQ predicate on the "assists" field.
func AssistsEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldAssists), v))
})
}
// AssistsNEQ applies the NEQ predicate on the "assists" field.
func AssistsNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldAssists), v))
})
}
// AssistsIn applies the In predicate on the "assists" field.
func AssistsIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldAssists), v...))
})
}
// AssistsNotIn applies the NotIn predicate on the "assists" field.
func AssistsNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldAssists), v...))
})
}
// AssistsGT applies the GT predicate on the "assists" field.
func AssistsGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldAssists), v))
})
}
// AssistsGTE applies the GTE predicate on the "assists" field.
func AssistsGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldAssists), v))
})
}
// AssistsLT applies the LT predicate on the "assists" field.
func AssistsLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldAssists), v))
})
}
// AssistsLTE applies the LTE predicate on the "assists" field.
func AssistsLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldAssists), v))
})
}
// HeadshotEQ applies the EQ predicate on the "headshot" field.
func HeadshotEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldHeadshot), v))
})
}
// HeadshotNEQ applies the NEQ predicate on the "headshot" field.
func HeadshotNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldHeadshot), v))
})
}
// HeadshotIn applies the In predicate on the "headshot" field.
func HeadshotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldHeadshot), v...))
})
}
// HeadshotNotIn applies the NotIn predicate on the "headshot" field.
func HeadshotNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldHeadshot), v...))
})
}
// HeadshotGT applies the GT predicate on the "headshot" field.
func HeadshotGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldHeadshot), v))
})
}
// HeadshotGTE applies the GTE predicate on the "headshot" field.
func HeadshotGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldHeadshot), v))
})
}
// HeadshotLT applies the LT predicate on the "headshot" field.
func HeadshotLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldHeadshot), v))
})
}
// HeadshotLTE applies the LTE predicate on the "headshot" field.
func HeadshotLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldHeadshot), v))
})
}
// MvpEQ applies the EQ predicate on the "mvp" field.
func MvpEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldMvp), v))
})
}
// MvpNEQ applies the NEQ predicate on the "mvp" field.
func MvpNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldMvp), v))
})
}
// MvpIn applies the In predicate on the "mvp" field.
func MvpIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldMvp), v...))
})
}
// MvpNotIn applies the NotIn predicate on the "mvp" field.
func MvpNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldMvp), v...))
})
}
// MvpGT applies the GT predicate on the "mvp" field.
func MvpGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldMvp), v))
})
}
// MvpGTE applies the GTE predicate on the "mvp" field.
func MvpGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldMvp), v))
})
}
// MvpLT applies the LT predicate on the "mvp" field.
func MvpLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldMvp), v))
})
}
// MvpLTE applies the LTE predicate on the "mvp" field.
func MvpLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldMvp), v))
})
}
// ScoreEQ applies the EQ predicate on the "score" field.
func ScoreEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldScore), v))
})
}
// ScoreNEQ applies the NEQ predicate on the "score" field.
func ScoreNEQ(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldScore), v))
})
}
// ScoreIn applies the In predicate on the "score" field.
func ScoreIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldScore), v...))
})
}
// ScoreNotIn applies the NotIn predicate on the "score" field.
func ScoreNotIn(vs ...int) predicate.Stats {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Stats(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(FieldScore), v...))
})
}
// ScoreGT applies the GT predicate on the "score" field.
func ScoreGT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldScore), v))
})
}
// ScoreGTE applies the GTE predicate on the "score" field.
func ScoreGTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldScore), v))
})
}
// ScoreLT applies the LT predicate on the "score" field.
func ScoreLT(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldScore), v))
})
}
// ScoreLTE applies the LTE predicate on the "score" field.
func ScoreLTE(v int) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldScore), v))
})
}
// ExtendedIsNil applies the IsNil predicate on the "extended" field.
func ExtendedIsNil() predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldExtended)))
})
}
// ExtendedNotNil applies the NotNil predicate on the "extended" field.
func ExtendedNotNil() predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldExtended)))
})
}
// HasMatches applies the HasEdge predicate on the "matches" edge.
func HasMatches() predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(MatchesTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, MatchesTable, MatchesColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasMatchesWith applies the HasEdge predicate on the "matches" edge with a given conditions (other predicates).
func HasMatchesWith(preds ...predicate.Match) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(MatchesInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, MatchesTable, MatchesColumn),
)
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasPlayers applies the HasEdge predicate on the "players" edge.
func HasPlayers() predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(PlayersTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, PlayersTable, PlayersColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasPlayersWith applies the HasEdge predicate on the "players" edge with a given conditions (other predicates).
func HasPlayersWith(preds ...predicate.Player) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(PlayersInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, PlayersTable, PlayersColumn),
)
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.Stats) predicate.Stats {
return predicate.Stats(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.Stats) predicate.Stats {
return predicate.Stats(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.Stats) predicate.Stats {
return predicate.Stats(func(s *sql.Selector) {
p(s.Not())
})
}

518
ent/stats_create.go Normal file
View File

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

111
ent/stats_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/stats"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StatsDelete is the builder for deleting a Stats entity.
type StatsDelete struct {
config
hooks []Hook
mutation *StatsMutation
}
// Where appends a list predicates to the StatsDelete builder.
func (sd *StatsDelete) Where(ps ...predicate.Stats) *StatsDelete {
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) {
var (
err error
affected int
)
if len(sd.hooks) == 0 {
affected, err = sd.sqlExec(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)
}
sd.mutation = mutation
affected, err = sd.sqlExec(ctx)
mutation.done = true
return affected, err
})
for i := len(sd.hooks) - 1; i >= 0; i-- {
if sd.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = sd.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, sd.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// ExecX is like Exec, but panics if an error occurs.
func (sd *StatsDelete) ExecX(ctx context.Context) int {
n, err := sd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (sd *StatsDelete) sqlExec(ctx context.Context) (int, error) {
_spec := &sqlgraph.DeleteSpec{
Node: &sqlgraph.NodeSpec{
Table: stats.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: stats.FieldID,
},
},
}
if ps := sd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
}
// StatsDeleteOne is the builder for deleting a single Stats entity.
type StatsDeleteOne struct {
sd *StatsDelete
}
// Exec executes the deletion query.
func (sdo *StatsDeleteOne) Exec(ctx context.Context) error {
n, err := sdo.sd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{stats.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (sdo *StatsDeleteOne) ExecX(ctx context.Context) {
sdo.sd.ExecX(ctx)
}

1060
ent/stats_query.go Normal file

File diff suppressed because it is too large Load Diff

1112
ent/stats_update.go Normal file

File diff suppressed because it is too large Load Diff

216
ent/tx.go Normal file
View File

@@ -0,0 +1,216 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"sync"
"entgo.io/ent/dialect"
)
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// Match is the client for interacting with the Match builders.
Match *MatchClient
// Player is the client for interacting with the Player builders.
Player *PlayerClient
// Stats is the client for interacting with the Stats builders.
Stats *StatsClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []CommitHook
onRollback []RollbackHook
// ctx lives for the life of the transaction. It is
// the same context used by the underlying connection.
ctx context.Context
}
type (
// Committer is the interface that wraps the Committer method.
Committer interface {
Commit(context.Context, *Tx) error
}
// The CommitFunc type is an adapter to allow the use of ordinary
// function as a Committer. If f is a function with the appropriate
// signature, CommitFunc(f) is a Committer that calls f.
CommitFunc func(context.Context, *Tx) error
// CommitHook defines the "commit middleware". A function that gets a Committer
// and returns a Committer. For example:
//
// hook := func(next ent.Committer) ent.Committer {
// return ent.CommitFunc(func(context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Commit(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
CommitHook func(Committer) Committer
)
// Commit calls f(ctx, m).
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Commit commits the transaction.
func (tx *Tx) Commit() error {
txDriver := tx.config.driver.(*txDriver)
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
return txDriver.tx.Commit()
})
tx.mu.Lock()
hooks := append([]CommitHook(nil), tx.onCommit...)
tx.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Commit(tx.ctx, tx)
}
// OnCommit adds a hook to call on commit.
func (tx *Tx) OnCommit(f CommitHook) {
tx.mu.Lock()
defer tx.mu.Unlock()
tx.onCommit = append(tx.onCommit, f)
}
type (
// Rollbacker is the interface that wraps the Rollbacker method.
Rollbacker interface {
Rollback(context.Context, *Tx) error
}
// The RollbackFunc type is an adapter to allow the use of ordinary
// function as a Rollbacker. If f is a function with the appropriate
// signature, RollbackFunc(f) is a Rollbacker that calls f.
RollbackFunc func(context.Context, *Tx) error
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
// and returns a Rollbacker. For example:
//
// hook := func(next ent.Rollbacker) ent.Rollbacker {
// return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Rollback(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
RollbackHook func(Rollbacker) Rollbacker
)
// Rollback calls f(ctx, m).
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Rollback rollbacks the transaction.
func (tx *Tx) Rollback() error {
txDriver := tx.config.driver.(*txDriver)
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
return txDriver.tx.Rollback()
})
tx.mu.Lock()
hooks := append([]RollbackHook(nil), tx.onRollback...)
tx.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Rollback(tx.ctx, tx)
}
// OnRollback adds a hook to call on rollback.
func (tx *Tx) OnRollback(f RollbackHook) {
tx.mu.Lock()
defer tx.mu.Unlock()
tx.onRollback = append(tx.onRollback, f)
}
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {
tx.Match = NewMatchClient(tx.config)
tx.Player = NewPlayerClient(tx.config)
tx.Stats = NewStatsClient(tx.config)
}
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
// The idea is to support transactions without adding any extra code to the builders.
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
// Commit and Rollback are nop for the internal builders and the user must call one
// of them in order to commit or rollback the transaction.
//
// If a closed transaction is embedded in one of the generated entities, and the entity
// applies a query, for example: Match.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.
type txDriver struct {
// the driver we started the transaction from.
drv dialect.Driver
// tx is the underlying transaction.
tx dialect.Tx
}
// newTx creates a new transactional driver.
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
tx, err := drv.Tx(ctx)
if err != nil {
return nil, err
}
return &txDriver{tx: tx, drv: drv}, nil
}
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
// from the internal builders. Should be called only by the internal builders.
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
// Dialect returns the dialect of the driver we started the transaction from.
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
// Close is a nop close.
func (*txDriver) Close() error { return nil }
// Commit is a nop commit for the internal builders.
// User must call `Tx.Commit` in order to commit the transaction.
func (*txDriver) Commit() error { return nil }
// Rollback is a nop rollback for the internal builders.
// User must call `Tx.Rollback` in order to rollback the transaction.
func (*txDriver) Rollback() error { return nil }
// Exec calls tx.Exec.
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error {
return tx.tx.Exec(ctx, query, args, v)
}
// Query calls tx.Query.
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error {
return tx.tx.Query(ctx, query, args, v)
}
var _ dialect.Driver = (*txDriver)(nil)