mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-04 08:30:45 +08:00
440 lines
13 KiB
Go
440 lines
13 KiB
Go
// 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
|
|
}
|