mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 03:27:39 +08:00
first draft version
This commit is contained in:
913
ent/client.go
Normal file
913
ent/client.go
Normal file
@@ -0,0 +1,913 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"polaris/ent/migrate"
|
||||
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/epidodes"
|
||||
"polaris/ent/indexers"
|
||||
"polaris/ent/series"
|
||||
"polaris/ent/settings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// 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
|
||||
// DownloadClients is the client for interacting with the DownloadClients builders.
|
||||
DownloadClients *DownloadClientsClient
|
||||
// Epidodes is the client for interacting with the Epidodes builders.
|
||||
Epidodes *EpidodesClient
|
||||
// Indexers is the client for interacting with the Indexers builders.
|
||||
Indexers *IndexersClient
|
||||
// Series is the client for interacting with the Series builders.
|
||||
Series *SeriesClient
|
||||
// Settings is the client for interacting with the Settings builders.
|
||||
Settings *SettingsClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
client := &Client{config: newConfig(opts...)}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.DownloadClients = NewDownloadClientsClient(c.config)
|
||||
c.Epidodes = NewEpidodesClient(c.config)
|
||||
c.Indexers = NewIndexersClient(c.config)
|
||||
c.Series = NewSeriesClient(c.config)
|
||||
c.Settings = NewSettingsClient(c.config)
|
||||
}
|
||||
|
||||
type (
|
||||
// config is the configuration for the client and its builder.
|
||||
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(...any)
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
// interceptors to execute on queries.
|
||||
inters *inters
|
||||
}
|
||||
// Option function to configure the client.
|
||||
Option func(*config)
|
||||
)
|
||||
|
||||
// newConfig creates a new config for the client.
|
||||
func newConfig(opts ...Option) config {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||
cfg.options(opts...)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// 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(...any)) 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
||||
|
||||
// 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, ErrTxStarted
|
||||
}
|
||||
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,
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Epidodes: NewEpidodesClient(cfg),
|
||||
Indexers: NewIndexersClient(cfg),
|
||||
Series: NewSeriesClient(cfg),
|
||||
Settings: NewSettingsClient(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, errors.New("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{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Epidodes: NewEpidodesClient(cfg),
|
||||
Indexers: NewIndexersClient(cfg),
|
||||
Series: NewSeriesClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// DownloadClients.
|
||||
// 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.DownloadClients.Use(hooks...)
|
||||
c.Epidodes.Use(hooks...)
|
||||
c.Indexers.Use(hooks...)
|
||||
c.Series.Use(hooks...)
|
||||
c.Settings.Use(hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.DownloadClients.Intercept(interceptors...)
|
||||
c.Epidodes.Intercept(interceptors...)
|
||||
c.Indexers.Intercept(interceptors...)
|
||||
c.Series.Intercept(interceptors...)
|
||||
c.Settings.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *DownloadClientsMutation:
|
||||
return c.DownloadClients.mutate(ctx, m)
|
||||
case *EpidodesMutation:
|
||||
return c.Epidodes.mutate(ctx, m)
|
||||
case *IndexersMutation:
|
||||
return c.Indexers.mutate(ctx, m)
|
||||
case *SeriesMutation:
|
||||
return c.Series.mutate(ctx, m)
|
||||
case *SettingsMutation:
|
||||
return c.Settings.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadClientsClient is a client for the DownloadClients schema.
|
||||
type DownloadClientsClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewDownloadClientsClient returns a client for the DownloadClients from the given config.
|
||||
func NewDownloadClientsClient(c config) *DownloadClientsClient {
|
||||
return &DownloadClientsClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `downloadclients.Hooks(f(g(h())))`.
|
||||
func (c *DownloadClientsClient) Use(hooks ...Hook) {
|
||||
c.hooks.DownloadClients = append(c.hooks.DownloadClients, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `downloadclients.Intercept(f(g(h())))`.
|
||||
func (c *DownloadClientsClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.DownloadClients = append(c.inters.DownloadClients, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a DownloadClients entity.
|
||||
func (c *DownloadClientsClient) Create() *DownloadClientsCreate {
|
||||
mutation := newDownloadClientsMutation(c.config, OpCreate)
|
||||
return &DownloadClientsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of DownloadClients entities.
|
||||
func (c *DownloadClientsClient) CreateBulk(builders ...*DownloadClientsCreate) *DownloadClientsCreateBulk {
|
||||
return &DownloadClientsCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *DownloadClientsClient) MapCreateBulk(slice any, setFunc func(*DownloadClientsCreate, int)) *DownloadClientsCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &DownloadClientsCreateBulk{err: fmt.Errorf("calling to DownloadClientsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*DownloadClientsCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &DownloadClientsCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for DownloadClients.
|
||||
func (c *DownloadClientsClient) Update() *DownloadClientsUpdate {
|
||||
mutation := newDownloadClientsMutation(c.config, OpUpdate)
|
||||
return &DownloadClientsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *DownloadClientsClient) UpdateOne(dc *DownloadClients) *DownloadClientsUpdateOne {
|
||||
mutation := newDownloadClientsMutation(c.config, OpUpdateOne, withDownloadClients(dc))
|
||||
return &DownloadClientsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *DownloadClientsClient) UpdateOneID(id int) *DownloadClientsUpdateOne {
|
||||
mutation := newDownloadClientsMutation(c.config, OpUpdateOne, withDownloadClientsID(id))
|
||||
return &DownloadClientsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for DownloadClients.
|
||||
func (c *DownloadClientsClient) Delete() *DownloadClientsDelete {
|
||||
mutation := newDownloadClientsMutation(c.config, OpDelete)
|
||||
return &DownloadClientsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *DownloadClientsClient) DeleteOne(dc *DownloadClients) *DownloadClientsDeleteOne {
|
||||
return c.DeleteOneID(dc.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *DownloadClientsClient) DeleteOneID(id int) *DownloadClientsDeleteOne {
|
||||
builder := c.Delete().Where(downloadclients.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &DownloadClientsDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for DownloadClients.
|
||||
func (c *DownloadClientsClient) Query() *DownloadClientsQuery {
|
||||
return &DownloadClientsQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeDownloadClients},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a DownloadClients entity by its id.
|
||||
func (c *DownloadClientsClient) Get(ctx context.Context, id int) (*DownloadClients, error) {
|
||||
return c.Query().Where(downloadclients.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *DownloadClientsClient) GetX(ctx context.Context, id int) *DownloadClients {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *DownloadClientsClient) Hooks() []Hook {
|
||||
return c.hooks.DownloadClients
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *DownloadClientsClient) Interceptors() []Interceptor {
|
||||
return c.inters.DownloadClients
|
||||
}
|
||||
|
||||
func (c *DownloadClientsClient) mutate(ctx context.Context, m *DownloadClientsMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&DownloadClientsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&DownloadClientsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&DownloadClientsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&DownloadClientsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown DownloadClients mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// EpidodesClient is a client for the Epidodes schema.
|
||||
type EpidodesClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewEpidodesClient returns a client for the Epidodes from the given config.
|
||||
func NewEpidodesClient(c config) *EpidodesClient {
|
||||
return &EpidodesClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `epidodes.Hooks(f(g(h())))`.
|
||||
func (c *EpidodesClient) Use(hooks ...Hook) {
|
||||
c.hooks.Epidodes = append(c.hooks.Epidodes, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `epidodes.Intercept(f(g(h())))`.
|
||||
func (c *EpidodesClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Epidodes = append(c.inters.Epidodes, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Epidodes entity.
|
||||
func (c *EpidodesClient) Create() *EpidodesCreate {
|
||||
mutation := newEpidodesMutation(c.config, OpCreate)
|
||||
return &EpidodesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Epidodes entities.
|
||||
func (c *EpidodesClient) CreateBulk(builders ...*EpidodesCreate) *EpidodesCreateBulk {
|
||||
return &EpidodesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *EpidodesClient) MapCreateBulk(slice any, setFunc func(*EpidodesCreate, int)) *EpidodesCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &EpidodesCreateBulk{err: fmt.Errorf("calling to EpidodesClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*EpidodesCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &EpidodesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Epidodes.
|
||||
func (c *EpidodesClient) Update() *EpidodesUpdate {
|
||||
mutation := newEpidodesMutation(c.config, OpUpdate)
|
||||
return &EpidodesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *EpidodesClient) UpdateOne(e *Epidodes) *EpidodesUpdateOne {
|
||||
mutation := newEpidodesMutation(c.config, OpUpdateOne, withEpidodes(e))
|
||||
return &EpidodesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *EpidodesClient) UpdateOneID(id int) *EpidodesUpdateOne {
|
||||
mutation := newEpidodesMutation(c.config, OpUpdateOne, withEpidodesID(id))
|
||||
return &EpidodesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Epidodes.
|
||||
func (c *EpidodesClient) Delete() *EpidodesDelete {
|
||||
mutation := newEpidodesMutation(c.config, OpDelete)
|
||||
return &EpidodesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *EpidodesClient) DeleteOne(e *Epidodes) *EpidodesDeleteOne {
|
||||
return c.DeleteOneID(e.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *EpidodesClient) DeleteOneID(id int) *EpidodesDeleteOne {
|
||||
builder := c.Delete().Where(epidodes.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &EpidodesDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Epidodes.
|
||||
func (c *EpidodesClient) Query() *EpidodesQuery {
|
||||
return &EpidodesQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeEpidodes},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Epidodes entity by its id.
|
||||
func (c *EpidodesClient) Get(ctx context.Context, id int) (*Epidodes, error) {
|
||||
return c.Query().Where(epidodes.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *EpidodesClient) GetX(ctx context.Context, id int) *Epidodes {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *EpidodesClient) Hooks() []Hook {
|
||||
return c.hooks.Epidodes
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *EpidodesClient) Interceptors() []Interceptor {
|
||||
return c.inters.Epidodes
|
||||
}
|
||||
|
||||
func (c *EpidodesClient) mutate(ctx context.Context, m *EpidodesMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&EpidodesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&EpidodesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&EpidodesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&EpidodesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Epidodes mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// IndexersClient is a client for the Indexers schema.
|
||||
type IndexersClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewIndexersClient returns a client for the Indexers from the given config.
|
||||
func NewIndexersClient(c config) *IndexersClient {
|
||||
return &IndexersClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `indexers.Hooks(f(g(h())))`.
|
||||
func (c *IndexersClient) Use(hooks ...Hook) {
|
||||
c.hooks.Indexers = append(c.hooks.Indexers, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `indexers.Intercept(f(g(h())))`.
|
||||
func (c *IndexersClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Indexers = append(c.inters.Indexers, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Indexers entity.
|
||||
func (c *IndexersClient) Create() *IndexersCreate {
|
||||
mutation := newIndexersMutation(c.config, OpCreate)
|
||||
return &IndexersCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Indexers entities.
|
||||
func (c *IndexersClient) CreateBulk(builders ...*IndexersCreate) *IndexersCreateBulk {
|
||||
return &IndexersCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *IndexersClient) MapCreateBulk(slice any, setFunc func(*IndexersCreate, int)) *IndexersCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &IndexersCreateBulk{err: fmt.Errorf("calling to IndexersClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*IndexersCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &IndexersCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Indexers.
|
||||
func (c *IndexersClient) Update() *IndexersUpdate {
|
||||
mutation := newIndexersMutation(c.config, OpUpdate)
|
||||
return &IndexersUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *IndexersClient) UpdateOne(i *Indexers) *IndexersUpdateOne {
|
||||
mutation := newIndexersMutation(c.config, OpUpdateOne, withIndexers(i))
|
||||
return &IndexersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *IndexersClient) UpdateOneID(id int) *IndexersUpdateOne {
|
||||
mutation := newIndexersMutation(c.config, OpUpdateOne, withIndexersID(id))
|
||||
return &IndexersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Indexers.
|
||||
func (c *IndexersClient) Delete() *IndexersDelete {
|
||||
mutation := newIndexersMutation(c.config, OpDelete)
|
||||
return &IndexersDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *IndexersClient) DeleteOne(i *Indexers) *IndexersDeleteOne {
|
||||
return c.DeleteOneID(i.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *IndexersClient) DeleteOneID(id int) *IndexersDeleteOne {
|
||||
builder := c.Delete().Where(indexers.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &IndexersDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Indexers.
|
||||
func (c *IndexersClient) Query() *IndexersQuery {
|
||||
return &IndexersQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeIndexers},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Indexers entity by its id.
|
||||
func (c *IndexersClient) Get(ctx context.Context, id int) (*Indexers, error) {
|
||||
return c.Query().Where(indexers.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *IndexersClient) GetX(ctx context.Context, id int) *Indexers {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *IndexersClient) Hooks() []Hook {
|
||||
return c.hooks.Indexers
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *IndexersClient) Interceptors() []Interceptor {
|
||||
return c.inters.Indexers
|
||||
}
|
||||
|
||||
func (c *IndexersClient) mutate(ctx context.Context, m *IndexersMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&IndexersCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&IndexersUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&IndexersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&IndexersDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Indexers mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SeriesClient is a client for the Series schema.
|
||||
type SeriesClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSeriesClient returns a client for the Series from the given config.
|
||||
func NewSeriesClient(c config) *SeriesClient {
|
||||
return &SeriesClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `series.Hooks(f(g(h())))`.
|
||||
func (c *SeriesClient) Use(hooks ...Hook) {
|
||||
c.hooks.Series = append(c.hooks.Series, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `series.Intercept(f(g(h())))`.
|
||||
func (c *SeriesClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Series = append(c.inters.Series, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Series entity.
|
||||
func (c *SeriesClient) Create() *SeriesCreate {
|
||||
mutation := newSeriesMutation(c.config, OpCreate)
|
||||
return &SeriesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Series entities.
|
||||
func (c *SeriesClient) CreateBulk(builders ...*SeriesCreate) *SeriesCreateBulk {
|
||||
return &SeriesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *SeriesClient) MapCreateBulk(slice any, setFunc func(*SeriesCreate, int)) *SeriesCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &SeriesCreateBulk{err: fmt.Errorf("calling to SeriesClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*SeriesCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &SeriesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Series.
|
||||
func (c *SeriesClient) Update() *SeriesUpdate {
|
||||
mutation := newSeriesMutation(c.config, OpUpdate)
|
||||
return &SeriesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SeriesClient) UpdateOne(s *Series) *SeriesUpdateOne {
|
||||
mutation := newSeriesMutation(c.config, OpUpdateOne, withSeries(s))
|
||||
return &SeriesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SeriesClient) UpdateOneID(id int) *SeriesUpdateOne {
|
||||
mutation := newSeriesMutation(c.config, OpUpdateOne, withSeriesID(id))
|
||||
return &SeriesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Series.
|
||||
func (c *SeriesClient) Delete() *SeriesDelete {
|
||||
mutation := newSeriesMutation(c.config, OpDelete)
|
||||
return &SeriesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SeriesClient) DeleteOne(s *Series) *SeriesDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SeriesClient) DeleteOneID(id int) *SeriesDeleteOne {
|
||||
builder := c.Delete().Where(series.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SeriesDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Series.
|
||||
func (c *SeriesClient) Query() *SeriesQuery {
|
||||
return &SeriesQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSeries},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Series entity by its id.
|
||||
func (c *SeriesClient) Get(ctx context.Context, id int) (*Series, error) {
|
||||
return c.Query().Where(series.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SeriesClient) GetX(ctx context.Context, id int) *Series {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SeriesClient) Hooks() []Hook {
|
||||
return c.hooks.Series
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SeriesClient) Interceptors() []Interceptor {
|
||||
return c.inters.Series
|
||||
}
|
||||
|
||||
func (c *SeriesClient) mutate(ctx context.Context, m *SeriesMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SeriesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SeriesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SeriesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SeriesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Series mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SettingsClient is a client for the Settings schema.
|
||||
type SettingsClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSettingsClient returns a client for the Settings from the given config.
|
||||
func NewSettingsClient(c config) *SettingsClient {
|
||||
return &SettingsClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `settings.Hooks(f(g(h())))`.
|
||||
func (c *SettingsClient) Use(hooks ...Hook) {
|
||||
c.hooks.Settings = append(c.hooks.Settings, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `settings.Intercept(f(g(h())))`.
|
||||
func (c *SettingsClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Settings = append(c.inters.Settings, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Settings entity.
|
||||
func (c *SettingsClient) Create() *SettingsCreate {
|
||||
mutation := newSettingsMutation(c.config, OpCreate)
|
||||
return &SettingsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Settings entities.
|
||||
func (c *SettingsClient) CreateBulk(builders ...*SettingsCreate) *SettingsCreateBulk {
|
||||
return &SettingsCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *SettingsClient) MapCreateBulk(slice any, setFunc func(*SettingsCreate, int)) *SettingsCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &SettingsCreateBulk{err: fmt.Errorf("calling to SettingsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*SettingsCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &SettingsCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Settings.
|
||||
func (c *SettingsClient) Update() *SettingsUpdate {
|
||||
mutation := newSettingsMutation(c.config, OpUpdate)
|
||||
return &SettingsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SettingsClient) UpdateOne(s *Settings) *SettingsUpdateOne {
|
||||
mutation := newSettingsMutation(c.config, OpUpdateOne, withSettings(s))
|
||||
return &SettingsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SettingsClient) UpdateOneID(id int) *SettingsUpdateOne {
|
||||
mutation := newSettingsMutation(c.config, OpUpdateOne, withSettingsID(id))
|
||||
return &SettingsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Settings.
|
||||
func (c *SettingsClient) Delete() *SettingsDelete {
|
||||
mutation := newSettingsMutation(c.config, OpDelete)
|
||||
return &SettingsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SettingsClient) DeleteOne(s *Settings) *SettingsDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SettingsClient) DeleteOneID(id int) *SettingsDeleteOne {
|
||||
builder := c.Delete().Where(settings.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SettingsDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Settings.
|
||||
func (c *SettingsClient) Query() *SettingsQuery {
|
||||
return &SettingsQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSettings},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Settings entity by its id.
|
||||
func (c *SettingsClient) Get(ctx context.Context, id int) (*Settings, error) {
|
||||
return c.Query().Where(settings.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SettingsClient) GetX(ctx context.Context, id int) *Settings {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SettingsClient) Hooks() []Hook {
|
||||
return c.hooks.Settings
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SettingsClient) Interceptors() []Interceptor {
|
||||
return c.inters.Settings
|
||||
}
|
||||
|
||||
func (c *SettingsClient) mutate(ctx context.Context, m *SettingsMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SettingsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SettingsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SettingsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SettingsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Settings mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
DownloadClients, Epidodes, Indexers, Series, Settings []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
DownloadClients, Epidodes, Indexers, Series, Settings []ent.Interceptor
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user