mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
366 lines
10 KiB
Go
366 lines
10 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"polaris/ent/indexers"
|
|
"polaris/ent/predicate"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// IndexersUpdate is the builder for updating Indexers entities.
|
|
type IndexersUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *IndexersMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the IndexersUpdate builder.
|
|
func (iu *IndexersUpdate) Where(ps ...predicate.Indexers) *IndexersUpdate {
|
|
iu.mutation.Where(ps...)
|
|
return iu
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (iu *IndexersUpdate) SetName(s string) *IndexersUpdate {
|
|
iu.mutation.SetName(s)
|
|
return iu
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (iu *IndexersUpdate) SetNillableName(s *string) *IndexersUpdate {
|
|
if s != nil {
|
|
iu.SetName(*s)
|
|
}
|
|
return iu
|
|
}
|
|
|
|
// SetImplementation sets the "implementation" field.
|
|
func (iu *IndexersUpdate) SetImplementation(s string) *IndexersUpdate {
|
|
iu.mutation.SetImplementation(s)
|
|
return iu
|
|
}
|
|
|
|
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
|
|
func (iu *IndexersUpdate) SetNillableImplementation(s *string) *IndexersUpdate {
|
|
if s != nil {
|
|
iu.SetImplementation(*s)
|
|
}
|
|
return iu
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (iu *IndexersUpdate) SetSettings(s string) *IndexersUpdate {
|
|
iu.mutation.SetSettings(s)
|
|
return iu
|
|
}
|
|
|
|
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
|
func (iu *IndexersUpdate) SetNillableSettings(s *string) *IndexersUpdate {
|
|
if s != nil {
|
|
iu.SetSettings(*s)
|
|
}
|
|
return iu
|
|
}
|
|
|
|
// SetEnableRss sets the "enable_rss" field.
|
|
func (iu *IndexersUpdate) SetEnableRss(b bool) *IndexersUpdate {
|
|
iu.mutation.SetEnableRss(b)
|
|
return iu
|
|
}
|
|
|
|
// SetNillableEnableRss sets the "enable_rss" field if the given value is not nil.
|
|
func (iu *IndexersUpdate) SetNillableEnableRss(b *bool) *IndexersUpdate {
|
|
if b != nil {
|
|
iu.SetEnableRss(*b)
|
|
}
|
|
return iu
|
|
}
|
|
|
|
// SetPriority sets the "priority" field.
|
|
func (iu *IndexersUpdate) SetPriority(i int) *IndexersUpdate {
|
|
iu.mutation.ResetPriority()
|
|
iu.mutation.SetPriority(i)
|
|
return iu
|
|
}
|
|
|
|
// SetNillablePriority sets the "priority" field if the given value is not nil.
|
|
func (iu *IndexersUpdate) SetNillablePriority(i *int) *IndexersUpdate {
|
|
if i != nil {
|
|
iu.SetPriority(*i)
|
|
}
|
|
return iu
|
|
}
|
|
|
|
// AddPriority adds i to the "priority" field.
|
|
func (iu *IndexersUpdate) AddPriority(i int) *IndexersUpdate {
|
|
iu.mutation.AddPriority(i)
|
|
return iu
|
|
}
|
|
|
|
// Mutation returns the IndexersMutation object of the builder.
|
|
func (iu *IndexersUpdate) Mutation() *IndexersMutation {
|
|
return iu.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (iu *IndexersUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, iu.sqlSave, iu.mutation, iu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (iu *IndexersUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := iu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (iu *IndexersUpdate) Exec(ctx context.Context) error {
|
|
_, err := iu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (iu *IndexersUpdate) ExecX(ctx context.Context) {
|
|
if err := iu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (iu *IndexersUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(indexers.Table, indexers.Columns, sqlgraph.NewFieldSpec(indexers.FieldID, field.TypeInt))
|
|
if ps := iu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := iu.mutation.Name(); ok {
|
|
_spec.SetField(indexers.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := iu.mutation.Implementation(); ok {
|
|
_spec.SetField(indexers.FieldImplementation, field.TypeString, value)
|
|
}
|
|
if value, ok := iu.mutation.Settings(); ok {
|
|
_spec.SetField(indexers.FieldSettings, field.TypeString, value)
|
|
}
|
|
if value, ok := iu.mutation.EnableRss(); ok {
|
|
_spec.SetField(indexers.FieldEnableRss, field.TypeBool, value)
|
|
}
|
|
if value, ok := iu.mutation.Priority(); ok {
|
|
_spec.SetField(indexers.FieldPriority, field.TypeInt, value)
|
|
}
|
|
if value, ok := iu.mutation.AddedPriority(); ok {
|
|
_spec.AddField(indexers.FieldPriority, field.TypeInt, value)
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{indexers.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
iu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// IndexersUpdateOne is the builder for updating a single Indexers entity.
|
|
type IndexersUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *IndexersMutation
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (iuo *IndexersUpdateOne) SetName(s string) *IndexersUpdateOne {
|
|
iuo.mutation.SetName(s)
|
|
return iuo
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (iuo *IndexersUpdateOne) SetNillableName(s *string) *IndexersUpdateOne {
|
|
if s != nil {
|
|
iuo.SetName(*s)
|
|
}
|
|
return iuo
|
|
}
|
|
|
|
// SetImplementation sets the "implementation" field.
|
|
func (iuo *IndexersUpdateOne) SetImplementation(s string) *IndexersUpdateOne {
|
|
iuo.mutation.SetImplementation(s)
|
|
return iuo
|
|
}
|
|
|
|
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
|
|
func (iuo *IndexersUpdateOne) SetNillableImplementation(s *string) *IndexersUpdateOne {
|
|
if s != nil {
|
|
iuo.SetImplementation(*s)
|
|
}
|
|
return iuo
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (iuo *IndexersUpdateOne) SetSettings(s string) *IndexersUpdateOne {
|
|
iuo.mutation.SetSettings(s)
|
|
return iuo
|
|
}
|
|
|
|
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
|
func (iuo *IndexersUpdateOne) SetNillableSettings(s *string) *IndexersUpdateOne {
|
|
if s != nil {
|
|
iuo.SetSettings(*s)
|
|
}
|
|
return iuo
|
|
}
|
|
|
|
// SetEnableRss sets the "enable_rss" field.
|
|
func (iuo *IndexersUpdateOne) SetEnableRss(b bool) *IndexersUpdateOne {
|
|
iuo.mutation.SetEnableRss(b)
|
|
return iuo
|
|
}
|
|
|
|
// SetNillableEnableRss sets the "enable_rss" field if the given value is not nil.
|
|
func (iuo *IndexersUpdateOne) SetNillableEnableRss(b *bool) *IndexersUpdateOne {
|
|
if b != nil {
|
|
iuo.SetEnableRss(*b)
|
|
}
|
|
return iuo
|
|
}
|
|
|
|
// SetPriority sets the "priority" field.
|
|
func (iuo *IndexersUpdateOne) SetPriority(i int) *IndexersUpdateOne {
|
|
iuo.mutation.ResetPriority()
|
|
iuo.mutation.SetPriority(i)
|
|
return iuo
|
|
}
|
|
|
|
// SetNillablePriority sets the "priority" field if the given value is not nil.
|
|
func (iuo *IndexersUpdateOne) SetNillablePriority(i *int) *IndexersUpdateOne {
|
|
if i != nil {
|
|
iuo.SetPriority(*i)
|
|
}
|
|
return iuo
|
|
}
|
|
|
|
// AddPriority adds i to the "priority" field.
|
|
func (iuo *IndexersUpdateOne) AddPriority(i int) *IndexersUpdateOne {
|
|
iuo.mutation.AddPriority(i)
|
|
return iuo
|
|
}
|
|
|
|
// Mutation returns the IndexersMutation object of the builder.
|
|
func (iuo *IndexersUpdateOne) Mutation() *IndexersMutation {
|
|
return iuo.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the IndexersUpdate builder.
|
|
func (iuo *IndexersUpdateOne) Where(ps ...predicate.Indexers) *IndexersUpdateOne {
|
|
iuo.mutation.Where(ps...)
|
|
return iuo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (iuo *IndexersUpdateOne) Select(field string, fields ...string) *IndexersUpdateOne {
|
|
iuo.fields = append([]string{field}, fields...)
|
|
return iuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Indexers entity.
|
|
func (iuo *IndexersUpdateOne) Save(ctx context.Context) (*Indexers, error) {
|
|
return withHooks(ctx, iuo.sqlSave, iuo.mutation, iuo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (iuo *IndexersUpdateOne) SaveX(ctx context.Context) *Indexers {
|
|
node, err := iuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (iuo *IndexersUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := iuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (iuo *IndexersUpdateOne) ExecX(ctx context.Context) {
|
|
if err := iuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (iuo *IndexersUpdateOne) sqlSave(ctx context.Context) (_node *Indexers, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(indexers.Table, indexers.Columns, sqlgraph.NewFieldSpec(indexers.FieldID, field.TypeInt))
|
|
id, ok := iuo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Indexers.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := iuo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, indexers.FieldID)
|
|
for _, f := range fields {
|
|
if !indexers.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != indexers.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := iuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := iuo.mutation.Name(); ok {
|
|
_spec.SetField(indexers.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := iuo.mutation.Implementation(); ok {
|
|
_spec.SetField(indexers.FieldImplementation, field.TypeString, value)
|
|
}
|
|
if value, ok := iuo.mutation.Settings(); ok {
|
|
_spec.SetField(indexers.FieldSettings, field.TypeString, value)
|
|
}
|
|
if value, ok := iuo.mutation.EnableRss(); ok {
|
|
_spec.SetField(indexers.FieldEnableRss, field.TypeBool, value)
|
|
}
|
|
if value, ok := iuo.mutation.Priority(); ok {
|
|
_spec.SetField(indexers.FieldPriority, field.TypeInt, value)
|
|
}
|
|
if value, ok := iuo.mutation.AddedPriority(); ok {
|
|
_spec.AddField(indexers.FieldPriority, field.TypeInt, value)
|
|
}
|
|
_node = &Indexers{config: iuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, iuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{indexers.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
iuo.mutation.done = true
|
|
return _node, nil
|
|
}
|