mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-10 03:57:39 +08:00
basic find and download ability
This commit is contained in:
352
ent/history_update.go
Normal file
352
ent/history_update.go
Normal file
@@ -0,0 +1,352 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// HistoryUpdate is the builder for updating History entities.
|
||||
type HistoryUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *HistoryMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the HistoryUpdate builder.
|
||||
func (hu *HistoryUpdate) Where(ps ...predicate.History) *HistoryUpdate {
|
||||
hu.mutation.Where(ps...)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetSeriesID sets the "series_id" field.
|
||||
func (hu *HistoryUpdate) SetSeriesID(i int) *HistoryUpdate {
|
||||
hu.mutation.ResetSeriesID()
|
||||
hu.mutation.SetSeriesID(i)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetNillableSeriesID sets the "series_id" field if the given value is not nil.
|
||||
func (hu *HistoryUpdate) SetNillableSeriesID(i *int) *HistoryUpdate {
|
||||
if i != nil {
|
||||
hu.SetSeriesID(*i)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// AddSeriesID adds i to the "series_id" field.
|
||||
func (hu *HistoryUpdate) AddSeriesID(i int) *HistoryUpdate {
|
||||
hu.mutation.AddSeriesID(i)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetEpisodeID sets the "episode_id" field.
|
||||
func (hu *HistoryUpdate) SetEpisodeID(i int) *HistoryUpdate {
|
||||
hu.mutation.ResetEpisodeID()
|
||||
hu.mutation.SetEpisodeID(i)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetNillableEpisodeID sets the "episode_id" field if the given value is not nil.
|
||||
func (hu *HistoryUpdate) SetNillableEpisodeID(i *int) *HistoryUpdate {
|
||||
if i != nil {
|
||||
hu.SetEpisodeID(*i)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// AddEpisodeID adds i to the "episode_id" field.
|
||||
func (hu *HistoryUpdate) AddEpisodeID(i int) *HistoryUpdate {
|
||||
hu.mutation.AddEpisodeID(i)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetSourceTitle sets the "source_title" field.
|
||||
func (hu *HistoryUpdate) SetSourceTitle(s string) *HistoryUpdate {
|
||||
hu.mutation.SetSourceTitle(s)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetNillableSourceTitle sets the "source_title" field if the given value is not nil.
|
||||
func (hu *HistoryUpdate) SetNillableSourceTitle(s *string) *HistoryUpdate {
|
||||
if s != nil {
|
||||
hu.SetSourceTitle(*s)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (hu *HistoryUpdate) SetDate(t time.Time) *HistoryUpdate {
|
||||
hu.mutation.SetDate(t)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (hu *HistoryUpdate) SetNillableDate(t *time.Time) *HistoryUpdate {
|
||||
if t != nil {
|
||||
hu.SetDate(*t)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// Mutation returns the HistoryMutation object of the builder.
|
||||
func (hu *HistoryUpdate) Mutation() *HistoryMutation {
|
||||
return hu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (hu *HistoryUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, hu.sqlSave, hu.mutation, hu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (hu *HistoryUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := hu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (hu *HistoryUpdate) Exec(ctx context.Context) error {
|
||||
_, err := hu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (hu *HistoryUpdate) ExecX(ctx context.Context) {
|
||||
if err := hu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(history.Table, history.Columns, sqlgraph.NewFieldSpec(history.FieldID, field.TypeInt))
|
||||
if ps := hu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := hu.mutation.SeriesID(); ok {
|
||||
_spec.SetField(history.FieldSeriesID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := hu.mutation.AddedSeriesID(); ok {
|
||||
_spec.AddField(history.FieldSeriesID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := hu.mutation.EpisodeID(); ok {
|
||||
_spec.SetField(history.FieldEpisodeID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := hu.mutation.AddedEpisodeID(); ok {
|
||||
_spec.AddField(history.FieldEpisodeID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := hu.mutation.SourceTitle(); ok {
|
||||
_spec.SetField(history.FieldSourceTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := hu.mutation.Date(); ok {
|
||||
_spec.SetField(history.FieldDate, field.TypeTime, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, hu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{history.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
hu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// HistoryUpdateOne is the builder for updating a single History entity.
|
||||
type HistoryUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *HistoryMutation
|
||||
}
|
||||
|
||||
// SetSeriesID sets the "series_id" field.
|
||||
func (huo *HistoryUpdateOne) SetSeriesID(i int) *HistoryUpdateOne {
|
||||
huo.mutation.ResetSeriesID()
|
||||
huo.mutation.SetSeriesID(i)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetNillableSeriesID sets the "series_id" field if the given value is not nil.
|
||||
func (huo *HistoryUpdateOne) SetNillableSeriesID(i *int) *HistoryUpdateOne {
|
||||
if i != nil {
|
||||
huo.SetSeriesID(*i)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// AddSeriesID adds i to the "series_id" field.
|
||||
func (huo *HistoryUpdateOne) AddSeriesID(i int) *HistoryUpdateOne {
|
||||
huo.mutation.AddSeriesID(i)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetEpisodeID sets the "episode_id" field.
|
||||
func (huo *HistoryUpdateOne) SetEpisodeID(i int) *HistoryUpdateOne {
|
||||
huo.mutation.ResetEpisodeID()
|
||||
huo.mutation.SetEpisodeID(i)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetNillableEpisodeID sets the "episode_id" field if the given value is not nil.
|
||||
func (huo *HistoryUpdateOne) SetNillableEpisodeID(i *int) *HistoryUpdateOne {
|
||||
if i != nil {
|
||||
huo.SetEpisodeID(*i)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// AddEpisodeID adds i to the "episode_id" field.
|
||||
func (huo *HistoryUpdateOne) AddEpisodeID(i int) *HistoryUpdateOne {
|
||||
huo.mutation.AddEpisodeID(i)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetSourceTitle sets the "source_title" field.
|
||||
func (huo *HistoryUpdateOne) SetSourceTitle(s string) *HistoryUpdateOne {
|
||||
huo.mutation.SetSourceTitle(s)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetNillableSourceTitle sets the "source_title" field if the given value is not nil.
|
||||
func (huo *HistoryUpdateOne) SetNillableSourceTitle(s *string) *HistoryUpdateOne {
|
||||
if s != nil {
|
||||
huo.SetSourceTitle(*s)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (huo *HistoryUpdateOne) SetDate(t time.Time) *HistoryUpdateOne {
|
||||
huo.mutation.SetDate(t)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (huo *HistoryUpdateOne) SetNillableDate(t *time.Time) *HistoryUpdateOne {
|
||||
if t != nil {
|
||||
huo.SetDate(*t)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// Mutation returns the HistoryMutation object of the builder.
|
||||
func (huo *HistoryUpdateOne) Mutation() *HistoryMutation {
|
||||
return huo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the HistoryUpdate builder.
|
||||
func (huo *HistoryUpdateOne) Where(ps ...predicate.History) *HistoryUpdateOne {
|
||||
huo.mutation.Where(ps...)
|
||||
return huo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (huo *HistoryUpdateOne) Select(field string, fields ...string) *HistoryUpdateOne {
|
||||
huo.fields = append([]string{field}, fields...)
|
||||
return huo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated History entity.
|
||||
func (huo *HistoryUpdateOne) Save(ctx context.Context) (*History, error) {
|
||||
return withHooks(ctx, huo.sqlSave, huo.mutation, huo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (huo *HistoryUpdateOne) SaveX(ctx context.Context) *History {
|
||||
node, err := huo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (huo *HistoryUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := huo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (huo *HistoryUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := huo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(history.Table, history.Columns, sqlgraph.NewFieldSpec(history.FieldID, field.TypeInt))
|
||||
id, ok := huo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "History.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := huo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, history.FieldID)
|
||||
for _, f := range fields {
|
||||
if !history.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != history.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := huo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := huo.mutation.SeriesID(); ok {
|
||||
_spec.SetField(history.FieldSeriesID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := huo.mutation.AddedSeriesID(); ok {
|
||||
_spec.AddField(history.FieldSeriesID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := huo.mutation.EpisodeID(); ok {
|
||||
_spec.SetField(history.FieldEpisodeID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := huo.mutation.AddedEpisodeID(); ok {
|
||||
_spec.AddField(history.FieldEpisodeID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := huo.mutation.SourceTitle(); ok {
|
||||
_spec.SetField(history.FieldSourceTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := huo.mutation.Date(); ok {
|
||||
_spec.SetField(history.FieldDate, field.TypeTime, value)
|
||||
}
|
||||
_node = &History{config: huo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, huo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{history.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
huo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user