db optimize

This commit is contained in:
Simon Ding
2024-07-06 11:56:53 +08:00
parent 7d9dc17f87
commit 1fef91fe66
30 changed files with 2289 additions and 1573 deletions

View File

@@ -65,7 +65,7 @@ func (c *Client) GetLanguage() string {
return lang
}
func (c *Client) AddWatchlist(path string, detail *tmdb.TVDetails) (*ent.Series, error) {
func (c *Client) AddWatchlist(path string, detail *tmdb.TVDetails, episodes []int) (*ent.Series, error) {
count := c.ent.Series.Query().Where(series.TmdbID(int(detail.ID))).CountX(context.Background())
if (count > 0) {
return nil, fmt.Errorf("tv series %s already in watchlist", detail.Name)
@@ -74,9 +74,10 @@ func (c *Client) AddWatchlist(path string, detail *tmdb.TVDetails) (*ent.Series,
SetTmdbID(int(detail.ID)).
SetPath(path).
SetOverview(detail.Overview).
SetTitle(detail.Name).
SetName(detail.Name).
SetOriginalName(detail.OriginalName).
SetPosterPath(detail.PosterPath).
AddEpisodeIDs(episodes...).
Save(context.TODO())
return r, err
}
@@ -90,16 +91,15 @@ func (c *Client) GetWatchlist() []*ent.Series {
return list
}
func (c *Client) SaveEposideDetail(d *ent.Epidodes) error {
_, err := c.ent.Epidodes.Create().
func (c *Client) SaveEposideDetail(d *ent.Episode) (int, error) {
ep, err := c.ent.Episode.Create().
SetAirDate(d.AirDate).
SetSeasonNumber(d.SeasonNumber).
SetEpisodeNumber(d.EpisodeNumber).
SetSeriesID(d.SeriesID).
SetOverview(d.Overview).
SetTitle(d.Title).Save(context.TODO())
return err
return ep.ID,err
}
type TorznabSetting struct {

View File

@@ -12,7 +12,7 @@ import (
"polaris/ent/migrate"
"polaris/ent/downloadclients"
"polaris/ent/epidodes"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/series"
@@ -21,6 +21,7 @@ import (
"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.
@@ -30,8 +31,8 @@ type Client struct {
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
// 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.
@@ -52,7 +53,7 @@ func NewClient(opts ...Option) *Client {
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.DownloadClients = NewDownloadClientsClient(c.config)
c.Epidodes = NewEpidodesClient(c.config)
c.Episode = NewEpisodeClient(c.config)
c.History = NewHistoryClient(c.config)
c.Indexers = NewIndexersClient(c.config)
c.Series = NewSeriesClient(c.config)
@@ -150,7 +151,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
ctx: ctx,
config: cfg,
DownloadClients: NewDownloadClientsClient(cfg),
Epidodes: NewEpidodesClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
Indexers: NewIndexersClient(cfg),
Series: NewSeriesClient(cfg),
@@ -175,7 +176,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
ctx: ctx,
config: cfg,
DownloadClients: NewDownloadClientsClient(cfg),
Epidodes: NewEpidodesClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
Indexers: NewIndexersClient(cfg),
Series: NewSeriesClient(cfg),
@@ -209,7 +210,7 @@ func (c *Client) Close() error {
// 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.Epidodes, c.History, c.Indexers, c.Series, c.Settings,
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Series, c.Settings,
} {
n.Use(hooks...)
}
@@ -219,7 +220,7 @@ func (c *Client) Use(hooks ...Hook) {
// 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.Epidodes, c.History, c.Indexers, c.Series, c.Settings,
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Series, c.Settings,
} {
n.Intercept(interceptors...)
}
@@ -230,8 +231,8 @@ 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 *EpisodeMutation:
return c.Episode.mutate(ctx, m)
case *HistoryMutation:
return c.History.mutate(ctx, m)
case *IndexersMutation:
@@ -378,107 +379,107 @@ func (c *DownloadClientsClient) mutate(ctx context.Context, m *DownloadClientsMu
}
}
// EpidodesClient is a client for the Epidodes schema.
type EpidodesClient struct {
// EpisodeClient is a client for the Episode schema.
type EpisodeClient struct {
config
}
// NewEpidodesClient returns a client for the Epidodes from the given config.
func NewEpidodesClient(c config) *EpidodesClient {
return &EpidodesClient{config: c}
// 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 `epidodes.Hooks(f(g(h())))`.
func (c *EpidodesClient) Use(hooks ...Hook) {
c.hooks.Epidodes = append(c.hooks.Epidodes, hooks...)
// 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 `epidodes.Intercept(f(g(h())))`.
func (c *EpidodesClient) Intercept(interceptors ...Interceptor) {
c.inters.Epidodes = append(c.inters.Epidodes, interceptors...)
// 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 Epidodes entity.
func (c *EpidodesClient) Create() *EpidodesCreate {
mutation := newEpidodesMutation(c.config, OpCreate)
return &EpidodesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// 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 Epidodes entities.
func (c *EpidodesClient) CreateBulk(builders ...*EpidodesCreate) *EpidodesCreateBulk {
return &EpidodesCreateBulk{config: c.config, builders: builders}
// 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 *EpidodesClient) MapCreateBulk(slice any, setFunc func(*EpidodesCreate, int)) *EpidodesCreateBulk {
func (c *EpisodeClient) MapCreateBulk(slice any, setFunc func(*EpisodeCreate, int)) *EpisodeCreateBulk {
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)}
return &EpisodeCreateBulk{err: fmt.Errorf("calling to EpisodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*EpidodesCreate, rv.Len())
builders := make([]*EpisodeCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &EpidodesCreateBulk{config: c.config, builders: builders}
return &EpisodeCreateBulk{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}
// 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 *EpidodesClient) UpdateOne(e *Epidodes) *EpidodesUpdateOne {
mutation := newEpidodesMutation(c.config, OpUpdateOne, withEpidodes(e))
return &EpidodesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
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 *EpidodesClient) UpdateOneID(id int) *EpidodesUpdateOne {
mutation := newEpidodesMutation(c.config, OpUpdateOne, withEpidodesID(id))
return &EpidodesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
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 Epidodes.
func (c *EpidodesClient) Delete() *EpidodesDelete {
mutation := newEpidodesMutation(c.config, OpDelete)
return &EpidodesDelete{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 *EpidodesClient) DeleteOne(e *Epidodes) *EpidodesDeleteOne {
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 *EpidodesClient) DeleteOneID(id int) *EpidodesDeleteOne {
builder := c.Delete().Where(epidodes.ID(id))
func (c *EpisodeClient) DeleteOneID(id int) *EpisodeDeleteOne {
builder := c.Delete().Where(episode.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &EpidodesDeleteOne{builder}
return &EpisodeDeleteOne{builder}
}
// Query returns a query builder for Epidodes.
func (c *EpidodesClient) Query() *EpidodesQuery {
return &EpidodesQuery{
// Query returns a query builder for Episode.
func (c *EpisodeClient) Query() *EpisodeQuery {
return &EpisodeQuery{
config: c.config,
ctx: &QueryContext{Type: TypeEpidodes},
ctx: &QueryContext{Type: TypeEpisode},
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)
// 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 *EpidodesClient) GetX(ctx context.Context, id int) *Epidodes {
func (c *EpisodeClient) GetX(ctx context.Context, id int) *Episode {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
@@ -486,28 +487,44 @@ func (c *EpidodesClient) GetX(ctx context.Context, id int) *Epidodes {
return obj
}
// QuerySeries queries the series edge of a Episode.
func (c *EpisodeClient) QuerySeries(e *Episode) *SeriesQuery {
query := (&SeriesClient{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(series.Table, series.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, episode.SeriesTable, episode.SeriesColumn),
)
fromV = sqlgraph.Neighbors(e.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *EpidodesClient) Hooks() []Hook {
return c.hooks.Epidodes
func (c *EpisodeClient) Hooks() []Hook {
return c.hooks.Episode
}
// Interceptors returns the client interceptors.
func (c *EpidodesClient) Interceptors() []Interceptor {
return c.inters.Epidodes
func (c *EpisodeClient) Interceptors() []Interceptor {
return c.inters.Episode
}
func (c *EpidodesClient) mutate(ctx context.Context, m *EpidodesMutation) (Value, error) {
func (c *EpisodeClient) mutate(ctx context.Context, m *EpisodeMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&EpidodesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
return (&EpisodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&EpidodesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
return (&EpisodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&EpidodesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
return (&EpisodeUpdateOne{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)
return (&EpisodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Epidodes mutation op: %q", m.Op())
return nil, fmt.Errorf("ent: unknown Episode mutation op: %q", m.Op())
}
}
@@ -885,6 +902,22 @@ func (c *SeriesClient) GetX(ctx context.Context, id int) *Series {
return obj
}
// QueryEpisodes queries the episodes edge of a Series.
func (c *SeriesClient) QueryEpisodes(s *Series) *EpisodeQuery {
query := (&EpisodeClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := s.ID
step := sqlgraph.NewStep(
sqlgraph.From(series.Table, series.FieldID, id),
sqlgraph.To(episode.Table, episode.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, series.EpisodesTable, series.EpisodesColumn),
)
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *SeriesClient) Hooks() []Hook {
return c.hooks.Series
@@ -1046,9 +1079,9 @@ func (c *SettingsClient) mutate(ctx context.Context, m *SettingsMutation) (Value
// hooks and interceptors per client, for fast access.
type (
hooks struct {
DownloadClients, Epidodes, History, Indexers, Series, Settings []ent.Hook
DownloadClients, Episode, History, Indexers, Series, Settings []ent.Hook
}
inters struct {
DownloadClients, Epidodes, History, Indexers, Series, Settings []ent.Interceptor
DownloadClients, Episode, History, Indexers, Series, Settings []ent.Interceptor
}
)

View File

@@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"polaris/ent/downloadclients"
"polaris/ent/epidodes"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/series"
@@ -79,7 +79,7 @@ func checkColumn(table, column string) error {
initCheck.Do(func() {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
downloadclients.Table: downloadclients.ValidColumn,
epidodes.Table: epidodes.ValidColumn,
episode.Table: episode.ValidColumn,
history.Table: history.ValidColumn,
indexers.Table: indexers.ValidColumn,
series.Table: series.ValidColumn,

View File

@@ -1,414 +0,0 @@
// Code generated by ent, DO NOT EDIT.
package epidodes
import (
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldID, id))
}
// SeriesID applies equality check predicate on the "series_id" field. It's identical to SeriesIDEQ.
func SeriesID(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldSeriesID, v))
}
// SeasonNumber applies equality check predicate on the "season_number" field. It's identical to SeasonNumberEQ.
func SeasonNumber(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldSeasonNumber, v))
}
// EpisodeNumber applies equality check predicate on the "episode_number" field. It's identical to EpisodeNumberEQ.
func EpisodeNumber(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldEpisodeNumber, v))
}
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
func Title(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldTitle, v))
}
// Overview applies equality check predicate on the "overview" field. It's identical to OverviewEQ.
func Overview(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldOverview, v))
}
// AirDate applies equality check predicate on the "air_date" field. It's identical to AirDateEQ.
func AirDate(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldAirDate, v))
}
// SeriesIDEQ applies the EQ predicate on the "series_id" field.
func SeriesIDEQ(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldSeriesID, v))
}
// SeriesIDNEQ applies the NEQ predicate on the "series_id" field.
func SeriesIDNEQ(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldSeriesID, v))
}
// SeriesIDIn applies the In predicate on the "series_id" field.
func SeriesIDIn(vs ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldSeriesID, vs...))
}
// SeriesIDNotIn applies the NotIn predicate on the "series_id" field.
func SeriesIDNotIn(vs ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldSeriesID, vs...))
}
// SeriesIDGT applies the GT predicate on the "series_id" field.
func SeriesIDGT(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldSeriesID, v))
}
// SeriesIDGTE applies the GTE predicate on the "series_id" field.
func SeriesIDGTE(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldSeriesID, v))
}
// SeriesIDLT applies the LT predicate on the "series_id" field.
func SeriesIDLT(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldSeriesID, v))
}
// SeriesIDLTE applies the LTE predicate on the "series_id" field.
func SeriesIDLTE(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldSeriesID, v))
}
// SeasonNumberEQ applies the EQ predicate on the "season_number" field.
func SeasonNumberEQ(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldSeasonNumber, v))
}
// SeasonNumberNEQ applies the NEQ predicate on the "season_number" field.
func SeasonNumberNEQ(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldSeasonNumber, v))
}
// SeasonNumberIn applies the In predicate on the "season_number" field.
func SeasonNumberIn(vs ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldSeasonNumber, vs...))
}
// SeasonNumberNotIn applies the NotIn predicate on the "season_number" field.
func SeasonNumberNotIn(vs ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldSeasonNumber, vs...))
}
// SeasonNumberGT applies the GT predicate on the "season_number" field.
func SeasonNumberGT(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldSeasonNumber, v))
}
// SeasonNumberGTE applies the GTE predicate on the "season_number" field.
func SeasonNumberGTE(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldSeasonNumber, v))
}
// SeasonNumberLT applies the LT predicate on the "season_number" field.
func SeasonNumberLT(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldSeasonNumber, v))
}
// SeasonNumberLTE applies the LTE predicate on the "season_number" field.
func SeasonNumberLTE(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldSeasonNumber, v))
}
// EpisodeNumberEQ applies the EQ predicate on the "episode_number" field.
func EpisodeNumberEQ(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldEpisodeNumber, v))
}
// EpisodeNumberNEQ applies the NEQ predicate on the "episode_number" field.
func EpisodeNumberNEQ(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldEpisodeNumber, v))
}
// EpisodeNumberIn applies the In predicate on the "episode_number" field.
func EpisodeNumberIn(vs ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldEpisodeNumber, vs...))
}
// EpisodeNumberNotIn applies the NotIn predicate on the "episode_number" field.
func EpisodeNumberNotIn(vs ...int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldEpisodeNumber, vs...))
}
// EpisodeNumberGT applies the GT predicate on the "episode_number" field.
func EpisodeNumberGT(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldEpisodeNumber, v))
}
// EpisodeNumberGTE applies the GTE predicate on the "episode_number" field.
func EpisodeNumberGTE(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldEpisodeNumber, v))
}
// EpisodeNumberLT applies the LT predicate on the "episode_number" field.
func EpisodeNumberLT(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldEpisodeNumber, v))
}
// EpisodeNumberLTE applies the LTE predicate on the "episode_number" field.
func EpisodeNumberLTE(v int) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldEpisodeNumber, v))
}
// TitleEQ applies the EQ predicate on the "title" field.
func TitleEQ(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldTitle, v))
}
// TitleNEQ applies the NEQ predicate on the "title" field.
func TitleNEQ(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldTitle, v))
}
// TitleIn applies the In predicate on the "title" field.
func TitleIn(vs ...string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldTitle, vs...))
}
// TitleNotIn applies the NotIn predicate on the "title" field.
func TitleNotIn(vs ...string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldTitle, vs...))
}
// TitleGT applies the GT predicate on the "title" field.
func TitleGT(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldTitle, v))
}
// TitleGTE applies the GTE predicate on the "title" field.
func TitleGTE(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldTitle, v))
}
// TitleLT applies the LT predicate on the "title" field.
func TitleLT(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldTitle, v))
}
// TitleLTE applies the LTE predicate on the "title" field.
func TitleLTE(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldTitle, v))
}
// TitleContains applies the Contains predicate on the "title" field.
func TitleContains(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldContains(FieldTitle, v))
}
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
func TitleHasPrefix(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldHasPrefix(FieldTitle, v))
}
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
func TitleHasSuffix(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldHasSuffix(FieldTitle, v))
}
// TitleEqualFold applies the EqualFold predicate on the "title" field.
func TitleEqualFold(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEqualFold(FieldTitle, v))
}
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
func TitleContainsFold(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldContainsFold(FieldTitle, v))
}
// OverviewEQ applies the EQ predicate on the "overview" field.
func OverviewEQ(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldOverview, v))
}
// OverviewNEQ applies the NEQ predicate on the "overview" field.
func OverviewNEQ(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldOverview, v))
}
// OverviewIn applies the In predicate on the "overview" field.
func OverviewIn(vs ...string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldOverview, vs...))
}
// OverviewNotIn applies the NotIn predicate on the "overview" field.
func OverviewNotIn(vs ...string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldOverview, vs...))
}
// OverviewGT applies the GT predicate on the "overview" field.
func OverviewGT(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldOverview, v))
}
// OverviewGTE applies the GTE predicate on the "overview" field.
func OverviewGTE(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldOverview, v))
}
// OverviewLT applies the LT predicate on the "overview" field.
func OverviewLT(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldOverview, v))
}
// OverviewLTE applies the LTE predicate on the "overview" field.
func OverviewLTE(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldOverview, v))
}
// OverviewContains applies the Contains predicate on the "overview" field.
func OverviewContains(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldContains(FieldOverview, v))
}
// OverviewHasPrefix applies the HasPrefix predicate on the "overview" field.
func OverviewHasPrefix(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldHasPrefix(FieldOverview, v))
}
// OverviewHasSuffix applies the HasSuffix predicate on the "overview" field.
func OverviewHasSuffix(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldHasSuffix(FieldOverview, v))
}
// OverviewEqualFold applies the EqualFold predicate on the "overview" field.
func OverviewEqualFold(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEqualFold(FieldOverview, v))
}
// OverviewContainsFold applies the ContainsFold predicate on the "overview" field.
func OverviewContainsFold(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldContainsFold(FieldOverview, v))
}
// AirDateEQ applies the EQ predicate on the "air_date" field.
func AirDateEQ(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEQ(FieldAirDate, v))
}
// AirDateNEQ applies the NEQ predicate on the "air_date" field.
func AirDateNEQ(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNEQ(FieldAirDate, v))
}
// AirDateIn applies the In predicate on the "air_date" field.
func AirDateIn(vs ...string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldIn(FieldAirDate, vs...))
}
// AirDateNotIn applies the NotIn predicate on the "air_date" field.
func AirDateNotIn(vs ...string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldNotIn(FieldAirDate, vs...))
}
// AirDateGT applies the GT predicate on the "air_date" field.
func AirDateGT(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGT(FieldAirDate, v))
}
// AirDateGTE applies the GTE predicate on the "air_date" field.
func AirDateGTE(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldGTE(FieldAirDate, v))
}
// AirDateLT applies the LT predicate on the "air_date" field.
func AirDateLT(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLT(FieldAirDate, v))
}
// AirDateLTE applies the LTE predicate on the "air_date" field.
func AirDateLTE(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldLTE(FieldAirDate, v))
}
// AirDateContains applies the Contains predicate on the "air_date" field.
func AirDateContains(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldContains(FieldAirDate, v))
}
// AirDateHasPrefix applies the HasPrefix predicate on the "air_date" field.
func AirDateHasPrefix(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldHasPrefix(FieldAirDate, v))
}
// AirDateHasSuffix applies the HasSuffix predicate on the "air_date" field.
func AirDateHasSuffix(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldHasSuffix(FieldAirDate, v))
}
// AirDateEqualFold applies the EqualFold predicate on the "air_date" field.
func AirDateEqualFold(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldEqualFold(FieldAirDate, v))
}
// AirDateContainsFold applies the ContainsFold predicate on the "air_date" field.
func AirDateContainsFold(v string) predicate.Epidodes {
return predicate.Epidodes(sql.FieldContainsFold(FieldAirDate, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Epidodes) predicate.Epidodes {
return predicate.Epidodes(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Epidodes) predicate.Epidodes {
return predicate.Epidodes(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Epidodes) predicate.Epidodes {
return predicate.Epidodes(sql.NotPredicates(p))
}

View File

@@ -1,439 +0,0 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/epidodes"
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// EpidodesUpdate is the builder for updating Epidodes entities.
type EpidodesUpdate struct {
config
hooks []Hook
mutation *EpidodesMutation
}
// Where appends a list predicates to the EpidodesUpdate builder.
func (eu *EpidodesUpdate) Where(ps ...predicate.Epidodes) *EpidodesUpdate {
eu.mutation.Where(ps...)
return eu
}
// SetSeriesID sets the "series_id" field.
func (eu *EpidodesUpdate) SetSeriesID(i int) *EpidodesUpdate {
eu.mutation.ResetSeriesID()
eu.mutation.SetSeriesID(i)
return eu
}
// SetNillableSeriesID sets the "series_id" field if the given value is not nil.
func (eu *EpidodesUpdate) SetNillableSeriesID(i *int) *EpidodesUpdate {
if i != nil {
eu.SetSeriesID(*i)
}
return eu
}
// AddSeriesID adds i to the "series_id" field.
func (eu *EpidodesUpdate) AddSeriesID(i int) *EpidodesUpdate {
eu.mutation.AddSeriesID(i)
return eu
}
// SetSeasonNumber sets the "season_number" field.
func (eu *EpidodesUpdate) SetSeasonNumber(i int) *EpidodesUpdate {
eu.mutation.ResetSeasonNumber()
eu.mutation.SetSeasonNumber(i)
return eu
}
// SetNillableSeasonNumber sets the "season_number" field if the given value is not nil.
func (eu *EpidodesUpdate) SetNillableSeasonNumber(i *int) *EpidodesUpdate {
if i != nil {
eu.SetSeasonNumber(*i)
}
return eu
}
// AddSeasonNumber adds i to the "season_number" field.
func (eu *EpidodesUpdate) AddSeasonNumber(i int) *EpidodesUpdate {
eu.mutation.AddSeasonNumber(i)
return eu
}
// SetEpisodeNumber sets the "episode_number" field.
func (eu *EpidodesUpdate) SetEpisodeNumber(i int) *EpidodesUpdate {
eu.mutation.ResetEpisodeNumber()
eu.mutation.SetEpisodeNumber(i)
return eu
}
// SetNillableEpisodeNumber sets the "episode_number" field if the given value is not nil.
func (eu *EpidodesUpdate) SetNillableEpisodeNumber(i *int) *EpidodesUpdate {
if i != nil {
eu.SetEpisodeNumber(*i)
}
return eu
}
// AddEpisodeNumber adds i to the "episode_number" field.
func (eu *EpidodesUpdate) AddEpisodeNumber(i int) *EpidodesUpdate {
eu.mutation.AddEpisodeNumber(i)
return eu
}
// SetTitle sets the "title" field.
func (eu *EpidodesUpdate) SetTitle(s string) *EpidodesUpdate {
eu.mutation.SetTitle(s)
return eu
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (eu *EpidodesUpdate) SetNillableTitle(s *string) *EpidodesUpdate {
if s != nil {
eu.SetTitle(*s)
}
return eu
}
// SetOverview sets the "overview" field.
func (eu *EpidodesUpdate) SetOverview(s string) *EpidodesUpdate {
eu.mutation.SetOverview(s)
return eu
}
// SetNillableOverview sets the "overview" field if the given value is not nil.
func (eu *EpidodesUpdate) SetNillableOverview(s *string) *EpidodesUpdate {
if s != nil {
eu.SetOverview(*s)
}
return eu
}
// SetAirDate sets the "air_date" field.
func (eu *EpidodesUpdate) SetAirDate(s string) *EpidodesUpdate {
eu.mutation.SetAirDate(s)
return eu
}
// SetNillableAirDate sets the "air_date" field if the given value is not nil.
func (eu *EpidodesUpdate) SetNillableAirDate(s *string) *EpidodesUpdate {
if s != nil {
eu.SetAirDate(*s)
}
return eu
}
// Mutation returns the EpidodesMutation object of the builder.
func (eu *EpidodesUpdate) Mutation() *EpidodesMutation {
return eu.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (eu *EpidodesUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (eu *EpidodesUpdate) SaveX(ctx context.Context) int {
affected, err := eu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (eu *EpidodesUpdate) Exec(ctx context.Context) error {
_, err := eu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (eu *EpidodesUpdate) ExecX(ctx context.Context) {
if err := eu.Exec(ctx); err != nil {
panic(err)
}
}
func (eu *EpidodesUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(epidodes.Table, epidodes.Columns, sqlgraph.NewFieldSpec(epidodes.FieldID, field.TypeInt))
if ps := eu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := eu.mutation.SeriesID(); ok {
_spec.SetField(epidodes.FieldSeriesID, field.TypeInt, value)
}
if value, ok := eu.mutation.AddedSeriesID(); ok {
_spec.AddField(epidodes.FieldSeriesID, field.TypeInt, value)
}
if value, ok := eu.mutation.SeasonNumber(); ok {
_spec.SetField(epidodes.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.AddedSeasonNumber(); ok {
_spec.AddField(epidodes.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.EpisodeNumber(); ok {
_spec.SetField(epidodes.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.AddedEpisodeNumber(); ok {
_spec.AddField(epidodes.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.Title(); ok {
_spec.SetField(epidodes.FieldTitle, field.TypeString, value)
}
if value, ok := eu.mutation.Overview(); ok {
_spec.SetField(epidodes.FieldOverview, field.TypeString, value)
}
if value, ok := eu.mutation.AirDate(); ok {
_spec.SetField(epidodes.FieldAirDate, field.TypeString, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{epidodes.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
eu.mutation.done = true
return n, nil
}
// EpidodesUpdateOne is the builder for updating a single Epidodes entity.
type EpidodesUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EpidodesMutation
}
// SetSeriesID sets the "series_id" field.
func (euo *EpidodesUpdateOne) SetSeriesID(i int) *EpidodesUpdateOne {
euo.mutation.ResetSeriesID()
euo.mutation.SetSeriesID(i)
return euo
}
// SetNillableSeriesID sets the "series_id" field if the given value is not nil.
func (euo *EpidodesUpdateOne) SetNillableSeriesID(i *int) *EpidodesUpdateOne {
if i != nil {
euo.SetSeriesID(*i)
}
return euo
}
// AddSeriesID adds i to the "series_id" field.
func (euo *EpidodesUpdateOne) AddSeriesID(i int) *EpidodesUpdateOne {
euo.mutation.AddSeriesID(i)
return euo
}
// SetSeasonNumber sets the "season_number" field.
func (euo *EpidodesUpdateOne) SetSeasonNumber(i int) *EpidodesUpdateOne {
euo.mutation.ResetSeasonNumber()
euo.mutation.SetSeasonNumber(i)
return euo
}
// SetNillableSeasonNumber sets the "season_number" field if the given value is not nil.
func (euo *EpidodesUpdateOne) SetNillableSeasonNumber(i *int) *EpidodesUpdateOne {
if i != nil {
euo.SetSeasonNumber(*i)
}
return euo
}
// AddSeasonNumber adds i to the "season_number" field.
func (euo *EpidodesUpdateOne) AddSeasonNumber(i int) *EpidodesUpdateOne {
euo.mutation.AddSeasonNumber(i)
return euo
}
// SetEpisodeNumber sets the "episode_number" field.
func (euo *EpidodesUpdateOne) SetEpisodeNumber(i int) *EpidodesUpdateOne {
euo.mutation.ResetEpisodeNumber()
euo.mutation.SetEpisodeNumber(i)
return euo
}
// SetNillableEpisodeNumber sets the "episode_number" field if the given value is not nil.
func (euo *EpidodesUpdateOne) SetNillableEpisodeNumber(i *int) *EpidodesUpdateOne {
if i != nil {
euo.SetEpisodeNumber(*i)
}
return euo
}
// AddEpisodeNumber adds i to the "episode_number" field.
func (euo *EpidodesUpdateOne) AddEpisodeNumber(i int) *EpidodesUpdateOne {
euo.mutation.AddEpisodeNumber(i)
return euo
}
// SetTitle sets the "title" field.
func (euo *EpidodesUpdateOne) SetTitle(s string) *EpidodesUpdateOne {
euo.mutation.SetTitle(s)
return euo
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (euo *EpidodesUpdateOne) SetNillableTitle(s *string) *EpidodesUpdateOne {
if s != nil {
euo.SetTitle(*s)
}
return euo
}
// SetOverview sets the "overview" field.
func (euo *EpidodesUpdateOne) SetOverview(s string) *EpidodesUpdateOne {
euo.mutation.SetOverview(s)
return euo
}
// SetNillableOverview sets the "overview" field if the given value is not nil.
func (euo *EpidodesUpdateOne) SetNillableOverview(s *string) *EpidodesUpdateOne {
if s != nil {
euo.SetOverview(*s)
}
return euo
}
// SetAirDate sets the "air_date" field.
func (euo *EpidodesUpdateOne) SetAirDate(s string) *EpidodesUpdateOne {
euo.mutation.SetAirDate(s)
return euo
}
// SetNillableAirDate sets the "air_date" field if the given value is not nil.
func (euo *EpidodesUpdateOne) SetNillableAirDate(s *string) *EpidodesUpdateOne {
if s != nil {
euo.SetAirDate(*s)
}
return euo
}
// Mutation returns the EpidodesMutation object of the builder.
func (euo *EpidodesUpdateOne) Mutation() *EpidodesMutation {
return euo.mutation
}
// Where appends a list predicates to the EpidodesUpdate builder.
func (euo *EpidodesUpdateOne) Where(ps ...predicate.Epidodes) *EpidodesUpdateOne {
euo.mutation.Where(ps...)
return euo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (euo *EpidodesUpdateOne) Select(field string, fields ...string) *EpidodesUpdateOne {
euo.fields = append([]string{field}, fields...)
return euo
}
// Save executes the query and returns the updated Epidodes entity.
func (euo *EpidodesUpdateOne) Save(ctx context.Context) (*Epidodes, error) {
return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (euo *EpidodesUpdateOne) SaveX(ctx context.Context) *Epidodes {
node, err := euo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (euo *EpidodesUpdateOne) Exec(ctx context.Context) error {
_, err := euo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (euo *EpidodesUpdateOne) ExecX(ctx context.Context) {
if err := euo.Exec(ctx); err != nil {
panic(err)
}
}
func (euo *EpidodesUpdateOne) sqlSave(ctx context.Context) (_node *Epidodes, err error) {
_spec := sqlgraph.NewUpdateSpec(epidodes.Table, epidodes.Columns, sqlgraph.NewFieldSpec(epidodes.FieldID, field.TypeInt))
id, ok := euo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Epidodes.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := euo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, epidodes.FieldID)
for _, f := range fields {
if !epidodes.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != epidodes.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := euo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := euo.mutation.SeriesID(); ok {
_spec.SetField(epidodes.FieldSeriesID, field.TypeInt, value)
}
if value, ok := euo.mutation.AddedSeriesID(); ok {
_spec.AddField(epidodes.FieldSeriesID, field.TypeInt, value)
}
if value, ok := euo.mutation.SeasonNumber(); ok {
_spec.SetField(epidodes.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.AddedSeasonNumber(); ok {
_spec.AddField(epidodes.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.EpisodeNumber(); ok {
_spec.SetField(epidodes.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.AddedEpisodeNumber(); ok {
_spec.AddField(epidodes.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.Title(); ok {
_spec.SetField(epidodes.FieldTitle, field.TypeString, value)
}
if value, ok := euo.mutation.Overview(); ok {
_spec.SetField(epidodes.FieldOverview, field.TypeString, value)
}
if value, ok := euo.mutation.AirDate(); ok {
_spec.SetField(epidodes.FieldAirDate, field.TypeString, value)
}
_node = &Epidodes{config: euo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{epidodes.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
euo.mutation.done = true
return _node, nil
}

View File

@@ -4,20 +4,19 @@ package ent
import (
"fmt"
"polaris/ent/epidodes"
"polaris/ent/episode"
"polaris/ent/series"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Epidodes is the model entity for the Epidodes schema.
type Epidodes struct {
// Episode is the model entity for the Episode schema.
type Episode struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// SeriesID holds the value of the "series_id" field.
SeriesID int `json:"series_id,omitempty"`
// SeasonNumber holds the value of the "season_number" field.
SeasonNumber int `json:"season_number,omitempty"`
// EpisodeNumber holds the value of the "episode_number" field.
@@ -27,19 +26,45 @@ type Epidodes struct {
// Overview holds the value of the "overview" field.
Overview string `json:"overview,omitempty"`
// AirDate holds the value of the "air_date" field.
AirDate string `json:"air_date,omitempty"`
selectValues sql.SelectValues
AirDate string `json:"air_date,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the EpisodeQuery when eager-loading is set.
Edges EpisodeEdges `json:"edges"`
series_episodes *int
selectValues sql.SelectValues
}
// EpisodeEdges holds the relations/edges for other nodes in the graph.
type EpisodeEdges struct {
// Series holds the value of the series edge.
Series *Series `json:"series,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// SeriesOrErr returns the Series value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EpisodeEdges) SeriesOrErr() (*Series, error) {
if e.Series != nil {
return e.Series, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: series.Label}
}
return nil, &NotLoadedError{edge: "series"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Epidodes) scanValues(columns []string) ([]any, error) {
func (*Episode) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case epidodes.FieldID, epidodes.FieldSeriesID, epidodes.FieldSeasonNumber, epidodes.FieldEpisodeNumber:
case episode.FieldID, episode.FieldSeasonNumber, episode.FieldEpisodeNumber:
values[i] = new(sql.NullInt64)
case epidodes.FieldTitle, epidodes.FieldOverview, epidodes.FieldAirDate:
case episode.FieldTitle, episode.FieldOverview, episode.FieldAirDate:
values[i] = new(sql.NullString)
case episode.ForeignKeys[0]: // series_episodes
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
@@ -48,55 +73,56 @@ func (*Epidodes) scanValues(columns []string) ([]any, error) {
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Epidodes fields.
func (e *Epidodes) assignValues(columns []string, values []any) error {
// to the Episode fields.
func (e *Episode) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case epidodes.FieldID:
case episode.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
e.ID = int(value.Int64)
case epidodes.FieldSeriesID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field series_id", values[i])
} else if value.Valid {
e.SeriesID = int(value.Int64)
}
case epidodes.FieldSeasonNumber:
case episode.FieldSeasonNumber:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field season_number", values[i])
} else if value.Valid {
e.SeasonNumber = int(value.Int64)
}
case epidodes.FieldEpisodeNumber:
case episode.FieldEpisodeNumber:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field episode_number", values[i])
} else if value.Valid {
e.EpisodeNumber = int(value.Int64)
}
case epidodes.FieldTitle:
case episode.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
} else if value.Valid {
e.Title = value.String
}
case epidodes.FieldOverview:
case episode.FieldOverview:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field overview", values[i])
} else if value.Valid {
e.Overview = value.String
}
case epidodes.FieldAirDate:
case episode.FieldAirDate:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field air_date", values[i])
} else if value.Valid {
e.AirDate = value.String
}
case episode.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field series_episodes", value)
} else if value.Valid {
e.series_episodes = new(int)
*e.series_episodes = int(value.Int64)
}
default:
e.selectValues.Set(columns[i], values[i])
}
@@ -104,38 +130,40 @@ func (e *Epidodes) assignValues(columns []string, values []any) error {
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Epidodes.
// Value returns the ent.Value that was dynamically selected and assigned to the Episode.
// This includes values selected through modifiers, order, etc.
func (e *Epidodes) Value(name string) (ent.Value, error) {
func (e *Episode) Value(name string) (ent.Value, error) {
return e.selectValues.Get(name)
}
// Update returns a builder for updating this Epidodes.
// Note that you need to call Epidodes.Unwrap() before calling this method if this Epidodes
// was returned from a transaction, and the transaction was committed or rolled back.
func (e *Epidodes) Update() *EpidodesUpdateOne {
return NewEpidodesClient(e.config).UpdateOne(e)
// QuerySeries queries the "series" edge of the Episode entity.
func (e *Episode) QuerySeries() *SeriesQuery {
return NewEpisodeClient(e.config).QuerySeries(e)
}
// Unwrap unwraps the Epidodes entity that was returned from a transaction after it was closed,
// Update returns a builder for updating this Episode.
// Note that you need to call Episode.Unwrap() before calling this method if this Episode
// was returned from a transaction, and the transaction was committed or rolled back.
func (e *Episode) Update() *EpisodeUpdateOne {
return NewEpisodeClient(e.config).UpdateOne(e)
}
// Unwrap unwraps the Episode entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (e *Epidodes) Unwrap() *Epidodes {
func (e *Episode) Unwrap() *Episode {
_tx, ok := e.config.driver.(*txDriver)
if !ok {
panic("ent: Epidodes is not a transactional entity")
panic("ent: Episode is not a transactional entity")
}
e.config.driver = _tx.drv
return e
}
// String implements the fmt.Stringer.
func (e *Epidodes) String() string {
func (e *Episode) String() string {
var builder strings.Builder
builder.WriteString("Epidodes(")
builder.WriteString("Episode(")
builder.WriteString(fmt.Sprintf("id=%v, ", e.ID))
builder.WriteString("series_id=")
builder.WriteString(fmt.Sprintf("%v", e.SeriesID))
builder.WriteString(", ")
builder.WriteString("season_number=")
builder.WriteString(fmt.Sprintf("%v", e.SeasonNumber))
builder.WriteString(", ")
@@ -154,5 +182,5 @@ func (e *Epidodes) String() string {
return builder.String()
}
// EpidodesSlice is a parsable slice of Epidodes.
type EpidodesSlice []*Epidodes
// Episodes is a parsable slice of Episode.
type Episodes []*Episode

View File

@@ -1,18 +1,17 @@
// Code generated by ent, DO NOT EDIT.
package epidodes
package episode
import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the epidodes type in the database.
Label = "epidodes"
// Label holds the string label denoting the episode type in the database.
Label = "episode"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldSeriesID holds the string denoting the series_id field in the database.
FieldSeriesID = "series_id"
// FieldSeasonNumber holds the string denoting the season_number field in the database.
FieldSeasonNumber = "season_number"
// FieldEpisodeNumber holds the string denoting the episode_number field in the database.
@@ -23,14 +22,22 @@ const (
FieldOverview = "overview"
// FieldAirDate holds the string denoting the air_date field in the database.
FieldAirDate = "air_date"
// Table holds the table name of the epidodes in the database.
Table = "epidodes"
// EdgeSeries holds the string denoting the series edge name in mutations.
EdgeSeries = "series"
// Table holds the table name of the episode in the database.
Table = "episodes"
// SeriesTable is the table that holds the series relation/edge.
SeriesTable = "episodes"
// SeriesInverseTable is the table name for the Series entity.
// It exists in this package in order to avoid circular dependency with the "series" package.
SeriesInverseTable = "series"
// SeriesColumn is the table column denoting the series relation/edge.
SeriesColumn = "series_episodes"
)
// Columns holds all SQL columns for epidodes fields.
// Columns holds all SQL columns for episode fields.
var Columns = []string{
FieldID,
FieldSeriesID,
FieldSeasonNumber,
FieldEpisodeNumber,
FieldTitle,
@@ -38,6 +45,12 @@ var Columns = []string{
FieldAirDate,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "episodes"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"series_episodes",
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
@@ -45,10 +58,15 @@ func ValidColumn(column string) bool {
return true
}
}
for i := range ForeignKeys {
if column == ForeignKeys[i] {
return true
}
}
return false
}
// OrderOption defines the ordering options for the Epidodes queries.
// OrderOption defines the ordering options for the Episode queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
@@ -56,11 +74,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// BySeriesID orders the results by the series_id field.
func BySeriesID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSeriesID, opts...).ToFunc()
}
// BySeasonNumber orders the results by the season_number field.
func BySeasonNumber(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSeasonNumber, opts...).ToFunc()
@@ -85,3 +98,17 @@ func ByOverview(opts ...sql.OrderTermOption) OrderOption {
func ByAirDate(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAirDate, opts...).ToFunc()
}
// BySeriesField orders the results by series field.
func BySeriesField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSeriesStep(), sql.OrderByField(field, opts...))
}
}
func newSeriesStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SeriesInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SeriesTable, SeriesColumn),
)
}

393
ent/episode/where.go Normal file
View File

@@ -0,0 +1,393 @@
// Code generated by ent, DO NOT EDIT.
package episode
import (
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldID, id))
}
// SeasonNumber applies equality check predicate on the "season_number" field. It's identical to SeasonNumberEQ.
func SeasonNumber(v int) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldSeasonNumber, v))
}
// EpisodeNumber applies equality check predicate on the "episode_number" field. It's identical to EpisodeNumberEQ.
func EpisodeNumber(v int) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldEpisodeNumber, v))
}
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
func Title(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldTitle, v))
}
// Overview applies equality check predicate on the "overview" field. It's identical to OverviewEQ.
func Overview(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldOverview, v))
}
// AirDate applies equality check predicate on the "air_date" field. It's identical to AirDateEQ.
func AirDate(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldAirDate, v))
}
// SeasonNumberEQ applies the EQ predicate on the "season_number" field.
func SeasonNumberEQ(v int) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldSeasonNumber, v))
}
// SeasonNumberNEQ applies the NEQ predicate on the "season_number" field.
func SeasonNumberNEQ(v int) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldSeasonNumber, v))
}
// SeasonNumberIn applies the In predicate on the "season_number" field.
func SeasonNumberIn(vs ...int) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldSeasonNumber, vs...))
}
// SeasonNumberNotIn applies the NotIn predicate on the "season_number" field.
func SeasonNumberNotIn(vs ...int) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldSeasonNumber, vs...))
}
// SeasonNumberGT applies the GT predicate on the "season_number" field.
func SeasonNumberGT(v int) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldSeasonNumber, v))
}
// SeasonNumberGTE applies the GTE predicate on the "season_number" field.
func SeasonNumberGTE(v int) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldSeasonNumber, v))
}
// SeasonNumberLT applies the LT predicate on the "season_number" field.
func SeasonNumberLT(v int) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldSeasonNumber, v))
}
// SeasonNumberLTE applies the LTE predicate on the "season_number" field.
func SeasonNumberLTE(v int) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldSeasonNumber, v))
}
// EpisodeNumberEQ applies the EQ predicate on the "episode_number" field.
func EpisodeNumberEQ(v int) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldEpisodeNumber, v))
}
// EpisodeNumberNEQ applies the NEQ predicate on the "episode_number" field.
func EpisodeNumberNEQ(v int) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldEpisodeNumber, v))
}
// EpisodeNumberIn applies the In predicate on the "episode_number" field.
func EpisodeNumberIn(vs ...int) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldEpisodeNumber, vs...))
}
// EpisodeNumberNotIn applies the NotIn predicate on the "episode_number" field.
func EpisodeNumberNotIn(vs ...int) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldEpisodeNumber, vs...))
}
// EpisodeNumberGT applies the GT predicate on the "episode_number" field.
func EpisodeNumberGT(v int) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldEpisodeNumber, v))
}
// EpisodeNumberGTE applies the GTE predicate on the "episode_number" field.
func EpisodeNumberGTE(v int) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldEpisodeNumber, v))
}
// EpisodeNumberLT applies the LT predicate on the "episode_number" field.
func EpisodeNumberLT(v int) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldEpisodeNumber, v))
}
// EpisodeNumberLTE applies the LTE predicate on the "episode_number" field.
func EpisodeNumberLTE(v int) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldEpisodeNumber, v))
}
// TitleEQ applies the EQ predicate on the "title" field.
func TitleEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldTitle, v))
}
// TitleNEQ applies the NEQ predicate on the "title" field.
func TitleNEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldTitle, v))
}
// TitleIn applies the In predicate on the "title" field.
func TitleIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldTitle, vs...))
}
// TitleNotIn applies the NotIn predicate on the "title" field.
func TitleNotIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldTitle, vs...))
}
// TitleGT applies the GT predicate on the "title" field.
func TitleGT(v string) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldTitle, v))
}
// TitleGTE applies the GTE predicate on the "title" field.
func TitleGTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldTitle, v))
}
// TitleLT applies the LT predicate on the "title" field.
func TitleLT(v string) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldTitle, v))
}
// TitleLTE applies the LTE predicate on the "title" field.
func TitleLTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldTitle, v))
}
// TitleContains applies the Contains predicate on the "title" field.
func TitleContains(v string) predicate.Episode {
return predicate.Episode(sql.FieldContains(FieldTitle, v))
}
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
func TitleHasPrefix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasPrefix(FieldTitle, v))
}
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
func TitleHasSuffix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasSuffix(FieldTitle, v))
}
// TitleEqualFold applies the EqualFold predicate on the "title" field.
func TitleEqualFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldEqualFold(FieldTitle, v))
}
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
func TitleContainsFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldContainsFold(FieldTitle, v))
}
// OverviewEQ applies the EQ predicate on the "overview" field.
func OverviewEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldOverview, v))
}
// OverviewNEQ applies the NEQ predicate on the "overview" field.
func OverviewNEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldOverview, v))
}
// OverviewIn applies the In predicate on the "overview" field.
func OverviewIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldOverview, vs...))
}
// OverviewNotIn applies the NotIn predicate on the "overview" field.
func OverviewNotIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldOverview, vs...))
}
// OverviewGT applies the GT predicate on the "overview" field.
func OverviewGT(v string) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldOverview, v))
}
// OverviewGTE applies the GTE predicate on the "overview" field.
func OverviewGTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldOverview, v))
}
// OverviewLT applies the LT predicate on the "overview" field.
func OverviewLT(v string) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldOverview, v))
}
// OverviewLTE applies the LTE predicate on the "overview" field.
func OverviewLTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldOverview, v))
}
// OverviewContains applies the Contains predicate on the "overview" field.
func OverviewContains(v string) predicate.Episode {
return predicate.Episode(sql.FieldContains(FieldOverview, v))
}
// OverviewHasPrefix applies the HasPrefix predicate on the "overview" field.
func OverviewHasPrefix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasPrefix(FieldOverview, v))
}
// OverviewHasSuffix applies the HasSuffix predicate on the "overview" field.
func OverviewHasSuffix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasSuffix(FieldOverview, v))
}
// OverviewEqualFold applies the EqualFold predicate on the "overview" field.
func OverviewEqualFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldEqualFold(FieldOverview, v))
}
// OverviewContainsFold applies the ContainsFold predicate on the "overview" field.
func OverviewContainsFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldContainsFold(FieldOverview, v))
}
// AirDateEQ applies the EQ predicate on the "air_date" field.
func AirDateEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldEQ(FieldAirDate, v))
}
// AirDateNEQ applies the NEQ predicate on the "air_date" field.
func AirDateNEQ(v string) predicate.Episode {
return predicate.Episode(sql.FieldNEQ(FieldAirDate, v))
}
// AirDateIn applies the In predicate on the "air_date" field.
func AirDateIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldIn(FieldAirDate, vs...))
}
// AirDateNotIn applies the NotIn predicate on the "air_date" field.
func AirDateNotIn(vs ...string) predicate.Episode {
return predicate.Episode(sql.FieldNotIn(FieldAirDate, vs...))
}
// AirDateGT applies the GT predicate on the "air_date" field.
func AirDateGT(v string) predicate.Episode {
return predicate.Episode(sql.FieldGT(FieldAirDate, v))
}
// AirDateGTE applies the GTE predicate on the "air_date" field.
func AirDateGTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldGTE(FieldAirDate, v))
}
// AirDateLT applies the LT predicate on the "air_date" field.
func AirDateLT(v string) predicate.Episode {
return predicate.Episode(sql.FieldLT(FieldAirDate, v))
}
// AirDateLTE applies the LTE predicate on the "air_date" field.
func AirDateLTE(v string) predicate.Episode {
return predicate.Episode(sql.FieldLTE(FieldAirDate, v))
}
// AirDateContains applies the Contains predicate on the "air_date" field.
func AirDateContains(v string) predicate.Episode {
return predicate.Episode(sql.FieldContains(FieldAirDate, v))
}
// AirDateHasPrefix applies the HasPrefix predicate on the "air_date" field.
func AirDateHasPrefix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasPrefix(FieldAirDate, v))
}
// AirDateHasSuffix applies the HasSuffix predicate on the "air_date" field.
func AirDateHasSuffix(v string) predicate.Episode {
return predicate.Episode(sql.FieldHasSuffix(FieldAirDate, v))
}
// AirDateEqualFold applies the EqualFold predicate on the "air_date" field.
func AirDateEqualFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldEqualFold(FieldAirDate, v))
}
// AirDateContainsFold applies the ContainsFold predicate on the "air_date" field.
func AirDateContainsFold(v string) predicate.Episode {
return predicate.Episode(sql.FieldContainsFold(FieldAirDate, v))
}
// HasSeries applies the HasEdge predicate on the "series" edge.
func HasSeries() predicate.Episode {
return predicate.Episode(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SeriesTable, SeriesColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSeriesWith applies the HasEdge predicate on the "series" edge with a given conditions (other predicates).
func HasSeriesWith(preds ...predicate.Series) predicate.Episode {
return predicate.Episode(func(s *sql.Selector) {
step := newSeriesStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Episode) predicate.Episode {
return predicate.Episode(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Episode) predicate.Episode {
return predicate.Episode(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Episode) predicate.Episode {
return predicate.Episode(sql.NotPredicates(p))
}

View File

@@ -6,67 +6,81 @@ import (
"context"
"errors"
"fmt"
"polaris/ent/epidodes"
"polaris/ent/episode"
"polaris/ent/series"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// EpidodesCreate is the builder for creating a Epidodes entity.
type EpidodesCreate struct {
// EpisodeCreate is the builder for creating a Episode entity.
type EpisodeCreate struct {
config
mutation *EpidodesMutation
mutation *EpisodeMutation
hooks []Hook
}
// SetSeriesID sets the "series_id" field.
func (ec *EpidodesCreate) SetSeriesID(i int) *EpidodesCreate {
ec.mutation.SetSeriesID(i)
return ec
}
// SetSeasonNumber sets the "season_number" field.
func (ec *EpidodesCreate) SetSeasonNumber(i int) *EpidodesCreate {
func (ec *EpisodeCreate) SetSeasonNumber(i int) *EpisodeCreate {
ec.mutation.SetSeasonNumber(i)
return ec
}
// SetEpisodeNumber sets the "episode_number" field.
func (ec *EpidodesCreate) SetEpisodeNumber(i int) *EpidodesCreate {
func (ec *EpisodeCreate) SetEpisodeNumber(i int) *EpisodeCreate {
ec.mutation.SetEpisodeNumber(i)
return ec
}
// SetTitle sets the "title" field.
func (ec *EpidodesCreate) SetTitle(s string) *EpidodesCreate {
func (ec *EpisodeCreate) SetTitle(s string) *EpisodeCreate {
ec.mutation.SetTitle(s)
return ec
}
// SetOverview sets the "overview" field.
func (ec *EpidodesCreate) SetOverview(s string) *EpidodesCreate {
func (ec *EpisodeCreate) SetOverview(s string) *EpisodeCreate {
ec.mutation.SetOverview(s)
return ec
}
// SetAirDate sets the "air_date" field.
func (ec *EpidodesCreate) SetAirDate(s string) *EpidodesCreate {
func (ec *EpisodeCreate) SetAirDate(s string) *EpisodeCreate {
ec.mutation.SetAirDate(s)
return ec
}
// Mutation returns the EpidodesMutation object of the builder.
func (ec *EpidodesCreate) Mutation() *EpidodesMutation {
// SetSeriesID sets the "series" edge to the Series entity by ID.
func (ec *EpisodeCreate) SetSeriesID(id int) *EpisodeCreate {
ec.mutation.SetSeriesID(id)
return ec
}
// SetNillableSeriesID sets the "series" edge to the Series entity by ID if the given value is not nil.
func (ec *EpisodeCreate) SetNillableSeriesID(id *int) *EpisodeCreate {
if id != nil {
ec = ec.SetSeriesID(*id)
}
return ec
}
// SetSeries sets the "series" edge to the Series entity.
func (ec *EpisodeCreate) SetSeries(s *Series) *EpisodeCreate {
return ec.SetSeriesID(s.ID)
}
// Mutation returns the EpisodeMutation object of the builder.
func (ec *EpisodeCreate) Mutation() *EpisodeMutation {
return ec.mutation
}
// Save creates the Epidodes in the database.
func (ec *EpidodesCreate) Save(ctx context.Context) (*Epidodes, error) {
// Save creates the Episode in the database.
func (ec *EpisodeCreate) Save(ctx context.Context) (*Episode, error) {
return withHooks(ctx, ec.sqlSave, ec.mutation, ec.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (ec *EpidodesCreate) SaveX(ctx context.Context) *Epidodes {
func (ec *EpisodeCreate) SaveX(ctx context.Context) *Episode {
v, err := ec.Save(ctx)
if err != nil {
panic(err)
@@ -75,42 +89,39 @@ func (ec *EpidodesCreate) SaveX(ctx context.Context) *Epidodes {
}
// Exec executes the query.
func (ec *EpidodesCreate) Exec(ctx context.Context) error {
func (ec *EpisodeCreate) Exec(ctx context.Context) error {
_, err := ec.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ec *EpidodesCreate) ExecX(ctx context.Context) {
func (ec *EpisodeCreate) ExecX(ctx context.Context) {
if err := ec.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (ec *EpidodesCreate) check() error {
if _, ok := ec.mutation.SeriesID(); !ok {
return &ValidationError{Name: "series_id", err: errors.New(`ent: missing required field "Epidodes.series_id"`)}
}
func (ec *EpisodeCreate) check() error {
if _, ok := ec.mutation.SeasonNumber(); !ok {
return &ValidationError{Name: "season_number", err: errors.New(`ent: missing required field "Epidodes.season_number"`)}
return &ValidationError{Name: "season_number", err: errors.New(`ent: missing required field "Episode.season_number"`)}
}
if _, ok := ec.mutation.EpisodeNumber(); !ok {
return &ValidationError{Name: "episode_number", err: errors.New(`ent: missing required field "Epidodes.episode_number"`)}
return &ValidationError{Name: "episode_number", err: errors.New(`ent: missing required field "Episode.episode_number"`)}
}
if _, ok := ec.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Epidodes.title"`)}
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Episode.title"`)}
}
if _, ok := ec.mutation.Overview(); !ok {
return &ValidationError{Name: "overview", err: errors.New(`ent: missing required field "Epidodes.overview"`)}
return &ValidationError{Name: "overview", err: errors.New(`ent: missing required field "Episode.overview"`)}
}
if _, ok := ec.mutation.AirDate(); !ok {
return &ValidationError{Name: "air_date", err: errors.New(`ent: missing required field "Epidodes.air_date"`)}
return &ValidationError{Name: "air_date", err: errors.New(`ent: missing required field "Episode.air_date"`)}
}
return nil
}
func (ec *EpidodesCreate) sqlSave(ctx context.Context) (*Epidodes, error) {
func (ec *EpisodeCreate) sqlSave(ctx context.Context) (*Episode, error) {
if err := ec.check(); err != nil {
return nil, err
}
@@ -128,58 +139,71 @@ func (ec *EpidodesCreate) sqlSave(ctx context.Context) (*Epidodes, error) {
return _node, nil
}
func (ec *EpidodesCreate) createSpec() (*Epidodes, *sqlgraph.CreateSpec) {
func (ec *EpisodeCreate) createSpec() (*Episode, *sqlgraph.CreateSpec) {
var (
_node = &Epidodes{config: ec.config}
_spec = sqlgraph.NewCreateSpec(epidodes.Table, sqlgraph.NewFieldSpec(epidodes.FieldID, field.TypeInt))
_node = &Episode{config: ec.config}
_spec = sqlgraph.NewCreateSpec(episode.Table, sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt))
)
if value, ok := ec.mutation.SeriesID(); ok {
_spec.SetField(epidodes.FieldSeriesID, field.TypeInt, value)
_node.SeriesID = value
}
if value, ok := ec.mutation.SeasonNumber(); ok {
_spec.SetField(epidodes.FieldSeasonNumber, field.TypeInt, value)
_spec.SetField(episode.FieldSeasonNumber, field.TypeInt, value)
_node.SeasonNumber = value
}
if value, ok := ec.mutation.EpisodeNumber(); ok {
_spec.SetField(epidodes.FieldEpisodeNumber, field.TypeInt, value)
_spec.SetField(episode.FieldEpisodeNumber, field.TypeInt, value)
_node.EpisodeNumber = value
}
if value, ok := ec.mutation.Title(); ok {
_spec.SetField(epidodes.FieldTitle, field.TypeString, value)
_spec.SetField(episode.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := ec.mutation.Overview(); ok {
_spec.SetField(epidodes.FieldOverview, field.TypeString, value)
_spec.SetField(episode.FieldOverview, field.TypeString, value)
_node.Overview = value
}
if value, ok := ec.mutation.AirDate(); ok {
_spec.SetField(epidodes.FieldAirDate, field.TypeString, value)
_spec.SetField(episode.FieldAirDate, field.TypeString, value)
_node.AirDate = value
}
if nodes := ec.mutation.SeriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: episode.SeriesTable,
Columns: []string{episode.SeriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(series.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.series_episodes = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// EpidodesCreateBulk is the builder for creating many Epidodes entities in bulk.
type EpidodesCreateBulk struct {
// EpisodeCreateBulk is the builder for creating many Episode entities in bulk.
type EpisodeCreateBulk struct {
config
err error
builders []*EpidodesCreate
builders []*EpisodeCreate
}
// Save creates the Epidodes entities in the database.
func (ecb *EpidodesCreateBulk) Save(ctx context.Context) ([]*Epidodes, error) {
// Save creates the Episode entities in the database.
func (ecb *EpisodeCreateBulk) Save(ctx context.Context) ([]*Episode, error) {
if ecb.err != nil {
return nil, ecb.err
}
specs := make([]*sqlgraph.CreateSpec, len(ecb.builders))
nodes := make([]*Epidodes, len(ecb.builders))
nodes := make([]*Episode, len(ecb.builders))
mutators := make([]Mutator, len(ecb.builders))
for i := range ecb.builders {
func(i int, root context.Context) {
builder := ecb.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*EpidodesMutation)
mutation, ok := m.(*EpisodeMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
@@ -226,7 +250,7 @@ func (ecb *EpidodesCreateBulk) Save(ctx context.Context) ([]*Epidodes, error) {
}
// SaveX is like Save, but panics if an error occurs.
func (ecb *EpidodesCreateBulk) SaveX(ctx context.Context) []*Epidodes {
func (ecb *EpisodeCreateBulk) SaveX(ctx context.Context) []*Episode {
v, err := ecb.Save(ctx)
if err != nil {
panic(err)
@@ -235,13 +259,13 @@ func (ecb *EpidodesCreateBulk) SaveX(ctx context.Context) []*Epidodes {
}
// Exec executes the query.
func (ecb *EpidodesCreateBulk) Exec(ctx context.Context) error {
func (ecb *EpisodeCreateBulk) Exec(ctx context.Context) error {
_, err := ecb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ecb *EpidodesCreateBulk) ExecX(ctx context.Context) {
func (ecb *EpisodeCreateBulk) ExecX(ctx context.Context) {
if err := ecb.Exec(ctx); err != nil {
panic(err)
}

View File

@@ -4,7 +4,7 @@ package ent
import (
"context"
"polaris/ent/epidodes"
"polaris/ent/episode"
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
@@ -12,26 +12,26 @@ import (
"entgo.io/ent/schema/field"
)
// EpidodesDelete is the builder for deleting a Epidodes entity.
type EpidodesDelete struct {
// EpisodeDelete is the builder for deleting a Episode entity.
type EpisodeDelete struct {
config
hooks []Hook
mutation *EpidodesMutation
mutation *EpisodeMutation
}
// Where appends a list predicates to the EpidodesDelete builder.
func (ed *EpidodesDelete) Where(ps ...predicate.Epidodes) *EpidodesDelete {
// Where appends a list predicates to the EpisodeDelete builder.
func (ed *EpisodeDelete) Where(ps ...predicate.Episode) *EpisodeDelete {
ed.mutation.Where(ps...)
return ed
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (ed *EpidodesDelete) Exec(ctx context.Context) (int, error) {
func (ed *EpisodeDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, ed.sqlExec, ed.mutation, ed.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (ed *EpidodesDelete) ExecX(ctx context.Context) int {
func (ed *EpisodeDelete) ExecX(ctx context.Context) int {
n, err := ed.Exec(ctx)
if err != nil {
panic(err)
@@ -39,8 +39,8 @@ func (ed *EpidodesDelete) ExecX(ctx context.Context) int {
return n
}
func (ed *EpidodesDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(epidodes.Table, sqlgraph.NewFieldSpec(epidodes.FieldID, field.TypeInt))
func (ed *EpisodeDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(episode.Table, sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt))
if ps := ed.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
@@ -56,32 +56,32 @@ func (ed *EpidodesDelete) sqlExec(ctx context.Context) (int, error) {
return affected, err
}
// EpidodesDeleteOne is the builder for deleting a single Epidodes entity.
type EpidodesDeleteOne struct {
ed *EpidodesDelete
// EpisodeDeleteOne is the builder for deleting a single Episode entity.
type EpisodeDeleteOne struct {
ed *EpisodeDelete
}
// Where appends a list predicates to the EpidodesDelete builder.
func (edo *EpidodesDeleteOne) Where(ps ...predicate.Epidodes) *EpidodesDeleteOne {
// Where appends a list predicates to the EpisodeDelete builder.
func (edo *EpisodeDeleteOne) Where(ps ...predicate.Episode) *EpisodeDeleteOne {
edo.ed.mutation.Where(ps...)
return edo
}
// Exec executes the deletion query.
func (edo *EpidodesDeleteOne) Exec(ctx context.Context) error {
func (edo *EpisodeDeleteOne) Exec(ctx context.Context) error {
n, err := edo.ed.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{epidodes.Label}
return &NotFoundError{episode.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (edo *EpidodesDeleteOne) ExecX(ctx context.Context) {
func (edo *EpisodeDeleteOne) ExecX(ctx context.Context) {
if err := edo.Exec(ctx); err != nil {
panic(err)
}

View File

@@ -6,72 +6,97 @@ import (
"context"
"fmt"
"math"
"polaris/ent/epidodes"
"polaris/ent/episode"
"polaris/ent/predicate"
"polaris/ent/series"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// EpidodesQuery is the builder for querying Epidodes entities.
type EpidodesQuery struct {
// EpisodeQuery is the builder for querying Episode entities.
type EpisodeQuery struct {
config
ctx *QueryContext
order []epidodes.OrderOption
order []episode.OrderOption
inters []Interceptor
predicates []predicate.Epidodes
predicates []predicate.Episode
withSeries *SeriesQuery
withFKs bool
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the EpidodesQuery builder.
func (eq *EpidodesQuery) Where(ps ...predicate.Epidodes) *EpidodesQuery {
// Where adds a new predicate for the EpisodeQuery builder.
func (eq *EpisodeQuery) Where(ps ...predicate.Episode) *EpisodeQuery {
eq.predicates = append(eq.predicates, ps...)
return eq
}
// Limit the number of records to be returned by this query.
func (eq *EpidodesQuery) Limit(limit int) *EpidodesQuery {
func (eq *EpisodeQuery) Limit(limit int) *EpisodeQuery {
eq.ctx.Limit = &limit
return eq
}
// Offset to start from.
func (eq *EpidodesQuery) Offset(offset int) *EpidodesQuery {
func (eq *EpisodeQuery) Offset(offset int) *EpisodeQuery {
eq.ctx.Offset = &offset
return eq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (eq *EpidodesQuery) Unique(unique bool) *EpidodesQuery {
func (eq *EpisodeQuery) Unique(unique bool) *EpisodeQuery {
eq.ctx.Unique = &unique
return eq
}
// Order specifies how the records should be ordered.
func (eq *EpidodesQuery) Order(o ...epidodes.OrderOption) *EpidodesQuery {
func (eq *EpisodeQuery) Order(o ...episode.OrderOption) *EpisodeQuery {
eq.order = append(eq.order, o...)
return eq
}
// First returns the first Epidodes entity from the query.
// Returns a *NotFoundError when no Epidodes was found.
func (eq *EpidodesQuery) First(ctx context.Context) (*Epidodes, error) {
// QuerySeries chains the current query on the "series" edge.
func (eq *EpisodeQuery) QuerySeries() *SeriesQuery {
query := (&SeriesClient{config: eq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := eq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := eq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(episode.Table, episode.FieldID, selector),
sqlgraph.To(series.Table, series.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, episode.SeriesTable, episode.SeriesColumn),
)
fromU = sqlgraph.SetNeighbors(eq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first Episode entity from the query.
// Returns a *NotFoundError when no Episode was found.
func (eq *EpisodeQuery) First(ctx context.Context) (*Episode, error) {
nodes, err := eq.Limit(1).All(setContextOp(ctx, eq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{epidodes.Label}
return nil, &NotFoundError{episode.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (eq *EpidodesQuery) FirstX(ctx context.Context) *Epidodes {
func (eq *EpisodeQuery) FirstX(ctx context.Context) *Episode {
node, err := eq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
@@ -79,22 +104,22 @@ func (eq *EpidodesQuery) FirstX(ctx context.Context) *Epidodes {
return node
}
// FirstID returns the first Epidodes ID from the query.
// Returns a *NotFoundError when no Epidodes ID was found.
func (eq *EpidodesQuery) FirstID(ctx context.Context) (id int, err error) {
// FirstID returns the first Episode ID from the query.
// Returns a *NotFoundError when no Episode ID was found.
func (eq *EpisodeQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = eq.Limit(1).IDs(setContextOp(ctx, eq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{epidodes.Label}
err = &NotFoundError{episode.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (eq *EpidodesQuery) FirstIDX(ctx context.Context) int {
func (eq *EpisodeQuery) FirstIDX(ctx context.Context) int {
id, err := eq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
@@ -102,10 +127,10 @@ func (eq *EpidodesQuery) FirstIDX(ctx context.Context) int {
return id
}
// Only returns a single Epidodes entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Epidodes entity is found.
// Returns a *NotFoundError when no Epidodes entities are found.
func (eq *EpidodesQuery) Only(ctx context.Context) (*Epidodes, error) {
// Only returns a single Episode entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Episode entity is found.
// Returns a *NotFoundError when no Episode entities are found.
func (eq *EpisodeQuery) Only(ctx context.Context) (*Episode, error) {
nodes, err := eq.Limit(2).All(setContextOp(ctx, eq.ctx, "Only"))
if err != nil {
return nil, err
@@ -114,14 +139,14 @@ func (eq *EpidodesQuery) Only(ctx context.Context) (*Epidodes, error) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{epidodes.Label}
return nil, &NotFoundError{episode.Label}
default:
return nil, &NotSingularError{epidodes.Label}
return nil, &NotSingularError{episode.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (eq *EpidodesQuery) OnlyX(ctx context.Context) *Epidodes {
func (eq *EpisodeQuery) OnlyX(ctx context.Context) *Episode {
node, err := eq.Only(ctx)
if err != nil {
panic(err)
@@ -129,10 +154,10 @@ func (eq *EpidodesQuery) OnlyX(ctx context.Context) *Epidodes {
return node
}
// OnlyID is like Only, but returns the only Epidodes ID in the query.
// Returns a *NotSingularError when more than one Epidodes ID is found.
// OnlyID is like Only, but returns the only Episode ID in the query.
// Returns a *NotSingularError when more than one Episode ID is found.
// Returns a *NotFoundError when no entities are found.
func (eq *EpidodesQuery) OnlyID(ctx context.Context) (id int, err error) {
func (eq *EpisodeQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = eq.Limit(2).IDs(setContextOp(ctx, eq.ctx, "OnlyID")); err != nil {
return
@@ -141,15 +166,15 @@ func (eq *EpidodesQuery) OnlyID(ctx context.Context) (id int, err error) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{epidodes.Label}
err = &NotFoundError{episode.Label}
default:
err = &NotSingularError{epidodes.Label}
err = &NotSingularError{episode.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (eq *EpidodesQuery) OnlyIDX(ctx context.Context) int {
func (eq *EpisodeQuery) OnlyIDX(ctx context.Context) int {
id, err := eq.OnlyID(ctx)
if err != nil {
panic(err)
@@ -157,18 +182,18 @@ func (eq *EpidodesQuery) OnlyIDX(ctx context.Context) int {
return id
}
// All executes the query and returns a list of EpidodesSlice.
func (eq *EpidodesQuery) All(ctx context.Context) ([]*Epidodes, error) {
// All executes the query and returns a list of Episodes.
func (eq *EpisodeQuery) All(ctx context.Context) ([]*Episode, error) {
ctx = setContextOp(ctx, eq.ctx, "All")
if err := eq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Epidodes, *EpidodesQuery]()
return withInterceptors[[]*Epidodes](ctx, eq, qr, eq.inters)
qr := querierAll[[]*Episode, *EpisodeQuery]()
return withInterceptors[[]*Episode](ctx, eq, qr, eq.inters)
}
// AllX is like All, but panics if an error occurs.
func (eq *EpidodesQuery) AllX(ctx context.Context) []*Epidodes {
func (eq *EpisodeQuery) AllX(ctx context.Context) []*Episode {
nodes, err := eq.All(ctx)
if err != nil {
panic(err)
@@ -176,20 +201,20 @@ func (eq *EpidodesQuery) AllX(ctx context.Context) []*Epidodes {
return nodes
}
// IDs executes the query and returns a list of Epidodes IDs.
func (eq *EpidodesQuery) IDs(ctx context.Context) (ids []int, err error) {
// IDs executes the query and returns a list of Episode IDs.
func (eq *EpisodeQuery) IDs(ctx context.Context) (ids []int, err error) {
if eq.ctx.Unique == nil && eq.path != nil {
eq.Unique(true)
}
ctx = setContextOp(ctx, eq.ctx, "IDs")
if err = eq.Select(epidodes.FieldID).Scan(ctx, &ids); err != nil {
if err = eq.Select(episode.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (eq *EpidodesQuery) IDsX(ctx context.Context) []int {
func (eq *EpisodeQuery) IDsX(ctx context.Context) []int {
ids, err := eq.IDs(ctx)
if err != nil {
panic(err)
@@ -198,16 +223,16 @@ func (eq *EpidodesQuery) IDsX(ctx context.Context) []int {
}
// Count returns the count of the given query.
func (eq *EpidodesQuery) Count(ctx context.Context) (int, error) {
func (eq *EpisodeQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, eq.ctx, "Count")
if err := eq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, eq, querierCount[*EpidodesQuery](), eq.inters)
return withInterceptors[int](ctx, eq, querierCount[*EpisodeQuery](), eq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (eq *EpidodesQuery) CountX(ctx context.Context) int {
func (eq *EpisodeQuery) CountX(ctx context.Context) int {
count, err := eq.Count(ctx)
if err != nil {
panic(err)
@@ -216,7 +241,7 @@ func (eq *EpidodesQuery) CountX(ctx context.Context) int {
}
// Exist returns true if the query has elements in the graph.
func (eq *EpidodesQuery) Exist(ctx context.Context) (bool, error) {
func (eq *EpisodeQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, eq.ctx, "Exist")
switch _, err := eq.FirstID(ctx); {
case IsNotFound(err):
@@ -229,7 +254,7 @@ func (eq *EpidodesQuery) Exist(ctx context.Context) (bool, error) {
}
// ExistX is like Exist, but panics if an error occurs.
func (eq *EpidodesQuery) ExistX(ctx context.Context) bool {
func (eq *EpisodeQuery) ExistX(ctx context.Context) bool {
exist, err := eq.Exist(ctx)
if err != nil {
panic(err)
@@ -237,43 +262,55 @@ func (eq *EpidodesQuery) ExistX(ctx context.Context) bool {
return exist
}
// Clone returns a duplicate of the EpidodesQuery builder, including all associated steps. It can be
// Clone returns a duplicate of the EpisodeQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (eq *EpidodesQuery) Clone() *EpidodesQuery {
func (eq *EpisodeQuery) Clone() *EpisodeQuery {
if eq == nil {
return nil
}
return &EpidodesQuery{
return &EpisodeQuery{
config: eq.config,
ctx: eq.ctx.Clone(),
order: append([]epidodes.OrderOption{}, eq.order...),
order: append([]episode.OrderOption{}, eq.order...),
inters: append([]Interceptor{}, eq.inters...),
predicates: append([]predicate.Epidodes{}, eq.predicates...),
predicates: append([]predicate.Episode{}, eq.predicates...),
withSeries: eq.withSeries.Clone(),
// clone intermediate query.
sql: eq.sql.Clone(),
path: eq.path,
}
}
// WithSeries tells the query-builder to eager-load the nodes that are connected to
// the "series" edge. The optional arguments are used to configure the query builder of the edge.
func (eq *EpisodeQuery) WithSeries(opts ...func(*SeriesQuery)) *EpisodeQuery {
query := (&SeriesClient{config: eq.config}).Query()
for _, opt := range opts {
opt(query)
}
eq.withSeries = query
return eq
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// SeriesID int `json:"series_id,omitempty"`
// SeasonNumber int `json:"season_number,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Epidodes.Query().
// GroupBy(epidodes.FieldSeriesID).
// client.Episode.Query().
// GroupBy(episode.FieldSeasonNumber).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (eq *EpidodesQuery) GroupBy(field string, fields ...string) *EpidodesGroupBy {
func (eq *EpisodeQuery) GroupBy(field string, fields ...string) *EpisodeGroupBy {
eq.ctx.Fields = append([]string{field}, fields...)
grbuild := &EpidodesGroupBy{build: eq}
grbuild := &EpisodeGroupBy{build: eq}
grbuild.flds = &eq.ctx.Fields
grbuild.label = epidodes.Label
grbuild.label = episode.Label
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -284,26 +321,26 @@ func (eq *EpidodesQuery) GroupBy(field string, fields ...string) *EpidodesGroupB
// Example:
//
// var v []struct {
// SeriesID int `json:"series_id,omitempty"`
// SeasonNumber int `json:"season_number,omitempty"`
// }
//
// client.Epidodes.Query().
// Select(epidodes.FieldSeriesID).
// client.Episode.Query().
// Select(episode.FieldSeasonNumber).
// Scan(ctx, &v)
func (eq *EpidodesQuery) Select(fields ...string) *EpidodesSelect {
func (eq *EpisodeQuery) Select(fields ...string) *EpisodeSelect {
eq.ctx.Fields = append(eq.ctx.Fields, fields...)
sbuild := &EpidodesSelect{EpidodesQuery: eq}
sbuild.label = epidodes.Label
sbuild := &EpisodeSelect{EpisodeQuery: eq}
sbuild.label = episode.Label
sbuild.flds, sbuild.scan = &eq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a EpidodesSelect configured with the given aggregations.
func (eq *EpidodesQuery) Aggregate(fns ...AggregateFunc) *EpidodesSelect {
// Aggregate returns a EpisodeSelect configured with the given aggregations.
func (eq *EpisodeQuery) Aggregate(fns ...AggregateFunc) *EpisodeSelect {
return eq.Select().Aggregate(fns...)
}
func (eq *EpidodesQuery) prepareQuery(ctx context.Context) error {
func (eq *EpisodeQuery) prepareQuery(ctx context.Context) error {
for _, inter := range eq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
@@ -315,7 +352,7 @@ func (eq *EpidodesQuery) prepareQuery(ctx context.Context) error {
}
}
for _, f := range eq.ctx.Fields {
if !epidodes.ValidColumn(f) {
if !episode.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
@@ -329,17 +366,28 @@ func (eq *EpidodesQuery) prepareQuery(ctx context.Context) error {
return nil
}
func (eq *EpidodesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Epidodes, error) {
func (eq *EpisodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Episode, error) {
var (
nodes = []*Epidodes{}
_spec = eq.querySpec()
nodes = []*Episode{}
withFKs = eq.withFKs
_spec = eq.querySpec()
loadedTypes = [1]bool{
eq.withSeries != nil,
}
)
if eq.withSeries != nil {
withFKs = true
}
if withFKs {
_spec.Node.Columns = append(_spec.Node.Columns, episode.ForeignKeys...)
}
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Epidodes).scanValues(nil, columns)
return (*Episode).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Epidodes{config: eq.config}
node := &Episode{config: eq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
@@ -351,10 +399,49 @@ func (eq *EpidodesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Epi
if len(nodes) == 0 {
return nodes, nil
}
if query := eq.withSeries; query != nil {
if err := eq.loadSeries(ctx, query, nodes, nil,
func(n *Episode, e *Series) { n.Edges.Series = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (eq *EpidodesQuery) sqlCount(ctx context.Context) (int, error) {
func (eq *EpisodeQuery) loadSeries(ctx context.Context, query *SeriesQuery, nodes []*Episode, init func(*Episode), assign func(*Episode, *Series)) error {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*Episode)
for i := range nodes {
if nodes[i].series_episodes == nil {
continue
}
fk := *nodes[i].series_episodes
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(series.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "series_episodes" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (eq *EpisodeQuery) sqlCount(ctx context.Context) (int, error) {
_spec := eq.querySpec()
_spec.Node.Columns = eq.ctx.Fields
if len(eq.ctx.Fields) > 0 {
@@ -363,8 +450,8 @@ func (eq *EpidodesQuery) sqlCount(ctx context.Context) (int, error) {
return sqlgraph.CountNodes(ctx, eq.driver, _spec)
}
func (eq *EpidodesQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(epidodes.Table, epidodes.Columns, sqlgraph.NewFieldSpec(epidodes.FieldID, field.TypeInt))
func (eq *EpisodeQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(episode.Table, episode.Columns, sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt))
_spec.From = eq.sql
if unique := eq.ctx.Unique; unique != nil {
_spec.Unique = *unique
@@ -373,9 +460,9 @@ func (eq *EpidodesQuery) querySpec() *sqlgraph.QuerySpec {
}
if fields := eq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, epidodes.FieldID)
_spec.Node.Columns = append(_spec.Node.Columns, episode.FieldID)
for i := range fields {
if fields[i] != epidodes.FieldID {
if fields[i] != episode.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
@@ -403,12 +490,12 @@ func (eq *EpidodesQuery) querySpec() *sqlgraph.QuerySpec {
return _spec
}
func (eq *EpidodesQuery) sqlQuery(ctx context.Context) *sql.Selector {
func (eq *EpisodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(eq.driver.Dialect())
t1 := builder.Table(epidodes.Table)
t1 := builder.Table(episode.Table)
columns := eq.ctx.Fields
if len(columns) == 0 {
columns = epidodes.Columns
columns = episode.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if eq.sql != nil {
@@ -435,28 +522,28 @@ func (eq *EpidodesQuery) sqlQuery(ctx context.Context) *sql.Selector {
return selector
}
// EpidodesGroupBy is the group-by builder for Epidodes entities.
type EpidodesGroupBy struct {
// EpisodeGroupBy is the group-by builder for Episode entities.
type EpisodeGroupBy struct {
selector
build *EpidodesQuery
build *EpisodeQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (egb *EpidodesGroupBy) Aggregate(fns ...AggregateFunc) *EpidodesGroupBy {
func (egb *EpisodeGroupBy) Aggregate(fns ...AggregateFunc) *EpisodeGroupBy {
egb.fns = append(egb.fns, fns...)
return egb
}
// Scan applies the selector query and scans the result into the given value.
func (egb *EpidodesGroupBy) Scan(ctx context.Context, v any) error {
func (egb *EpisodeGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, egb.build.ctx, "GroupBy")
if err := egb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*EpidodesQuery, *EpidodesGroupBy](ctx, egb.build, egb, egb.build.inters, v)
return scanWithInterceptors[*EpisodeQuery, *EpisodeGroupBy](ctx, egb.build, egb, egb.build.inters, v)
}
func (egb *EpidodesGroupBy) sqlScan(ctx context.Context, root *EpidodesQuery, v any) error {
func (egb *EpisodeGroupBy) sqlScan(ctx context.Context, root *EpisodeQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(egb.fns))
for _, fn := range egb.fns {
@@ -483,28 +570,28 @@ func (egb *EpidodesGroupBy) sqlScan(ctx context.Context, root *EpidodesQuery, v
return sql.ScanSlice(rows, v)
}
// EpidodesSelect is the builder for selecting fields of Epidodes entities.
type EpidodesSelect struct {
*EpidodesQuery
// EpisodeSelect is the builder for selecting fields of Episode entities.
type EpisodeSelect struct {
*EpisodeQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (es *EpidodesSelect) Aggregate(fns ...AggregateFunc) *EpidodesSelect {
func (es *EpisodeSelect) Aggregate(fns ...AggregateFunc) *EpisodeSelect {
es.fns = append(es.fns, fns...)
return es
}
// Scan applies the selector query and scans the result into the given value.
func (es *EpidodesSelect) Scan(ctx context.Context, v any) error {
func (es *EpisodeSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, es.ctx, "Select")
if err := es.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*EpidodesQuery, *EpidodesSelect](ctx, es.EpidodesQuery, es, es.inters, v)
return scanWithInterceptors[*EpisodeQuery, *EpisodeSelect](ctx, es.EpisodeQuery, es, es.inters, v)
}
func (es *EpidodesSelect) sqlScan(ctx context.Context, root *EpidodesQuery, v any) error {
func (es *EpisodeSelect) sqlScan(ctx context.Context, root *EpisodeQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(es.fns))
for _, fn := range es.fns {

494
ent/episode_update.go Normal file
View File

@@ -0,0 +1,494 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/episode"
"polaris/ent/predicate"
"polaris/ent/series"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// EpisodeUpdate is the builder for updating Episode entities.
type EpisodeUpdate struct {
config
hooks []Hook
mutation *EpisodeMutation
}
// Where appends a list predicates to the EpisodeUpdate builder.
func (eu *EpisodeUpdate) Where(ps ...predicate.Episode) *EpisodeUpdate {
eu.mutation.Where(ps...)
return eu
}
// SetSeasonNumber sets the "season_number" field.
func (eu *EpisodeUpdate) SetSeasonNumber(i int) *EpisodeUpdate {
eu.mutation.ResetSeasonNumber()
eu.mutation.SetSeasonNumber(i)
return eu
}
// SetNillableSeasonNumber sets the "season_number" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableSeasonNumber(i *int) *EpisodeUpdate {
if i != nil {
eu.SetSeasonNumber(*i)
}
return eu
}
// AddSeasonNumber adds i to the "season_number" field.
func (eu *EpisodeUpdate) AddSeasonNumber(i int) *EpisodeUpdate {
eu.mutation.AddSeasonNumber(i)
return eu
}
// SetEpisodeNumber sets the "episode_number" field.
func (eu *EpisodeUpdate) SetEpisodeNumber(i int) *EpisodeUpdate {
eu.mutation.ResetEpisodeNumber()
eu.mutation.SetEpisodeNumber(i)
return eu
}
// SetNillableEpisodeNumber sets the "episode_number" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableEpisodeNumber(i *int) *EpisodeUpdate {
if i != nil {
eu.SetEpisodeNumber(*i)
}
return eu
}
// AddEpisodeNumber adds i to the "episode_number" field.
func (eu *EpisodeUpdate) AddEpisodeNumber(i int) *EpisodeUpdate {
eu.mutation.AddEpisodeNumber(i)
return eu
}
// SetTitle sets the "title" field.
func (eu *EpisodeUpdate) SetTitle(s string) *EpisodeUpdate {
eu.mutation.SetTitle(s)
return eu
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableTitle(s *string) *EpisodeUpdate {
if s != nil {
eu.SetTitle(*s)
}
return eu
}
// SetOverview sets the "overview" field.
func (eu *EpisodeUpdate) SetOverview(s string) *EpisodeUpdate {
eu.mutation.SetOverview(s)
return eu
}
// SetNillableOverview sets the "overview" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableOverview(s *string) *EpisodeUpdate {
if s != nil {
eu.SetOverview(*s)
}
return eu
}
// SetAirDate sets the "air_date" field.
func (eu *EpisodeUpdate) SetAirDate(s string) *EpisodeUpdate {
eu.mutation.SetAirDate(s)
return eu
}
// SetNillableAirDate sets the "air_date" field if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableAirDate(s *string) *EpisodeUpdate {
if s != nil {
eu.SetAirDate(*s)
}
return eu
}
// SetSeriesID sets the "series" edge to the Series entity by ID.
func (eu *EpisodeUpdate) SetSeriesID(id int) *EpisodeUpdate {
eu.mutation.SetSeriesID(id)
return eu
}
// SetNillableSeriesID sets the "series" edge to the Series entity by ID if the given value is not nil.
func (eu *EpisodeUpdate) SetNillableSeriesID(id *int) *EpisodeUpdate {
if id != nil {
eu = eu.SetSeriesID(*id)
}
return eu
}
// SetSeries sets the "series" edge to the Series entity.
func (eu *EpisodeUpdate) SetSeries(s *Series) *EpisodeUpdate {
return eu.SetSeriesID(s.ID)
}
// Mutation returns the EpisodeMutation object of the builder.
func (eu *EpisodeUpdate) Mutation() *EpisodeMutation {
return eu.mutation
}
// ClearSeries clears the "series" edge to the Series entity.
func (eu *EpisodeUpdate) ClearSeries() *EpisodeUpdate {
eu.mutation.ClearSeries()
return eu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (eu *EpisodeUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (eu *EpisodeUpdate) SaveX(ctx context.Context) int {
affected, err := eu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (eu *EpisodeUpdate) Exec(ctx context.Context) error {
_, err := eu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (eu *EpisodeUpdate) ExecX(ctx context.Context) {
if err := eu.Exec(ctx); err != nil {
panic(err)
}
}
func (eu *EpisodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(episode.Table, episode.Columns, sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt))
if ps := eu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := eu.mutation.SeasonNumber(); ok {
_spec.SetField(episode.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.AddedSeasonNumber(); ok {
_spec.AddField(episode.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.EpisodeNumber(); ok {
_spec.SetField(episode.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.AddedEpisodeNumber(); ok {
_spec.AddField(episode.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := eu.mutation.Title(); ok {
_spec.SetField(episode.FieldTitle, field.TypeString, value)
}
if value, ok := eu.mutation.Overview(); ok {
_spec.SetField(episode.FieldOverview, field.TypeString, value)
}
if value, ok := eu.mutation.AirDate(); ok {
_spec.SetField(episode.FieldAirDate, field.TypeString, value)
}
if eu.mutation.SeriesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: episode.SeriesTable,
Columns: []string{episode.SeriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(series.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := eu.mutation.SeriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: episode.SeriesTable,
Columns: []string{episode.SeriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(series.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{episode.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
eu.mutation.done = true
return n, nil
}
// EpisodeUpdateOne is the builder for updating a single Episode entity.
type EpisodeUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EpisodeMutation
}
// SetSeasonNumber sets the "season_number" field.
func (euo *EpisodeUpdateOne) SetSeasonNumber(i int) *EpisodeUpdateOne {
euo.mutation.ResetSeasonNumber()
euo.mutation.SetSeasonNumber(i)
return euo
}
// SetNillableSeasonNumber sets the "season_number" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableSeasonNumber(i *int) *EpisodeUpdateOne {
if i != nil {
euo.SetSeasonNumber(*i)
}
return euo
}
// AddSeasonNumber adds i to the "season_number" field.
func (euo *EpisodeUpdateOne) AddSeasonNumber(i int) *EpisodeUpdateOne {
euo.mutation.AddSeasonNumber(i)
return euo
}
// SetEpisodeNumber sets the "episode_number" field.
func (euo *EpisodeUpdateOne) SetEpisodeNumber(i int) *EpisodeUpdateOne {
euo.mutation.ResetEpisodeNumber()
euo.mutation.SetEpisodeNumber(i)
return euo
}
// SetNillableEpisodeNumber sets the "episode_number" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableEpisodeNumber(i *int) *EpisodeUpdateOne {
if i != nil {
euo.SetEpisodeNumber(*i)
}
return euo
}
// AddEpisodeNumber adds i to the "episode_number" field.
func (euo *EpisodeUpdateOne) AddEpisodeNumber(i int) *EpisodeUpdateOne {
euo.mutation.AddEpisodeNumber(i)
return euo
}
// SetTitle sets the "title" field.
func (euo *EpisodeUpdateOne) SetTitle(s string) *EpisodeUpdateOne {
euo.mutation.SetTitle(s)
return euo
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableTitle(s *string) *EpisodeUpdateOne {
if s != nil {
euo.SetTitle(*s)
}
return euo
}
// SetOverview sets the "overview" field.
func (euo *EpisodeUpdateOne) SetOverview(s string) *EpisodeUpdateOne {
euo.mutation.SetOverview(s)
return euo
}
// SetNillableOverview sets the "overview" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableOverview(s *string) *EpisodeUpdateOne {
if s != nil {
euo.SetOverview(*s)
}
return euo
}
// SetAirDate sets the "air_date" field.
func (euo *EpisodeUpdateOne) SetAirDate(s string) *EpisodeUpdateOne {
euo.mutation.SetAirDate(s)
return euo
}
// SetNillableAirDate sets the "air_date" field if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableAirDate(s *string) *EpisodeUpdateOne {
if s != nil {
euo.SetAirDate(*s)
}
return euo
}
// SetSeriesID sets the "series" edge to the Series entity by ID.
func (euo *EpisodeUpdateOne) SetSeriesID(id int) *EpisodeUpdateOne {
euo.mutation.SetSeriesID(id)
return euo
}
// SetNillableSeriesID sets the "series" edge to the Series entity by ID if the given value is not nil.
func (euo *EpisodeUpdateOne) SetNillableSeriesID(id *int) *EpisodeUpdateOne {
if id != nil {
euo = euo.SetSeriesID(*id)
}
return euo
}
// SetSeries sets the "series" edge to the Series entity.
func (euo *EpisodeUpdateOne) SetSeries(s *Series) *EpisodeUpdateOne {
return euo.SetSeriesID(s.ID)
}
// Mutation returns the EpisodeMutation object of the builder.
func (euo *EpisodeUpdateOne) Mutation() *EpisodeMutation {
return euo.mutation
}
// ClearSeries clears the "series" edge to the Series entity.
func (euo *EpisodeUpdateOne) ClearSeries() *EpisodeUpdateOne {
euo.mutation.ClearSeries()
return euo
}
// Where appends a list predicates to the EpisodeUpdate builder.
func (euo *EpisodeUpdateOne) Where(ps ...predicate.Episode) *EpisodeUpdateOne {
euo.mutation.Where(ps...)
return euo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (euo *EpisodeUpdateOne) Select(field string, fields ...string) *EpisodeUpdateOne {
euo.fields = append([]string{field}, fields...)
return euo
}
// Save executes the query and returns the updated Episode entity.
func (euo *EpisodeUpdateOne) Save(ctx context.Context) (*Episode, error) {
return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (euo *EpisodeUpdateOne) SaveX(ctx context.Context) *Episode {
node, err := euo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (euo *EpisodeUpdateOne) Exec(ctx context.Context) error {
_, err := euo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (euo *EpisodeUpdateOne) ExecX(ctx context.Context) {
if err := euo.Exec(ctx); err != nil {
panic(err)
}
}
func (euo *EpisodeUpdateOne) sqlSave(ctx context.Context) (_node *Episode, err error) {
_spec := sqlgraph.NewUpdateSpec(episode.Table, episode.Columns, sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt))
id, ok := euo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Episode.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := euo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, episode.FieldID)
for _, f := range fields {
if !episode.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != episode.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := euo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := euo.mutation.SeasonNumber(); ok {
_spec.SetField(episode.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.AddedSeasonNumber(); ok {
_spec.AddField(episode.FieldSeasonNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.EpisodeNumber(); ok {
_spec.SetField(episode.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.AddedEpisodeNumber(); ok {
_spec.AddField(episode.FieldEpisodeNumber, field.TypeInt, value)
}
if value, ok := euo.mutation.Title(); ok {
_spec.SetField(episode.FieldTitle, field.TypeString, value)
}
if value, ok := euo.mutation.Overview(); ok {
_spec.SetField(episode.FieldOverview, field.TypeString, value)
}
if value, ok := euo.mutation.AirDate(); ok {
_spec.SetField(episode.FieldAirDate, field.TypeString, value)
}
if euo.mutation.SeriesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: episode.SeriesTable,
Columns: []string{episode.SeriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(series.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := euo.mutation.SeriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: episode.SeriesTable,
Columns: []string{episode.SeriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(series.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Episode{config: euo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{episode.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
euo.mutation.done = true
return _node, nil
}

View File

@@ -20,16 +20,16 @@ func (f DownloadClientsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Va
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DownloadClientsMutation", m)
}
// The EpidodesFunc type is an adapter to allow the use of ordinary
// function as Epidodes mutator.
type EpidodesFunc func(context.Context, *ent.EpidodesMutation) (ent.Value, error)
// The EpisodeFunc type is an adapter to allow the use of ordinary
// function as Episode mutator.
type EpisodeFunc func(context.Context, *ent.EpisodeMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f EpidodesFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.EpidodesMutation); ok {
func (f EpisodeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.EpisodeMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EpidodesMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EpisodeMutation", m)
}
// The HistoryFunc type is an adapter to allow the use of ordinary

View File

@@ -29,21 +29,29 @@ var (
Columns: DownloadClientsColumns,
PrimaryKey: []*schema.Column{DownloadClientsColumns[0]},
}
// EpidodesColumns holds the columns for the "epidodes" table.
EpidodesColumns = []*schema.Column{
// EpisodesColumns holds the columns for the "episodes" table.
EpisodesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "series_id", Type: field.TypeInt},
{Name: "season_number", Type: field.TypeInt},
{Name: "episode_number", Type: field.TypeInt},
{Name: "title", Type: field.TypeString},
{Name: "overview", Type: field.TypeString},
{Name: "air_date", Type: field.TypeString},
{Name: "series_episodes", Type: field.TypeInt, Nullable: true},
}
// EpidodesTable holds the schema information for the "epidodes" table.
EpidodesTable = &schema.Table{
Name: "epidodes",
Columns: EpidodesColumns,
PrimaryKey: []*schema.Column{EpidodesColumns[0]},
// EpisodesTable holds the schema information for the "episodes" table.
EpisodesTable = &schema.Table{
Name: "episodes",
Columns: EpisodesColumns,
PrimaryKey: []*schema.Column{EpisodesColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "episodes_series_episodes",
Columns: []*schema.Column{EpisodesColumns[6]},
RefColumns: []*schema.Column{SeriesColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// HistoriesColumns holds the columns for the "histories" table.
HistoriesColumns = []*schema.Column{
@@ -79,7 +87,7 @@ var (
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "tmdb_id", Type: field.TypeInt},
{Name: "imdb_id", Type: field.TypeString, Nullable: true},
{Name: "title", Type: field.TypeString},
{Name: "name", Type: field.TypeString},
{Name: "original_name", Type: field.TypeString},
{Name: "overview", Type: field.TypeString},
{Name: "path", Type: field.TypeString},
@@ -107,7 +115,7 @@ var (
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
DownloadClientsTable,
EpidodesTable,
EpisodesTable,
HistoriesTable,
IndexersTable,
SeriesTable,
@@ -116,4 +124,5 @@ var (
)
func init() {
EpisodesTable.ForeignKeys[0].RefTable = SeriesTable
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -9,8 +9,8 @@ import (
// DownloadClients is the predicate function for downloadclients builders.
type DownloadClients func(*sql.Selector)
// Epidodes is the predicate function for epidodes builders.
type Epidodes func(*sql.Selector)
// Episode is the predicate function for episode builders.
type Episode func(*sql.Selector)
// History is the predicate function for history builders.
type History func(*sql.Selector)

View File

@@ -1,28 +0,0 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
// Epidodes holds the schema definition for the Epidodes entity.
type Epidodes struct {
ent.Schema
}
// Fields of the Epidodes.
func (Epidodes) Fields() []ent.Field {
return []ent.Field{
field.Int("series_id"),
field.Int("season_number"),
field.Int("episode_number"),
field.String("title"),
field.String("overview"),
field.String("air_date"),
}
}
// Edges of the Epidodes.
func (Epidodes) Edges() []ent.Edge {
return nil
}

34
ent/schema/episode.go Normal file
View File

@@ -0,0 +1,34 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Episode holds the schema definition for the Epidodes entity.
type Episode struct {
ent.Schema
}
// Fields of the Episode.
func (Episode) Fields() []ent.Field {
return []ent.Field{
//field.Int("series_id"),
field.Int("season_number"),
field.Int("episode_number"),
field.String("title"),
field.String("overview"),
field.String("air_date"),
}
}
// Edges of the Episode.
func (Episode) Edges() []ent.Edge {
return []ent.Edge{
edge.From("series", Series.Type).
Ref("episodes").
Unique(),
}
}

View File

@@ -4,6 +4,7 @@ import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
@@ -17,7 +18,7 @@ func (Series) Fields() []ent.Field {
return []ent.Field{
field.Int("tmdb_id"),
field.String("imdb_id").Optional(),
field.String("title"),
field.String("name"),
field.String("original_name"),
field.String("overview"),
field.String("path"),
@@ -28,5 +29,8 @@ func (Series) Fields() []ent.Field {
// Edges of the Series.
func (Series) Edges() []ent.Edge {
return nil
return []ent.Edge{
edge.To("episodes", Episode.Type),
}
}

View File

@@ -21,8 +21,8 @@ type Series struct {
TmdbID int `json:"tmdb_id,omitempty"`
// ImdbID holds the value of the "imdb_id" field.
ImdbID string `json:"imdb_id,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// OriginalName holds the value of the "original_name" field.
OriginalName string `json:"original_name,omitempty"`
// Overview holds the value of the "overview" field.
@@ -32,10 +32,31 @@ type Series struct {
// PosterPath holds the value of the "poster_path" field.
PosterPath string `json:"poster_path,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SeriesQuery when eager-loading is set.
Edges SeriesEdges `json:"edges"`
selectValues sql.SelectValues
}
// SeriesEdges holds the relations/edges for other nodes in the graph.
type SeriesEdges struct {
// Episodes holds the value of the episodes edge.
Episodes []*Episode `json:"episodes,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// EpisodesOrErr returns the Episodes value or an error if the edge
// was not loaded in eager-loading.
func (e SeriesEdges) EpisodesOrErr() ([]*Episode, error) {
if e.loadedTypes[0] {
return e.Episodes, nil
}
return nil, &NotLoadedError{edge: "episodes"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Series) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
@@ -43,7 +64,7 @@ func (*Series) scanValues(columns []string) ([]any, error) {
switch columns[i] {
case series.FieldID, series.FieldTmdbID:
values[i] = new(sql.NullInt64)
case series.FieldImdbID, series.FieldTitle, series.FieldOriginalName, series.FieldOverview, series.FieldPath, series.FieldPosterPath:
case series.FieldImdbID, series.FieldName, series.FieldOriginalName, series.FieldOverview, series.FieldPath, series.FieldPosterPath:
values[i] = new(sql.NullString)
case series.FieldCreatedAt:
values[i] = new(sql.NullTime)
@@ -80,11 +101,11 @@ func (s *Series) assignValues(columns []string, values []any) error {
} else if value.Valid {
s.ImdbID = value.String
}
case series.FieldTitle:
case series.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
s.Title = value.String
s.Name = value.String
}
case series.FieldOriginalName:
if value, ok := values[i].(*sql.NullString); !ok {
@@ -129,6 +150,11 @@ func (s *Series) Value(name string) (ent.Value, error) {
return s.selectValues.Get(name)
}
// QueryEpisodes queries the "episodes" edge of the Series entity.
func (s *Series) QueryEpisodes() *EpisodeQuery {
return NewSeriesClient(s.config).QueryEpisodes(s)
}
// Update returns a builder for updating this Series.
// Note that you need to call Series.Unwrap() before calling this method if this Series
// was returned from a transaction, and the transaction was committed or rolled back.
@@ -158,8 +184,8 @@ func (s *Series) String() string {
builder.WriteString("imdb_id=")
builder.WriteString(s.ImdbID)
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(s.Title)
builder.WriteString("name=")
builder.WriteString(s.Name)
builder.WriteString(", ")
builder.WriteString("original_name=")
builder.WriteString(s.OriginalName)

View File

@@ -6,6 +6,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
@@ -17,8 +18,8 @@ const (
FieldTmdbID = "tmdb_id"
// FieldImdbID holds the string denoting the imdb_id field in the database.
FieldImdbID = "imdb_id"
// FieldTitle holds the string denoting the title field in the database.
FieldTitle = "title"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldOriginalName holds the string denoting the original_name field in the database.
FieldOriginalName = "original_name"
// FieldOverview holds the string denoting the overview field in the database.
@@ -29,8 +30,17 @@ const (
FieldPosterPath = "poster_path"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeEpisodes holds the string denoting the episodes edge name in mutations.
EdgeEpisodes = "episodes"
// Table holds the table name of the series in the database.
Table = "series"
// EpisodesTable is the table that holds the episodes relation/edge.
EpisodesTable = "episodes"
// EpisodesInverseTable is the table name for the Episode entity.
// It exists in this package in order to avoid circular dependency with the "episode" package.
EpisodesInverseTable = "episodes"
// EpisodesColumn is the table column denoting the episodes relation/edge.
EpisodesColumn = "series_episodes"
)
// Columns holds all SQL columns for series fields.
@@ -38,7 +48,7 @@ var Columns = []string{
FieldID,
FieldTmdbID,
FieldImdbID,
FieldTitle,
FieldName,
FieldOriginalName,
FieldOverview,
FieldPath,
@@ -79,9 +89,9 @@ func ByImdbID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldImdbID, opts...).ToFunc()
}
// ByTitle orders the results by the title field.
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTitle, opts...).ToFunc()
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByOriginalName orders the results by the original_name field.
@@ -108,3 +118,24 @@ func ByPosterPath(opts ...sql.OrderTermOption) OrderOption {
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByEpisodesCount orders the results by episodes count.
func ByEpisodesCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newEpisodesStep(), opts...)
}
}
// ByEpisodes orders the results by episodes terms.
func ByEpisodes(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newEpisodesStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newEpisodesStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(EpisodesInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, EpisodesTable, EpisodesColumn),
)
}

View File

@@ -7,6 +7,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ID filters vertices based on their ID field.
@@ -64,9 +65,9 @@ func ImdbID(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldImdbID, v))
}
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
func Title(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldTitle, v))
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldName, v))
}
// OriginalName applies equality check predicate on the "original_name" field. It's identical to OriginalNameEQ.
@@ -209,69 +210,69 @@ func ImdbIDContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldImdbID, v))
}
// TitleEQ applies the EQ predicate on the "title" field.
func TitleEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldTitle, v))
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldName, v))
}
// TitleNEQ applies the NEQ predicate on the "title" field.
func TitleNEQ(v string) predicate.Series {
return predicate.Series(sql.FieldNEQ(FieldTitle, v))
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Series {
return predicate.Series(sql.FieldNEQ(FieldName, v))
}
// TitleIn applies the In predicate on the "title" field.
func TitleIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldIn(FieldTitle, vs...))
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldIn(FieldName, vs...))
}
// TitleNotIn applies the NotIn predicate on the "title" field.
func TitleNotIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldNotIn(FieldTitle, vs...))
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldNotIn(FieldName, vs...))
}
// TitleGT applies the GT predicate on the "title" field.
func TitleGT(v string) predicate.Series {
return predicate.Series(sql.FieldGT(FieldTitle, v))
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Series {
return predicate.Series(sql.FieldGT(FieldName, v))
}
// TitleGTE applies the GTE predicate on the "title" field.
func TitleGTE(v string) predicate.Series {
return predicate.Series(sql.FieldGTE(FieldTitle, v))
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Series {
return predicate.Series(sql.FieldGTE(FieldName, v))
}
// TitleLT applies the LT predicate on the "title" field.
func TitleLT(v string) predicate.Series {
return predicate.Series(sql.FieldLT(FieldTitle, v))
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Series {
return predicate.Series(sql.FieldLT(FieldName, v))
}
// TitleLTE applies the LTE predicate on the "title" field.
func TitleLTE(v string) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldTitle, v))
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldName, v))
}
// TitleContains applies the Contains predicate on the "title" field.
func TitleContains(v string) predicate.Series {
return predicate.Series(sql.FieldContains(FieldTitle, v))
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Series {
return predicate.Series(sql.FieldContains(FieldName, v))
}
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
func TitleHasPrefix(v string) predicate.Series {
return predicate.Series(sql.FieldHasPrefix(FieldTitle, v))
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Series {
return predicate.Series(sql.FieldHasPrefix(FieldName, v))
}
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
func TitleHasSuffix(v string) predicate.Series {
return predicate.Series(sql.FieldHasSuffix(FieldTitle, v))
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Series {
return predicate.Series(sql.FieldHasSuffix(FieldName, v))
}
// TitleEqualFold applies the EqualFold predicate on the "title" field.
func TitleEqualFold(v string) predicate.Series {
return predicate.Series(sql.FieldEqualFold(FieldTitle, v))
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Series {
return predicate.Series(sql.FieldEqualFold(FieldName, v))
}
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
func TitleContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldTitle, v))
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldName, v))
}
// OriginalNameEQ applies the EQ predicate on the "original_name" field.
@@ -584,6 +585,29 @@ func CreatedAtLTE(v time.Time) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldCreatedAt, v))
}
// HasEpisodes applies the HasEdge predicate on the "episodes" edge.
func HasEpisodes() predicate.Series {
return predicate.Series(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, EpisodesTable, EpisodesColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasEpisodesWith applies the HasEdge predicate on the "episodes" edge with a given conditions (other predicates).
func HasEpisodesWith(preds ...predicate.Episode) predicate.Series {
return predicate.Series(func(s *sql.Selector) {
step := newEpisodesStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Series) predicate.Series {
return predicate.Series(sql.AndPredicates(predicates...))

View File

@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"polaris/ent/episode"
"polaris/ent/series"
"time"
@@ -40,9 +41,9 @@ func (sc *SeriesCreate) SetNillableImdbID(s *string) *SeriesCreate {
return sc
}
// SetTitle sets the "title" field.
func (sc *SeriesCreate) SetTitle(s string) *SeriesCreate {
sc.mutation.SetTitle(s)
// SetName sets the "name" field.
func (sc *SeriesCreate) SetName(s string) *SeriesCreate {
sc.mutation.SetName(s)
return sc
}
@@ -92,6 +93,21 @@ func (sc *SeriesCreate) SetNillableCreatedAt(t *time.Time) *SeriesCreate {
return sc
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (sc *SeriesCreate) AddEpisodeIDs(ids ...int) *SeriesCreate {
sc.mutation.AddEpisodeIDs(ids...)
return sc
}
// AddEpisodes adds the "episodes" edges to the Episode entity.
func (sc *SeriesCreate) AddEpisodes(e ...*Episode) *SeriesCreate {
ids := make([]int, len(e))
for i := range e {
ids[i] = e[i].ID
}
return sc.AddEpisodeIDs(ids...)
}
// Mutation returns the SeriesMutation object of the builder.
func (sc *SeriesCreate) Mutation() *SeriesMutation {
return sc.mutation
@@ -138,8 +154,8 @@ func (sc *SeriesCreate) check() error {
if _, ok := sc.mutation.TmdbID(); !ok {
return &ValidationError{Name: "tmdb_id", err: errors.New(`ent: missing required field "Series.tmdb_id"`)}
}
if _, ok := sc.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Series.title"`)}
if _, ok := sc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Series.name"`)}
}
if _, ok := sc.mutation.OriginalName(); !ok {
return &ValidationError{Name: "original_name", err: errors.New(`ent: missing required field "Series.original_name"`)}
@@ -187,9 +203,9 @@ func (sc *SeriesCreate) createSpec() (*Series, *sqlgraph.CreateSpec) {
_spec.SetField(series.FieldImdbID, field.TypeString, value)
_node.ImdbID = value
}
if value, ok := sc.mutation.Title(); ok {
_spec.SetField(series.FieldTitle, field.TypeString, value)
_node.Title = value
if value, ok := sc.mutation.Name(); ok {
_spec.SetField(series.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := sc.mutation.OriginalName(); ok {
_spec.SetField(series.FieldOriginalName, field.TypeString, value)
@@ -211,6 +227,22 @@ func (sc *SeriesCreate) createSpec() (*Series, *sqlgraph.CreateSpec) {
_spec.SetField(series.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if nodes := sc.mutation.EpisodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}

View File

@@ -4,8 +4,10 @@ package ent
import (
"context"
"database/sql/driver"
"fmt"
"math"
"polaris/ent/episode"
"polaris/ent/predicate"
"polaris/ent/series"
@@ -17,10 +19,11 @@ import (
// SeriesQuery is the builder for querying Series entities.
type SeriesQuery struct {
config
ctx *QueryContext
order []series.OrderOption
inters []Interceptor
predicates []predicate.Series
ctx *QueryContext
order []series.OrderOption
inters []Interceptor
predicates []predicate.Series
withEpisodes *EpisodeQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
@@ -57,6 +60,28 @@ func (sq *SeriesQuery) Order(o ...series.OrderOption) *SeriesQuery {
return sq
}
// QueryEpisodes chains the current query on the "episodes" edge.
func (sq *SeriesQuery) QueryEpisodes() *EpisodeQuery {
query := (&EpisodeClient{config: sq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := sq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := sq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(series.Table, series.FieldID, selector),
sqlgraph.To(episode.Table, episode.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, series.EpisodesTable, series.EpisodesColumn),
)
fromU = sqlgraph.SetNeighbors(sq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first Series entity from the query.
// Returns a *NotFoundError when no Series was found.
func (sq *SeriesQuery) First(ctx context.Context) (*Series, error) {
@@ -244,17 +269,29 @@ func (sq *SeriesQuery) Clone() *SeriesQuery {
return nil
}
return &SeriesQuery{
config: sq.config,
ctx: sq.ctx.Clone(),
order: append([]series.OrderOption{}, sq.order...),
inters: append([]Interceptor{}, sq.inters...),
predicates: append([]predicate.Series{}, sq.predicates...),
config: sq.config,
ctx: sq.ctx.Clone(),
order: append([]series.OrderOption{}, sq.order...),
inters: append([]Interceptor{}, sq.inters...),
predicates: append([]predicate.Series{}, sq.predicates...),
withEpisodes: sq.withEpisodes.Clone(),
// clone intermediate query.
sql: sq.sql.Clone(),
path: sq.path,
}
}
// WithEpisodes tells the query-builder to eager-load the nodes that are connected to
// the "episodes" edge. The optional arguments are used to configure the query builder of the edge.
func (sq *SeriesQuery) WithEpisodes(opts ...func(*EpisodeQuery)) *SeriesQuery {
query := (&EpisodeClient{config: sq.config}).Query()
for _, opt := range opts {
opt(query)
}
sq.withEpisodes = query
return sq
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
@@ -331,8 +368,11 @@ func (sq *SeriesQuery) prepareQuery(ctx context.Context) error {
func (sq *SeriesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Series, error) {
var (
nodes = []*Series{}
_spec = sq.querySpec()
nodes = []*Series{}
_spec = sq.querySpec()
loadedTypes = [1]bool{
sq.withEpisodes != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Series).scanValues(nil, columns)
@@ -340,6 +380,7 @@ func (sq *SeriesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Serie
_spec.Assign = func(columns []string, values []any) error {
node := &Series{config: sq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
@@ -351,9 +392,48 @@ func (sq *SeriesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Serie
if len(nodes) == 0 {
return nodes, nil
}
if query := sq.withEpisodes; query != nil {
if err := sq.loadEpisodes(ctx, query, nodes,
func(n *Series) { n.Edges.Episodes = []*Episode{} },
func(n *Series, e *Episode) { n.Edges.Episodes = append(n.Edges.Episodes, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (sq *SeriesQuery) loadEpisodes(ctx context.Context, query *EpisodeQuery, nodes []*Series, init func(*Series), assign func(*Series, *Episode)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*Series)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
query.withFKs = true
query.Where(predicate.Episode(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(series.EpisodesColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.series_episodes
if fk == nil {
return fmt.Errorf(`foreign-key "series_episodes" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "series_episodes" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (sq *SeriesQuery) sqlCount(ctx context.Context) (int, error) {
_spec := sq.querySpec()
_spec.Node.Columns = sq.ctx.Fields

View File

@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"polaris/ent/episode"
"polaris/ent/predicate"
"polaris/ent/series"
"time"
@@ -69,16 +70,16 @@ func (su *SeriesUpdate) ClearImdbID() *SeriesUpdate {
return su
}
// SetTitle sets the "title" field.
func (su *SeriesUpdate) SetTitle(s string) *SeriesUpdate {
su.mutation.SetTitle(s)
// SetName sets the "name" field.
func (su *SeriesUpdate) SetName(s string) *SeriesUpdate {
su.mutation.SetName(s)
return su
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (su *SeriesUpdate) SetNillableTitle(s *string) *SeriesUpdate {
// SetNillableName sets the "name" field if the given value is not nil.
func (su *SeriesUpdate) SetNillableName(s *string) *SeriesUpdate {
if s != nil {
su.SetTitle(*s)
su.SetName(*s)
}
return su
}
@@ -159,11 +160,47 @@ func (su *SeriesUpdate) SetNillableCreatedAt(t *time.Time) *SeriesUpdate {
return su
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (su *SeriesUpdate) AddEpisodeIDs(ids ...int) *SeriesUpdate {
su.mutation.AddEpisodeIDs(ids...)
return su
}
// AddEpisodes adds the "episodes" edges to the Episode entity.
func (su *SeriesUpdate) AddEpisodes(e ...*Episode) *SeriesUpdate {
ids := make([]int, len(e))
for i := range e {
ids[i] = e[i].ID
}
return su.AddEpisodeIDs(ids...)
}
// Mutation returns the SeriesMutation object of the builder.
func (su *SeriesUpdate) Mutation() *SeriesMutation {
return su.mutation
}
// ClearEpisodes clears all "episodes" edges to the Episode entity.
func (su *SeriesUpdate) ClearEpisodes() *SeriesUpdate {
su.mutation.ClearEpisodes()
return su
}
// RemoveEpisodeIDs removes the "episodes" edge to Episode entities by IDs.
func (su *SeriesUpdate) RemoveEpisodeIDs(ids ...int) *SeriesUpdate {
su.mutation.RemoveEpisodeIDs(ids...)
return su
}
// RemoveEpisodes removes "episodes" edges to Episode entities.
func (su *SeriesUpdate) RemoveEpisodes(e ...*Episode) *SeriesUpdate {
ids := make([]int, len(e))
for i := range e {
ids[i] = e[i].ID
}
return su.RemoveEpisodeIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (su *SeriesUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
@@ -212,8 +249,8 @@ func (su *SeriesUpdate) sqlSave(ctx context.Context) (n int, err error) {
if su.mutation.ImdbIDCleared() {
_spec.ClearField(series.FieldImdbID, field.TypeString)
}
if value, ok := su.mutation.Title(); ok {
_spec.SetField(series.FieldTitle, field.TypeString, value)
if value, ok := su.mutation.Name(); ok {
_spec.SetField(series.FieldName, field.TypeString, value)
}
if value, ok := su.mutation.OriginalName(); ok {
_spec.SetField(series.FieldOriginalName, field.TypeString, value)
@@ -233,6 +270,51 @@ func (su *SeriesUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := su.mutation.CreatedAt(); ok {
_spec.SetField(series.FieldCreatedAt, field.TypeTime, value)
}
if su.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := su.mutation.RemovedEpisodesIDs(); len(nodes) > 0 && !su.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := su.mutation.EpisodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{series.Label}
@@ -294,16 +376,16 @@ func (suo *SeriesUpdateOne) ClearImdbID() *SeriesUpdateOne {
return suo
}
// SetTitle sets the "title" field.
func (suo *SeriesUpdateOne) SetTitle(s string) *SeriesUpdateOne {
suo.mutation.SetTitle(s)
// SetName sets the "name" field.
func (suo *SeriesUpdateOne) SetName(s string) *SeriesUpdateOne {
suo.mutation.SetName(s)
return suo
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (suo *SeriesUpdateOne) SetNillableTitle(s *string) *SeriesUpdateOne {
// SetNillableName sets the "name" field if the given value is not nil.
func (suo *SeriesUpdateOne) SetNillableName(s *string) *SeriesUpdateOne {
if s != nil {
suo.SetTitle(*s)
suo.SetName(*s)
}
return suo
}
@@ -384,11 +466,47 @@ func (suo *SeriesUpdateOne) SetNillableCreatedAt(t *time.Time) *SeriesUpdateOne
return suo
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (suo *SeriesUpdateOne) AddEpisodeIDs(ids ...int) *SeriesUpdateOne {
suo.mutation.AddEpisodeIDs(ids...)
return suo
}
// AddEpisodes adds the "episodes" edges to the Episode entity.
func (suo *SeriesUpdateOne) AddEpisodes(e ...*Episode) *SeriesUpdateOne {
ids := make([]int, len(e))
for i := range e {
ids[i] = e[i].ID
}
return suo.AddEpisodeIDs(ids...)
}
// Mutation returns the SeriesMutation object of the builder.
func (suo *SeriesUpdateOne) Mutation() *SeriesMutation {
return suo.mutation
}
// ClearEpisodes clears all "episodes" edges to the Episode entity.
func (suo *SeriesUpdateOne) ClearEpisodes() *SeriesUpdateOne {
suo.mutation.ClearEpisodes()
return suo
}
// RemoveEpisodeIDs removes the "episodes" edge to Episode entities by IDs.
func (suo *SeriesUpdateOne) RemoveEpisodeIDs(ids ...int) *SeriesUpdateOne {
suo.mutation.RemoveEpisodeIDs(ids...)
return suo
}
// RemoveEpisodes removes "episodes" edges to Episode entities.
func (suo *SeriesUpdateOne) RemoveEpisodes(e ...*Episode) *SeriesUpdateOne {
ids := make([]int, len(e))
for i := range e {
ids[i] = e[i].ID
}
return suo.RemoveEpisodeIDs(ids...)
}
// Where appends a list predicates to the SeriesUpdate builder.
func (suo *SeriesUpdateOne) Where(ps ...predicate.Series) *SeriesUpdateOne {
suo.mutation.Where(ps...)
@@ -467,8 +585,8 @@ func (suo *SeriesUpdateOne) sqlSave(ctx context.Context) (_node *Series, err err
if suo.mutation.ImdbIDCleared() {
_spec.ClearField(series.FieldImdbID, field.TypeString)
}
if value, ok := suo.mutation.Title(); ok {
_spec.SetField(series.FieldTitle, field.TypeString, value)
if value, ok := suo.mutation.Name(); ok {
_spec.SetField(series.FieldName, field.TypeString, value)
}
if value, ok := suo.mutation.OriginalName(); ok {
_spec.SetField(series.FieldOriginalName, field.TypeString, value)
@@ -488,6 +606,51 @@ func (suo *SeriesUpdateOne) sqlSave(ctx context.Context) (_node *Series, err err
if value, ok := suo.mutation.CreatedAt(); ok {
_spec.SetField(series.FieldCreatedAt, field.TypeTime, value)
}
if suo.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := suo.mutation.RemovedEpisodesIDs(); len(nodes) > 0 && !suo.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := suo.mutation.EpisodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: series.EpisodesTable,
Columns: []string{series.EpisodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Series{config: suo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues

View File

@@ -14,8 +14,8 @@ type Tx struct {
config
// DownloadClients is the client for interacting with the DownloadClients builders.
DownloadClients *DownloadClientsClient
// Epidodes is the client for interacting with the Epidodes builders.
Epidodes *EpidodesClient
// 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.
@@ -156,7 +156,7 @@ func (tx *Tx) Client() *Client {
func (tx *Tx) init() {
tx.DownloadClients = NewDownloadClientsClient(tx.config)
tx.Epidodes = NewEpidodesClient(tx.config)
tx.Episode = NewEpisodeClient(tx.config)
tx.History = NewHistoryClient(tx.config)
tx.Indexers = NewIndexersClient(tx.config)
tx.Series = NewSeriesClient(tx.config)

View File

@@ -41,12 +41,8 @@ func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
}
log.Infof("find detail for tv id %d: %v", in.ID, detail)
wl, err := s.db.AddWatchlist(in.RootFolder, detail)
if err != nil {
return nil, errors.Wrap(err, "add to list")
}
log.Infof("save watchlist success: %s", detail.Name)
var epIds []int
for _, season := range detail.Seasons {
seasonId := season.SeasonNumber
se, err := s.MustTMDB().GetSeasonDetails(int(detail.ID), seasonId, s.language)
@@ -55,8 +51,7 @@ func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
continue
}
for _, ep := range se.Episodes {
err = s.db.SaveEposideDetail(&ent.Epidodes{
SeriesID: wl.ID,
epid, err := s.db.SaveEposideDetail(&ent.Episode{
SeasonNumber: seasonId,
EpisodeNumber: ep.EpisodeNumber,
Title: ep.Name,
@@ -67,8 +62,14 @@ func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
log.Errorf("save episode info error: %v", err)
continue
}
epIds = append(epIds, epid)
}
}
_, err = s.db.AddWatchlist(in.RootFolder, detail, epIds)
if err != nil {
return nil, errors.Wrap(err, "add to list")
}
log.Infof("add tv %s to watchlist success", detail.Name)
return nil, nil
}
@@ -77,3 +78,8 @@ func (s *Server) GetWatchlist(c *gin.Context) (interface{}, error) {
list := s.db.GetWatchlist()
return list, nil
}
func (s *Server) GetTvDetails(c *gin.Context) (interface{}, error) {
return nil, nil
}

View File

@@ -22,7 +22,7 @@ class MyApp extends StatelessWidget {
final _shellRoute = ShellRoute(
builder: (BuildContext context, GoRouterState state, Widget child) {
return Scaffold(
appBar: AppBar(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
@@ -30,6 +30,11 @@ class MyApp extends StatelessWidget {
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: const Text("Polaris追剧"),
actions: [
IconButton(
onPressed: () => context.go(SystemSettingsPage.route),
icon: const Icon(Icons.settings))
],
),
body: Center(
// Center is a layout widget. It takes a single child and positions it

24
ui/lib/tv_details.dart Normal file
View File

@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
class TvDetailsPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
throw UnimplementedError();
}
}
class _TvDetailsPageState extends State<TvDetailsPage> {
final int tvId = 1;
@override
Widget build(BuildContext context) {
// TODO: implement build
throw Column(
children: [
],
)
}
}

View File

@@ -48,7 +48,7 @@ class _WeclomePageState extends State<WelcomePage> {
),
Flexible(
child: Text(
item.title!,
item.name!,
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.bold),
),
@@ -75,7 +75,7 @@ class _WeclomePageState extends State<WelcomePage> {
class TvSeries {
int? id;
int? tmdbId;
String? title;
String? name;
String? originalName;
String? overview;
String? path;
@@ -84,7 +84,7 @@ class TvSeries {
TvSeries(
{this.id,
this.tmdbId,
this.title,
this.name,
this.originalName,
this.overview,
this.path,
@@ -93,7 +93,7 @@ class TvSeries {
TvSeries.fromJson(Map<String, dynamic> json) {
id = json['id'];
tmdbId = json['tmdb_id'];
title = json['title'];
name = json['name'];
originalName = json['original_name'];
overview = json['overview'];
path = json['path'];