mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
1232 lines
42 KiB
Go
1232 lines
42 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"reflect"
|
|
|
|
"polaris/ent/migrate"
|
|
|
|
"polaris/ent/downloadclients"
|
|
"polaris/ent/episode"
|
|
"polaris/ent/history"
|
|
"polaris/ent/indexers"
|
|
"polaris/ent/media"
|
|
"polaris/ent/settings"
|
|
"polaris/ent/storage"
|
|
|
|
"entgo.io/ent"
|
|
"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
|
|
// DownloadClients is the client for interacting with the DownloadClients builders.
|
|
DownloadClients *DownloadClientsClient
|
|
// Episode is the client for interacting with the Episode builders.
|
|
Episode *EpisodeClient
|
|
// History is the client for interacting with the History builders.
|
|
History *HistoryClient
|
|
// Indexers is the client for interacting with the Indexers builders.
|
|
Indexers *IndexersClient
|
|
// Media is the client for interacting with the Media builders.
|
|
Media *MediaClient
|
|
// Settings is the client for interacting with the Settings builders.
|
|
Settings *SettingsClient
|
|
// Storage is the client for interacting with the Storage builders.
|
|
Storage *StorageClient
|
|
}
|
|
|
|
// 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.Episode = NewEpisodeClient(c.config)
|
|
c.History = NewHistoryClient(c.config)
|
|
c.Indexers = NewIndexersClient(c.config)
|
|
c.Media = NewMediaClient(c.config)
|
|
c.Settings = NewSettingsClient(c.config)
|
|
c.Storage = NewStorageClient(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),
|
|
Episode: NewEpisodeClient(cfg),
|
|
History: NewHistoryClient(cfg),
|
|
Indexers: NewIndexersClient(cfg),
|
|
Media: NewMediaClient(cfg),
|
|
Settings: NewSettingsClient(cfg),
|
|
Storage: NewStorageClient(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),
|
|
Episode: NewEpisodeClient(cfg),
|
|
History: NewHistoryClient(cfg),
|
|
Indexers: NewIndexersClient(cfg),
|
|
Media: NewMediaClient(cfg),
|
|
Settings: NewSettingsClient(cfg),
|
|
Storage: NewStorageClient(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) {
|
|
for _, n := range []interface{ Use(...Hook) }{
|
|
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media, c.Settings,
|
|
c.Storage,
|
|
} {
|
|
n.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) {
|
|
for _, n := range []interface{ Intercept(...Interceptor) }{
|
|
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media, c.Settings,
|
|
c.Storage,
|
|
} {
|
|
n.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 *EpisodeMutation:
|
|
return c.Episode.mutate(ctx, m)
|
|
case *HistoryMutation:
|
|
return c.History.mutate(ctx, m)
|
|
case *IndexersMutation:
|
|
return c.Indexers.mutate(ctx, m)
|
|
case *MediaMutation:
|
|
return c.Media.mutate(ctx, m)
|
|
case *SettingsMutation:
|
|
return c.Settings.mutate(ctx, m)
|
|
case *StorageMutation:
|
|
return c.Storage.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())
|
|
}
|
|
}
|
|
|
|
// EpisodeClient is a client for the Episode schema.
|
|
type EpisodeClient struct {
|
|
config
|
|
}
|
|
|
|
// NewEpisodeClient returns a client for the Episode from the given config.
|
|
func NewEpisodeClient(c config) *EpisodeClient {
|
|
return &EpisodeClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `episode.Hooks(f(g(h())))`.
|
|
func (c *EpisodeClient) Use(hooks ...Hook) {
|
|
c.hooks.Episode = append(c.hooks.Episode, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `episode.Intercept(f(g(h())))`.
|
|
func (c *EpisodeClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Episode = append(c.inters.Episode, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Episode entity.
|
|
func (c *EpisodeClient) Create() *EpisodeCreate {
|
|
mutation := newEpisodeMutation(c.config, OpCreate)
|
|
return &EpisodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Episode entities.
|
|
func (c *EpisodeClient) CreateBulk(builders ...*EpisodeCreate) *EpisodeCreateBulk {
|
|
return &EpisodeCreateBulk{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 *EpisodeClient) MapCreateBulk(slice any, setFunc func(*EpisodeCreate, int)) *EpisodeCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &EpisodeCreateBulk{err: fmt.Errorf("calling to EpisodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*EpisodeCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &EpisodeCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Episode.
|
|
func (c *EpisodeClient) Update() *EpisodeUpdate {
|
|
mutation := newEpisodeMutation(c.config, OpUpdate)
|
|
return &EpisodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *EpisodeClient) UpdateOne(e *Episode) *EpisodeUpdateOne {
|
|
mutation := newEpisodeMutation(c.config, OpUpdateOne, withEpisode(e))
|
|
return &EpisodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *EpisodeClient) UpdateOneID(id int) *EpisodeUpdateOne {
|
|
mutation := newEpisodeMutation(c.config, OpUpdateOne, withEpisodeID(id))
|
|
return &EpisodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Episode.
|
|
func (c *EpisodeClient) Delete() *EpisodeDelete {
|
|
mutation := newEpisodeMutation(c.config, OpDelete)
|
|
return &EpisodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *EpisodeClient) DeleteOne(e *Episode) *EpisodeDeleteOne {
|
|
return c.DeleteOneID(e.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *EpisodeClient) DeleteOneID(id int) *EpisodeDeleteOne {
|
|
builder := c.Delete().Where(episode.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &EpisodeDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Episode.
|
|
func (c *EpisodeClient) Query() *EpisodeQuery {
|
|
return &EpisodeQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeEpisode},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Episode entity by its id.
|
|
func (c *EpisodeClient) Get(ctx context.Context, id int) (*Episode, error) {
|
|
return c.Query().Where(episode.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *EpisodeClient) GetX(ctx context.Context, id int) *Episode {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryMedia queries the media edge of a Episode.
|
|
func (c *EpisodeClient) QueryMedia(e *Episode) *MediaQuery {
|
|
query := (&MediaClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := e.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(episode.Table, episode.FieldID, id),
|
|
sqlgraph.To(media.Table, media.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, episode.MediaTable, episode.MediaColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(e.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *EpisodeClient) Hooks() []Hook {
|
|
return c.hooks.Episode
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *EpisodeClient) Interceptors() []Interceptor {
|
|
return c.inters.Episode
|
|
}
|
|
|
|
func (c *EpisodeClient) mutate(ctx context.Context, m *EpisodeMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&EpisodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&EpisodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&EpisodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&EpisodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Episode mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// HistoryClient is a client for the History schema.
|
|
type HistoryClient struct {
|
|
config
|
|
}
|
|
|
|
// NewHistoryClient returns a client for the History from the given config.
|
|
func NewHistoryClient(c config) *HistoryClient {
|
|
return &HistoryClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `history.Hooks(f(g(h())))`.
|
|
func (c *HistoryClient) Use(hooks ...Hook) {
|
|
c.hooks.History = append(c.hooks.History, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `history.Intercept(f(g(h())))`.
|
|
func (c *HistoryClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.History = append(c.inters.History, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a History entity.
|
|
func (c *HistoryClient) Create() *HistoryCreate {
|
|
mutation := newHistoryMutation(c.config, OpCreate)
|
|
return &HistoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of History entities.
|
|
func (c *HistoryClient) CreateBulk(builders ...*HistoryCreate) *HistoryCreateBulk {
|
|
return &HistoryCreateBulk{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 *HistoryClient) MapCreateBulk(slice any, setFunc func(*HistoryCreate, int)) *HistoryCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &HistoryCreateBulk{err: fmt.Errorf("calling to HistoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*HistoryCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &HistoryCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for History.
|
|
func (c *HistoryClient) Update() *HistoryUpdate {
|
|
mutation := newHistoryMutation(c.config, OpUpdate)
|
|
return &HistoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *HistoryClient) UpdateOne(h *History) *HistoryUpdateOne {
|
|
mutation := newHistoryMutation(c.config, OpUpdateOne, withHistory(h))
|
|
return &HistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *HistoryClient) UpdateOneID(id int) *HistoryUpdateOne {
|
|
mutation := newHistoryMutation(c.config, OpUpdateOne, withHistoryID(id))
|
|
return &HistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for History.
|
|
func (c *HistoryClient) Delete() *HistoryDelete {
|
|
mutation := newHistoryMutation(c.config, OpDelete)
|
|
return &HistoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *HistoryClient) DeleteOne(h *History) *HistoryDeleteOne {
|
|
return c.DeleteOneID(h.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *HistoryClient) DeleteOneID(id int) *HistoryDeleteOne {
|
|
builder := c.Delete().Where(history.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &HistoryDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for History.
|
|
func (c *HistoryClient) Query() *HistoryQuery {
|
|
return &HistoryQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeHistory},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a History entity by its id.
|
|
func (c *HistoryClient) Get(ctx context.Context, id int) (*History, error) {
|
|
return c.Query().Where(history.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *HistoryClient) GetX(ctx context.Context, id int) *History {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *HistoryClient) Hooks() []Hook {
|
|
return c.hooks.History
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *HistoryClient) Interceptors() []Interceptor {
|
|
return c.inters.History
|
|
}
|
|
|
|
func (c *HistoryClient) mutate(ctx context.Context, m *HistoryMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&HistoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&HistoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&HistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&HistoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown History 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())
|
|
}
|
|
}
|
|
|
|
// MediaClient is a client for the Media schema.
|
|
type MediaClient struct {
|
|
config
|
|
}
|
|
|
|
// NewMediaClient returns a client for the Media from the given config.
|
|
func NewMediaClient(c config) *MediaClient {
|
|
return &MediaClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `media.Hooks(f(g(h())))`.
|
|
func (c *MediaClient) Use(hooks ...Hook) {
|
|
c.hooks.Media = append(c.hooks.Media, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `media.Intercept(f(g(h())))`.
|
|
func (c *MediaClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Media = append(c.inters.Media, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Media entity.
|
|
func (c *MediaClient) Create() *MediaCreate {
|
|
mutation := newMediaMutation(c.config, OpCreate)
|
|
return &MediaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Media entities.
|
|
func (c *MediaClient) CreateBulk(builders ...*MediaCreate) *MediaCreateBulk {
|
|
return &MediaCreateBulk{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 *MediaClient) MapCreateBulk(slice any, setFunc func(*MediaCreate, int)) *MediaCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &MediaCreateBulk{err: fmt.Errorf("calling to MediaClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*MediaCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &MediaCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Media.
|
|
func (c *MediaClient) Update() *MediaUpdate {
|
|
mutation := newMediaMutation(c.config, OpUpdate)
|
|
return &MediaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *MediaClient) UpdateOne(m *Media) *MediaUpdateOne {
|
|
mutation := newMediaMutation(c.config, OpUpdateOne, withMedia(m))
|
|
return &MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *MediaClient) UpdateOneID(id int) *MediaUpdateOne {
|
|
mutation := newMediaMutation(c.config, OpUpdateOne, withMediaID(id))
|
|
return &MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Media.
|
|
func (c *MediaClient) Delete() *MediaDelete {
|
|
mutation := newMediaMutation(c.config, OpDelete)
|
|
return &MediaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *MediaClient) DeleteOne(m *Media) *MediaDeleteOne {
|
|
return c.DeleteOneID(m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *MediaClient) DeleteOneID(id int) *MediaDeleteOne {
|
|
builder := c.Delete().Where(media.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &MediaDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Media.
|
|
func (c *MediaClient) Query() *MediaQuery {
|
|
return &MediaQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeMedia},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Media entity by its id.
|
|
func (c *MediaClient) Get(ctx context.Context, id int) (*Media, error) {
|
|
return c.Query().Where(media.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *MediaClient) GetX(ctx context.Context, id int) *Media {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryEpisodes queries the episodes edge of a Media.
|
|
func (c *MediaClient) QueryEpisodes(m *Media) *EpisodeQuery {
|
|
query := (&EpisodeClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(media.Table, media.FieldID, id),
|
|
sqlgraph.To(episode.Table, episode.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, media.EpisodesTable, media.EpisodesColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *MediaClient) Hooks() []Hook {
|
|
return c.hooks.Media
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *MediaClient) Interceptors() []Interceptor {
|
|
return c.inters.Media
|
|
}
|
|
|
|
func (c *MediaClient) mutate(ctx context.Context, m *MediaMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&MediaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&MediaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&MediaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Media 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())
|
|
}
|
|
}
|
|
|
|
// StorageClient is a client for the Storage schema.
|
|
type StorageClient struct {
|
|
config
|
|
}
|
|
|
|
// NewStorageClient returns a client for the Storage from the given config.
|
|
func NewStorageClient(c config) *StorageClient {
|
|
return &StorageClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `storage.Hooks(f(g(h())))`.
|
|
func (c *StorageClient) Use(hooks ...Hook) {
|
|
c.hooks.Storage = append(c.hooks.Storage, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `storage.Intercept(f(g(h())))`.
|
|
func (c *StorageClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Storage = append(c.inters.Storage, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Storage entity.
|
|
func (c *StorageClient) Create() *StorageCreate {
|
|
mutation := newStorageMutation(c.config, OpCreate)
|
|
return &StorageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Storage entities.
|
|
func (c *StorageClient) CreateBulk(builders ...*StorageCreate) *StorageCreateBulk {
|
|
return &StorageCreateBulk{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 *StorageClient) MapCreateBulk(slice any, setFunc func(*StorageCreate, int)) *StorageCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &StorageCreateBulk{err: fmt.Errorf("calling to StorageClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*StorageCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &StorageCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Storage.
|
|
func (c *StorageClient) Update() *StorageUpdate {
|
|
mutation := newStorageMutation(c.config, OpUpdate)
|
|
return &StorageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *StorageClient) UpdateOne(s *Storage) *StorageUpdateOne {
|
|
mutation := newStorageMutation(c.config, OpUpdateOne, withStorage(s))
|
|
return &StorageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *StorageClient) UpdateOneID(id int) *StorageUpdateOne {
|
|
mutation := newStorageMutation(c.config, OpUpdateOne, withStorageID(id))
|
|
return &StorageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Storage.
|
|
func (c *StorageClient) Delete() *StorageDelete {
|
|
mutation := newStorageMutation(c.config, OpDelete)
|
|
return &StorageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *StorageClient) DeleteOne(s *Storage) *StorageDeleteOne {
|
|
return c.DeleteOneID(s.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *StorageClient) DeleteOneID(id int) *StorageDeleteOne {
|
|
builder := c.Delete().Where(storage.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &StorageDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Storage.
|
|
func (c *StorageClient) Query() *StorageQuery {
|
|
return &StorageQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeStorage},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Storage entity by its id.
|
|
func (c *StorageClient) Get(ctx context.Context, id int) (*Storage, error) {
|
|
return c.Query().Where(storage.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *StorageClient) GetX(ctx context.Context, id int) *Storage {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *StorageClient) Hooks() []Hook {
|
|
return c.hooks.Storage
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *StorageClient) Interceptors() []Interceptor {
|
|
return c.inters.Storage
|
|
}
|
|
|
|
func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&StorageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&StorageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&StorageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&StorageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Storage mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// hooks and interceptors per client, for fast access.
|
|
type (
|
|
hooks struct {
|
|
DownloadClients, Episode, History, Indexers, Media, Settings, Storage []ent.Hook
|
|
}
|
|
inters struct {
|
|
DownloadClients, Episode, History, Indexers, Media, Settings,
|
|
Storage []ent.Interceptor
|
|
}
|
|
)
|