// 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 }