mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
1100 lines
32 KiB
Go
1100 lines
32 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"polaris/ent/episode"
|
|
"polaris/ent/media"
|
|
"polaris/ent/predicate"
|
|
"polaris/ent/schema"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/dialect/sql/sqljson"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// MediaUpdate is the builder for updating Media entities.
|
|
type MediaUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *MediaMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the MediaUpdate builder.
|
|
func (mu *MediaUpdate) Where(ps ...predicate.Media) *MediaUpdate {
|
|
mu.mutation.Where(ps...)
|
|
return mu
|
|
}
|
|
|
|
// SetTmdbID sets the "tmdb_id" field.
|
|
func (mu *MediaUpdate) SetTmdbID(i int) *MediaUpdate {
|
|
mu.mutation.ResetTmdbID()
|
|
mu.mutation.SetTmdbID(i)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableTmdbID sets the "tmdb_id" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableTmdbID(i *int) *MediaUpdate {
|
|
if i != nil {
|
|
mu.SetTmdbID(*i)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// AddTmdbID adds i to the "tmdb_id" field.
|
|
func (mu *MediaUpdate) AddTmdbID(i int) *MediaUpdate {
|
|
mu.mutation.AddTmdbID(i)
|
|
return mu
|
|
}
|
|
|
|
// SetImdbID sets the "imdb_id" field.
|
|
func (mu *MediaUpdate) SetImdbID(s string) *MediaUpdate {
|
|
mu.mutation.SetImdbID(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableImdbID sets the "imdb_id" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableImdbID(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetImdbID(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// ClearImdbID clears the value of the "imdb_id" field.
|
|
func (mu *MediaUpdate) ClearImdbID() *MediaUpdate {
|
|
mu.mutation.ClearImdbID()
|
|
return mu
|
|
}
|
|
|
|
// SetMediaType sets the "media_type" field.
|
|
func (mu *MediaUpdate) SetMediaType(mt media.MediaType) *MediaUpdate {
|
|
mu.mutation.SetMediaType(mt)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableMediaType sets the "media_type" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableMediaType(mt *media.MediaType) *MediaUpdate {
|
|
if mt != nil {
|
|
mu.SetMediaType(*mt)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetNameCn sets the "name_cn" field.
|
|
func (mu *MediaUpdate) SetNameCn(s string) *MediaUpdate {
|
|
mu.mutation.SetNameCn(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableNameCn sets the "name_cn" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableNameCn(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetNameCn(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetNameEn sets the "name_en" field.
|
|
func (mu *MediaUpdate) SetNameEn(s string) *MediaUpdate {
|
|
mu.mutation.SetNameEn(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableNameEn sets the "name_en" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableNameEn(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetNameEn(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetOriginalName sets the "original_name" field.
|
|
func (mu *MediaUpdate) SetOriginalName(s string) *MediaUpdate {
|
|
mu.mutation.SetOriginalName(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableOriginalName sets the "original_name" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableOriginalName(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetOriginalName(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetOverview sets the "overview" field.
|
|
func (mu *MediaUpdate) SetOverview(s string) *MediaUpdate {
|
|
mu.mutation.SetOverview(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableOverview sets the "overview" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableOverview(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetOverview(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (mu *MediaUpdate) SetCreatedAt(t time.Time) *MediaUpdate {
|
|
mu.mutation.SetCreatedAt(t)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableCreatedAt(t *time.Time) *MediaUpdate {
|
|
if t != nil {
|
|
mu.SetCreatedAt(*t)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetAirDate sets the "air_date" field.
|
|
func (mu *MediaUpdate) SetAirDate(s string) *MediaUpdate {
|
|
mu.mutation.SetAirDate(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableAirDate sets the "air_date" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableAirDate(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetAirDate(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetResolution sets the "resolution" field.
|
|
func (mu *MediaUpdate) SetResolution(m media.Resolution) *MediaUpdate {
|
|
mu.mutation.SetResolution(m)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableResolution sets the "resolution" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableResolution(m *media.Resolution) *MediaUpdate {
|
|
if m != nil {
|
|
mu.SetResolution(*m)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// SetStorageID sets the "storage_id" field.
|
|
func (mu *MediaUpdate) SetStorageID(i int) *MediaUpdate {
|
|
mu.mutation.ResetStorageID()
|
|
mu.mutation.SetStorageID(i)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableStorageID(i *int) *MediaUpdate {
|
|
if i != nil {
|
|
mu.SetStorageID(*i)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// AddStorageID adds i to the "storage_id" field.
|
|
func (mu *MediaUpdate) AddStorageID(i int) *MediaUpdate {
|
|
mu.mutation.AddStorageID(i)
|
|
return mu
|
|
}
|
|
|
|
// ClearStorageID clears the value of the "storage_id" field.
|
|
func (mu *MediaUpdate) ClearStorageID() *MediaUpdate {
|
|
mu.mutation.ClearStorageID()
|
|
return mu
|
|
}
|
|
|
|
// SetTargetDir sets the "target_dir" field.
|
|
func (mu *MediaUpdate) SetTargetDir(s string) *MediaUpdate {
|
|
mu.mutation.SetTargetDir(s)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableTargetDir sets the "target_dir" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableTargetDir(s *string) *MediaUpdate {
|
|
if s != nil {
|
|
mu.SetTargetDir(*s)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// ClearTargetDir clears the value of the "target_dir" field.
|
|
func (mu *MediaUpdate) ClearTargetDir() *MediaUpdate {
|
|
mu.mutation.ClearTargetDir()
|
|
return mu
|
|
}
|
|
|
|
// SetDownloadHistoryEpisodes sets the "download_history_episodes" field.
|
|
func (mu *MediaUpdate) SetDownloadHistoryEpisodes(b bool) *MediaUpdate {
|
|
mu.mutation.SetDownloadHistoryEpisodes(b)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableDownloadHistoryEpisodes sets the "download_history_episodes" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableDownloadHistoryEpisodes(b *bool) *MediaUpdate {
|
|
if b != nil {
|
|
mu.SetDownloadHistoryEpisodes(*b)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// ClearDownloadHistoryEpisodes clears the value of the "download_history_episodes" field.
|
|
func (mu *MediaUpdate) ClearDownloadHistoryEpisodes() *MediaUpdate {
|
|
mu.mutation.ClearDownloadHistoryEpisodes()
|
|
return mu
|
|
}
|
|
|
|
// SetLimiter sets the "limiter" field.
|
|
func (mu *MediaUpdate) SetLimiter(sl schema.MediaLimiter) *MediaUpdate {
|
|
mu.mutation.SetLimiter(sl)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableLimiter sets the "limiter" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableLimiter(sl *schema.MediaLimiter) *MediaUpdate {
|
|
if sl != nil {
|
|
mu.SetLimiter(*sl)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// ClearLimiter clears the value of the "limiter" field.
|
|
func (mu *MediaUpdate) ClearLimiter() *MediaUpdate {
|
|
mu.mutation.ClearLimiter()
|
|
return mu
|
|
}
|
|
|
|
// SetExtras sets the "extras" field.
|
|
func (mu *MediaUpdate) SetExtras(se schema.MediaExtras) *MediaUpdate {
|
|
mu.mutation.SetExtras(se)
|
|
return mu
|
|
}
|
|
|
|
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
|
func (mu *MediaUpdate) SetNillableExtras(se *schema.MediaExtras) *MediaUpdate {
|
|
if se != nil {
|
|
mu.SetExtras(*se)
|
|
}
|
|
return mu
|
|
}
|
|
|
|
// ClearExtras clears the value of the "extras" field.
|
|
func (mu *MediaUpdate) ClearExtras() *MediaUpdate {
|
|
mu.mutation.ClearExtras()
|
|
return mu
|
|
}
|
|
|
|
// SetAlternativeTitles sets the "alternative_titles" field.
|
|
func (mu *MediaUpdate) SetAlternativeTitles(st []schema.AlternativeTilte) *MediaUpdate {
|
|
mu.mutation.SetAlternativeTitles(st)
|
|
return mu
|
|
}
|
|
|
|
// AppendAlternativeTitles appends st to the "alternative_titles" field.
|
|
func (mu *MediaUpdate) AppendAlternativeTitles(st []schema.AlternativeTilte) *MediaUpdate {
|
|
mu.mutation.AppendAlternativeTitles(st)
|
|
return mu
|
|
}
|
|
|
|
// ClearAlternativeTitles clears the value of the "alternative_titles" field.
|
|
func (mu *MediaUpdate) ClearAlternativeTitles() *MediaUpdate {
|
|
mu.mutation.ClearAlternativeTitles()
|
|
return mu
|
|
}
|
|
|
|
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
|
func (mu *MediaUpdate) AddEpisodeIDs(ids ...int) *MediaUpdate {
|
|
mu.mutation.AddEpisodeIDs(ids...)
|
|
return mu
|
|
}
|
|
|
|
// AddEpisodes adds the "episodes" edges to the Episode entity.
|
|
func (mu *MediaUpdate) AddEpisodes(e ...*Episode) *MediaUpdate {
|
|
ids := make([]int, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return mu.AddEpisodeIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the MediaMutation object of the builder.
|
|
func (mu *MediaUpdate) Mutation() *MediaMutation {
|
|
return mu.mutation
|
|
}
|
|
|
|
// ClearEpisodes clears all "episodes" edges to the Episode entity.
|
|
func (mu *MediaUpdate) ClearEpisodes() *MediaUpdate {
|
|
mu.mutation.ClearEpisodes()
|
|
return mu
|
|
}
|
|
|
|
// RemoveEpisodeIDs removes the "episodes" edge to Episode entities by IDs.
|
|
func (mu *MediaUpdate) RemoveEpisodeIDs(ids ...int) *MediaUpdate {
|
|
mu.mutation.RemoveEpisodeIDs(ids...)
|
|
return mu
|
|
}
|
|
|
|
// RemoveEpisodes removes "episodes" edges to Episode entities.
|
|
func (mu *MediaUpdate) RemoveEpisodes(e ...*Episode) *MediaUpdate {
|
|
ids := make([]int, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return mu.RemoveEpisodeIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (mu *MediaUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (mu *MediaUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := mu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (mu *MediaUpdate) Exec(ctx context.Context) error {
|
|
_, err := mu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (mu *MediaUpdate) ExecX(ctx context.Context) {
|
|
if err := mu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (mu *MediaUpdate) check() error {
|
|
if v, ok := mu.mutation.MediaType(); ok {
|
|
if err := media.MediaTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "media_type", err: fmt.Errorf(`ent: validator failed for field "Media.media_type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := mu.mutation.Resolution(); ok {
|
|
if err := media.ResolutionValidator(v); err != nil {
|
|
return &ValidationError{Name: "resolution", err: fmt.Errorf(`ent: validator failed for field "Media.resolution": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mu *MediaUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := mu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(media.Table, media.Columns, sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt))
|
|
if ps := mu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := mu.mutation.TmdbID(); ok {
|
|
_spec.SetField(media.FieldTmdbID, field.TypeInt, value)
|
|
}
|
|
if value, ok := mu.mutation.AddedTmdbID(); ok {
|
|
_spec.AddField(media.FieldTmdbID, field.TypeInt, value)
|
|
}
|
|
if value, ok := mu.mutation.ImdbID(); ok {
|
|
_spec.SetField(media.FieldImdbID, field.TypeString, value)
|
|
}
|
|
if mu.mutation.ImdbIDCleared() {
|
|
_spec.ClearField(media.FieldImdbID, field.TypeString)
|
|
}
|
|
if value, ok := mu.mutation.MediaType(); ok {
|
|
_spec.SetField(media.FieldMediaType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := mu.mutation.NameCn(); ok {
|
|
_spec.SetField(media.FieldNameCn, field.TypeString, value)
|
|
}
|
|
if value, ok := mu.mutation.NameEn(); ok {
|
|
_spec.SetField(media.FieldNameEn, field.TypeString, value)
|
|
}
|
|
if value, ok := mu.mutation.OriginalName(); ok {
|
|
_spec.SetField(media.FieldOriginalName, field.TypeString, value)
|
|
}
|
|
if value, ok := mu.mutation.Overview(); ok {
|
|
_spec.SetField(media.FieldOverview, field.TypeString, value)
|
|
}
|
|
if value, ok := mu.mutation.CreatedAt(); ok {
|
|
_spec.SetField(media.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := mu.mutation.AirDate(); ok {
|
|
_spec.SetField(media.FieldAirDate, field.TypeString, value)
|
|
}
|
|
if value, ok := mu.mutation.Resolution(); ok {
|
|
_spec.SetField(media.FieldResolution, field.TypeEnum, value)
|
|
}
|
|
if value, ok := mu.mutation.StorageID(); ok {
|
|
_spec.SetField(media.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if value, ok := mu.mutation.AddedStorageID(); ok {
|
|
_spec.AddField(media.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if mu.mutation.StorageIDCleared() {
|
|
_spec.ClearField(media.FieldStorageID, field.TypeInt)
|
|
}
|
|
if value, ok := mu.mutation.TargetDir(); ok {
|
|
_spec.SetField(media.FieldTargetDir, field.TypeString, value)
|
|
}
|
|
if mu.mutation.TargetDirCleared() {
|
|
_spec.ClearField(media.FieldTargetDir, field.TypeString)
|
|
}
|
|
if value, ok := mu.mutation.DownloadHistoryEpisodes(); ok {
|
|
_spec.SetField(media.FieldDownloadHistoryEpisodes, field.TypeBool, value)
|
|
}
|
|
if mu.mutation.DownloadHistoryEpisodesCleared() {
|
|
_spec.ClearField(media.FieldDownloadHistoryEpisodes, field.TypeBool)
|
|
}
|
|
if value, ok := mu.mutation.Limiter(); ok {
|
|
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
|
|
}
|
|
if mu.mutation.LimiterCleared() {
|
|
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
|
|
}
|
|
if value, ok := mu.mutation.Extras(); ok {
|
|
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
|
}
|
|
if mu.mutation.ExtrasCleared() {
|
|
_spec.ClearField(media.FieldExtras, field.TypeJSON)
|
|
}
|
|
if value, ok := mu.mutation.AlternativeTitles(); ok {
|
|
_spec.SetField(media.FieldAlternativeTitles, field.TypeJSON, value)
|
|
}
|
|
if value, ok := mu.mutation.AppendedAlternativeTitles(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, media.FieldAlternativeTitles, value)
|
|
})
|
|
}
|
|
if mu.mutation.AlternativeTitlesCleared() {
|
|
_spec.ClearField(media.FieldAlternativeTitles, field.TypeJSON)
|
|
}
|
|
if mu.mutation.CreateTimeCleared() {
|
|
_spec.ClearField(media.FieldCreateTime, field.TypeTime)
|
|
}
|
|
if mu.mutation.EpisodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: media.EpisodesTable,
|
|
Columns: []string{media.EpisodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := mu.mutation.RemovedEpisodesIDs(); len(nodes) > 0 && !mu.mutation.EpisodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: media.EpisodesTable,
|
|
Columns: []string{media.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 := mu.mutation.EpisodesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: media.EpisodesTable,
|
|
Columns: []string{media.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, mu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{media.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
mu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// MediaUpdateOne is the builder for updating a single Media entity.
|
|
type MediaUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *MediaMutation
|
|
}
|
|
|
|
// SetTmdbID sets the "tmdb_id" field.
|
|
func (muo *MediaUpdateOne) SetTmdbID(i int) *MediaUpdateOne {
|
|
muo.mutation.ResetTmdbID()
|
|
muo.mutation.SetTmdbID(i)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableTmdbID sets the "tmdb_id" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableTmdbID(i *int) *MediaUpdateOne {
|
|
if i != nil {
|
|
muo.SetTmdbID(*i)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// AddTmdbID adds i to the "tmdb_id" field.
|
|
func (muo *MediaUpdateOne) AddTmdbID(i int) *MediaUpdateOne {
|
|
muo.mutation.AddTmdbID(i)
|
|
return muo
|
|
}
|
|
|
|
// SetImdbID sets the "imdb_id" field.
|
|
func (muo *MediaUpdateOne) SetImdbID(s string) *MediaUpdateOne {
|
|
muo.mutation.SetImdbID(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableImdbID sets the "imdb_id" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableImdbID(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetImdbID(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// ClearImdbID clears the value of the "imdb_id" field.
|
|
func (muo *MediaUpdateOne) ClearImdbID() *MediaUpdateOne {
|
|
muo.mutation.ClearImdbID()
|
|
return muo
|
|
}
|
|
|
|
// SetMediaType sets the "media_type" field.
|
|
func (muo *MediaUpdateOne) SetMediaType(mt media.MediaType) *MediaUpdateOne {
|
|
muo.mutation.SetMediaType(mt)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableMediaType sets the "media_type" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableMediaType(mt *media.MediaType) *MediaUpdateOne {
|
|
if mt != nil {
|
|
muo.SetMediaType(*mt)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetNameCn sets the "name_cn" field.
|
|
func (muo *MediaUpdateOne) SetNameCn(s string) *MediaUpdateOne {
|
|
muo.mutation.SetNameCn(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableNameCn sets the "name_cn" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableNameCn(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetNameCn(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetNameEn sets the "name_en" field.
|
|
func (muo *MediaUpdateOne) SetNameEn(s string) *MediaUpdateOne {
|
|
muo.mutation.SetNameEn(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableNameEn sets the "name_en" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableNameEn(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetNameEn(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetOriginalName sets the "original_name" field.
|
|
func (muo *MediaUpdateOne) SetOriginalName(s string) *MediaUpdateOne {
|
|
muo.mutation.SetOriginalName(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableOriginalName sets the "original_name" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableOriginalName(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetOriginalName(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetOverview sets the "overview" field.
|
|
func (muo *MediaUpdateOne) SetOverview(s string) *MediaUpdateOne {
|
|
muo.mutation.SetOverview(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableOverview sets the "overview" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableOverview(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetOverview(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (muo *MediaUpdateOne) SetCreatedAt(t time.Time) *MediaUpdateOne {
|
|
muo.mutation.SetCreatedAt(t)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableCreatedAt(t *time.Time) *MediaUpdateOne {
|
|
if t != nil {
|
|
muo.SetCreatedAt(*t)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetAirDate sets the "air_date" field.
|
|
func (muo *MediaUpdateOne) SetAirDate(s string) *MediaUpdateOne {
|
|
muo.mutation.SetAirDate(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableAirDate sets the "air_date" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableAirDate(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetAirDate(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetResolution sets the "resolution" field.
|
|
func (muo *MediaUpdateOne) SetResolution(m media.Resolution) *MediaUpdateOne {
|
|
muo.mutation.SetResolution(m)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableResolution sets the "resolution" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableResolution(m *media.Resolution) *MediaUpdateOne {
|
|
if m != nil {
|
|
muo.SetResolution(*m)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// SetStorageID sets the "storage_id" field.
|
|
func (muo *MediaUpdateOne) SetStorageID(i int) *MediaUpdateOne {
|
|
muo.mutation.ResetStorageID()
|
|
muo.mutation.SetStorageID(i)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableStorageID(i *int) *MediaUpdateOne {
|
|
if i != nil {
|
|
muo.SetStorageID(*i)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// AddStorageID adds i to the "storage_id" field.
|
|
func (muo *MediaUpdateOne) AddStorageID(i int) *MediaUpdateOne {
|
|
muo.mutation.AddStorageID(i)
|
|
return muo
|
|
}
|
|
|
|
// ClearStorageID clears the value of the "storage_id" field.
|
|
func (muo *MediaUpdateOne) ClearStorageID() *MediaUpdateOne {
|
|
muo.mutation.ClearStorageID()
|
|
return muo
|
|
}
|
|
|
|
// SetTargetDir sets the "target_dir" field.
|
|
func (muo *MediaUpdateOne) SetTargetDir(s string) *MediaUpdateOne {
|
|
muo.mutation.SetTargetDir(s)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableTargetDir sets the "target_dir" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableTargetDir(s *string) *MediaUpdateOne {
|
|
if s != nil {
|
|
muo.SetTargetDir(*s)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// ClearTargetDir clears the value of the "target_dir" field.
|
|
func (muo *MediaUpdateOne) ClearTargetDir() *MediaUpdateOne {
|
|
muo.mutation.ClearTargetDir()
|
|
return muo
|
|
}
|
|
|
|
// SetDownloadHistoryEpisodes sets the "download_history_episodes" field.
|
|
func (muo *MediaUpdateOne) SetDownloadHistoryEpisodes(b bool) *MediaUpdateOne {
|
|
muo.mutation.SetDownloadHistoryEpisodes(b)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableDownloadHistoryEpisodes sets the "download_history_episodes" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableDownloadHistoryEpisodes(b *bool) *MediaUpdateOne {
|
|
if b != nil {
|
|
muo.SetDownloadHistoryEpisodes(*b)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// ClearDownloadHistoryEpisodes clears the value of the "download_history_episodes" field.
|
|
func (muo *MediaUpdateOne) ClearDownloadHistoryEpisodes() *MediaUpdateOne {
|
|
muo.mutation.ClearDownloadHistoryEpisodes()
|
|
return muo
|
|
}
|
|
|
|
// SetLimiter sets the "limiter" field.
|
|
func (muo *MediaUpdateOne) SetLimiter(sl schema.MediaLimiter) *MediaUpdateOne {
|
|
muo.mutation.SetLimiter(sl)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableLimiter sets the "limiter" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableLimiter(sl *schema.MediaLimiter) *MediaUpdateOne {
|
|
if sl != nil {
|
|
muo.SetLimiter(*sl)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// ClearLimiter clears the value of the "limiter" field.
|
|
func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne {
|
|
muo.mutation.ClearLimiter()
|
|
return muo
|
|
}
|
|
|
|
// SetExtras sets the "extras" field.
|
|
func (muo *MediaUpdateOne) SetExtras(se schema.MediaExtras) *MediaUpdateOne {
|
|
muo.mutation.SetExtras(se)
|
|
return muo
|
|
}
|
|
|
|
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
|
func (muo *MediaUpdateOne) SetNillableExtras(se *schema.MediaExtras) *MediaUpdateOne {
|
|
if se != nil {
|
|
muo.SetExtras(*se)
|
|
}
|
|
return muo
|
|
}
|
|
|
|
// ClearExtras clears the value of the "extras" field.
|
|
func (muo *MediaUpdateOne) ClearExtras() *MediaUpdateOne {
|
|
muo.mutation.ClearExtras()
|
|
return muo
|
|
}
|
|
|
|
// SetAlternativeTitles sets the "alternative_titles" field.
|
|
func (muo *MediaUpdateOne) SetAlternativeTitles(st []schema.AlternativeTilte) *MediaUpdateOne {
|
|
muo.mutation.SetAlternativeTitles(st)
|
|
return muo
|
|
}
|
|
|
|
// AppendAlternativeTitles appends st to the "alternative_titles" field.
|
|
func (muo *MediaUpdateOne) AppendAlternativeTitles(st []schema.AlternativeTilte) *MediaUpdateOne {
|
|
muo.mutation.AppendAlternativeTitles(st)
|
|
return muo
|
|
}
|
|
|
|
// ClearAlternativeTitles clears the value of the "alternative_titles" field.
|
|
func (muo *MediaUpdateOne) ClearAlternativeTitles() *MediaUpdateOne {
|
|
muo.mutation.ClearAlternativeTitles()
|
|
return muo
|
|
}
|
|
|
|
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
|
func (muo *MediaUpdateOne) AddEpisodeIDs(ids ...int) *MediaUpdateOne {
|
|
muo.mutation.AddEpisodeIDs(ids...)
|
|
return muo
|
|
}
|
|
|
|
// AddEpisodes adds the "episodes" edges to the Episode entity.
|
|
func (muo *MediaUpdateOne) AddEpisodes(e ...*Episode) *MediaUpdateOne {
|
|
ids := make([]int, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return muo.AddEpisodeIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the MediaMutation object of the builder.
|
|
func (muo *MediaUpdateOne) Mutation() *MediaMutation {
|
|
return muo.mutation
|
|
}
|
|
|
|
// ClearEpisodes clears all "episodes" edges to the Episode entity.
|
|
func (muo *MediaUpdateOne) ClearEpisodes() *MediaUpdateOne {
|
|
muo.mutation.ClearEpisodes()
|
|
return muo
|
|
}
|
|
|
|
// RemoveEpisodeIDs removes the "episodes" edge to Episode entities by IDs.
|
|
func (muo *MediaUpdateOne) RemoveEpisodeIDs(ids ...int) *MediaUpdateOne {
|
|
muo.mutation.RemoveEpisodeIDs(ids...)
|
|
return muo
|
|
}
|
|
|
|
// RemoveEpisodes removes "episodes" edges to Episode entities.
|
|
func (muo *MediaUpdateOne) RemoveEpisodes(e ...*Episode) *MediaUpdateOne {
|
|
ids := make([]int, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return muo.RemoveEpisodeIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the MediaUpdate builder.
|
|
func (muo *MediaUpdateOne) Where(ps ...predicate.Media) *MediaUpdateOne {
|
|
muo.mutation.Where(ps...)
|
|
return muo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (muo *MediaUpdateOne) Select(field string, fields ...string) *MediaUpdateOne {
|
|
muo.fields = append([]string{field}, fields...)
|
|
return muo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Media entity.
|
|
func (muo *MediaUpdateOne) Save(ctx context.Context) (*Media, error) {
|
|
return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (muo *MediaUpdateOne) SaveX(ctx context.Context) *Media {
|
|
node, err := muo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (muo *MediaUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := muo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (muo *MediaUpdateOne) ExecX(ctx context.Context) {
|
|
if err := muo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (muo *MediaUpdateOne) check() error {
|
|
if v, ok := muo.mutation.MediaType(); ok {
|
|
if err := media.MediaTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "media_type", err: fmt.Errorf(`ent: validator failed for field "Media.media_type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := muo.mutation.Resolution(); ok {
|
|
if err := media.ResolutionValidator(v); err != nil {
|
|
return &ValidationError{Name: "resolution", err: fmt.Errorf(`ent: validator failed for field "Media.resolution": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (muo *MediaUpdateOne) sqlSave(ctx context.Context) (_node *Media, err error) {
|
|
if err := muo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(media.Table, media.Columns, sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt))
|
|
id, ok := muo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Media.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := muo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, media.FieldID)
|
|
for _, f := range fields {
|
|
if !media.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != media.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := muo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := muo.mutation.TmdbID(); ok {
|
|
_spec.SetField(media.FieldTmdbID, field.TypeInt, value)
|
|
}
|
|
if value, ok := muo.mutation.AddedTmdbID(); ok {
|
|
_spec.AddField(media.FieldTmdbID, field.TypeInt, value)
|
|
}
|
|
if value, ok := muo.mutation.ImdbID(); ok {
|
|
_spec.SetField(media.FieldImdbID, field.TypeString, value)
|
|
}
|
|
if muo.mutation.ImdbIDCleared() {
|
|
_spec.ClearField(media.FieldImdbID, field.TypeString)
|
|
}
|
|
if value, ok := muo.mutation.MediaType(); ok {
|
|
_spec.SetField(media.FieldMediaType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := muo.mutation.NameCn(); ok {
|
|
_spec.SetField(media.FieldNameCn, field.TypeString, value)
|
|
}
|
|
if value, ok := muo.mutation.NameEn(); ok {
|
|
_spec.SetField(media.FieldNameEn, field.TypeString, value)
|
|
}
|
|
if value, ok := muo.mutation.OriginalName(); ok {
|
|
_spec.SetField(media.FieldOriginalName, field.TypeString, value)
|
|
}
|
|
if value, ok := muo.mutation.Overview(); ok {
|
|
_spec.SetField(media.FieldOverview, field.TypeString, value)
|
|
}
|
|
if value, ok := muo.mutation.CreatedAt(); ok {
|
|
_spec.SetField(media.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := muo.mutation.AirDate(); ok {
|
|
_spec.SetField(media.FieldAirDate, field.TypeString, value)
|
|
}
|
|
if value, ok := muo.mutation.Resolution(); ok {
|
|
_spec.SetField(media.FieldResolution, field.TypeEnum, value)
|
|
}
|
|
if value, ok := muo.mutation.StorageID(); ok {
|
|
_spec.SetField(media.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if value, ok := muo.mutation.AddedStorageID(); ok {
|
|
_spec.AddField(media.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if muo.mutation.StorageIDCleared() {
|
|
_spec.ClearField(media.FieldStorageID, field.TypeInt)
|
|
}
|
|
if value, ok := muo.mutation.TargetDir(); ok {
|
|
_spec.SetField(media.FieldTargetDir, field.TypeString, value)
|
|
}
|
|
if muo.mutation.TargetDirCleared() {
|
|
_spec.ClearField(media.FieldTargetDir, field.TypeString)
|
|
}
|
|
if value, ok := muo.mutation.DownloadHistoryEpisodes(); ok {
|
|
_spec.SetField(media.FieldDownloadHistoryEpisodes, field.TypeBool, value)
|
|
}
|
|
if muo.mutation.DownloadHistoryEpisodesCleared() {
|
|
_spec.ClearField(media.FieldDownloadHistoryEpisodes, field.TypeBool)
|
|
}
|
|
if value, ok := muo.mutation.Limiter(); ok {
|
|
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
|
|
}
|
|
if muo.mutation.LimiterCleared() {
|
|
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
|
|
}
|
|
if value, ok := muo.mutation.Extras(); ok {
|
|
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
|
}
|
|
if muo.mutation.ExtrasCleared() {
|
|
_spec.ClearField(media.FieldExtras, field.TypeJSON)
|
|
}
|
|
if value, ok := muo.mutation.AlternativeTitles(); ok {
|
|
_spec.SetField(media.FieldAlternativeTitles, field.TypeJSON, value)
|
|
}
|
|
if value, ok := muo.mutation.AppendedAlternativeTitles(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, media.FieldAlternativeTitles, value)
|
|
})
|
|
}
|
|
if muo.mutation.AlternativeTitlesCleared() {
|
|
_spec.ClearField(media.FieldAlternativeTitles, field.TypeJSON)
|
|
}
|
|
if muo.mutation.CreateTimeCleared() {
|
|
_spec.ClearField(media.FieldCreateTime, field.TypeTime)
|
|
}
|
|
if muo.mutation.EpisodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: media.EpisodesTable,
|
|
Columns: []string{media.EpisodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(episode.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := muo.mutation.RemovedEpisodesIDs(); len(nodes) > 0 && !muo.mutation.EpisodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: media.EpisodesTable,
|
|
Columns: []string{media.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 := muo.mutation.EpisodesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: media.EpisodesTable,
|
|
Columns: []string{media.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 = &Media{config: muo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{media.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
muo.mutation.done = true
|
|
return _node, nil
|
|
}
|