mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
463 lines
13 KiB
Go
463 lines
13 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"polaris/ent/importlist"
|
|
"polaris/ent/predicate"
|
|
"polaris/ent/schema"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ImportListUpdate is the builder for updating ImportList entities.
|
|
type ImportListUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *ImportListMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ImportListUpdate builder.
|
|
func (ilu *ImportListUpdate) Where(ps ...predicate.ImportList) *ImportListUpdate {
|
|
ilu.mutation.Where(ps...)
|
|
return ilu
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (ilu *ImportListUpdate) SetName(s string) *ImportListUpdate {
|
|
ilu.mutation.SetName(s)
|
|
return ilu
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (ilu *ImportListUpdate) SetNillableName(s *string) *ImportListUpdate {
|
|
if s != nil {
|
|
ilu.SetName(*s)
|
|
}
|
|
return ilu
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (ilu *ImportListUpdate) SetType(i importlist.Type) *ImportListUpdate {
|
|
ilu.mutation.SetType(i)
|
|
return ilu
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (ilu *ImportListUpdate) SetNillableType(i *importlist.Type) *ImportListUpdate {
|
|
if i != nil {
|
|
ilu.SetType(*i)
|
|
}
|
|
return ilu
|
|
}
|
|
|
|
// SetURL sets the "url" field.
|
|
func (ilu *ImportListUpdate) SetURL(s string) *ImportListUpdate {
|
|
ilu.mutation.SetURL(s)
|
|
return ilu
|
|
}
|
|
|
|
// SetNillableURL sets the "url" field if the given value is not nil.
|
|
func (ilu *ImportListUpdate) SetNillableURL(s *string) *ImportListUpdate {
|
|
if s != nil {
|
|
ilu.SetURL(*s)
|
|
}
|
|
return ilu
|
|
}
|
|
|
|
// ClearURL clears the value of the "url" field.
|
|
func (ilu *ImportListUpdate) ClearURL() *ImportListUpdate {
|
|
ilu.mutation.ClearURL()
|
|
return ilu
|
|
}
|
|
|
|
// SetQulity sets the "qulity" field.
|
|
func (ilu *ImportListUpdate) SetQulity(s string) *ImportListUpdate {
|
|
ilu.mutation.SetQulity(s)
|
|
return ilu
|
|
}
|
|
|
|
// SetNillableQulity sets the "qulity" field if the given value is not nil.
|
|
func (ilu *ImportListUpdate) SetNillableQulity(s *string) *ImportListUpdate {
|
|
if s != nil {
|
|
ilu.SetQulity(*s)
|
|
}
|
|
return ilu
|
|
}
|
|
|
|
// SetStorageID sets the "storage_id" field.
|
|
func (ilu *ImportListUpdate) SetStorageID(i int) *ImportListUpdate {
|
|
ilu.mutation.ResetStorageID()
|
|
ilu.mutation.SetStorageID(i)
|
|
return ilu
|
|
}
|
|
|
|
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
|
|
func (ilu *ImportListUpdate) SetNillableStorageID(i *int) *ImportListUpdate {
|
|
if i != nil {
|
|
ilu.SetStorageID(*i)
|
|
}
|
|
return ilu
|
|
}
|
|
|
|
// AddStorageID adds i to the "storage_id" field.
|
|
func (ilu *ImportListUpdate) AddStorageID(i int) *ImportListUpdate {
|
|
ilu.mutation.AddStorageID(i)
|
|
return ilu
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (ilu *ImportListUpdate) SetSettings(sls schema.ImportListSettings) *ImportListUpdate {
|
|
ilu.mutation.SetSettings(sls)
|
|
return ilu
|
|
}
|
|
|
|
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
|
func (ilu *ImportListUpdate) SetNillableSettings(sls *schema.ImportListSettings) *ImportListUpdate {
|
|
if sls != nil {
|
|
ilu.SetSettings(*sls)
|
|
}
|
|
return ilu
|
|
}
|
|
|
|
// ClearSettings clears the value of the "settings" field.
|
|
func (ilu *ImportListUpdate) ClearSettings() *ImportListUpdate {
|
|
ilu.mutation.ClearSettings()
|
|
return ilu
|
|
}
|
|
|
|
// Mutation returns the ImportListMutation object of the builder.
|
|
func (ilu *ImportListUpdate) Mutation() *ImportListMutation {
|
|
return ilu.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (ilu *ImportListUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, ilu.sqlSave, ilu.mutation, ilu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (ilu *ImportListUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := ilu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (ilu *ImportListUpdate) Exec(ctx context.Context) error {
|
|
_, err := ilu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ilu *ImportListUpdate) ExecX(ctx context.Context) {
|
|
if err := ilu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (ilu *ImportListUpdate) check() error {
|
|
if v, ok := ilu.mutation.GetType(); ok {
|
|
if err := importlist.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ImportList.type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ilu *ImportListUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := ilu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(importlist.Table, importlist.Columns, sqlgraph.NewFieldSpec(importlist.FieldID, field.TypeInt))
|
|
if ps := ilu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := ilu.mutation.Name(); ok {
|
|
_spec.SetField(importlist.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := ilu.mutation.GetType(); ok {
|
|
_spec.SetField(importlist.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := ilu.mutation.URL(); ok {
|
|
_spec.SetField(importlist.FieldURL, field.TypeString, value)
|
|
}
|
|
if ilu.mutation.URLCleared() {
|
|
_spec.ClearField(importlist.FieldURL, field.TypeString)
|
|
}
|
|
if value, ok := ilu.mutation.Qulity(); ok {
|
|
_spec.SetField(importlist.FieldQulity, field.TypeString, value)
|
|
}
|
|
if value, ok := ilu.mutation.StorageID(); ok {
|
|
_spec.SetField(importlist.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if value, ok := ilu.mutation.AddedStorageID(); ok {
|
|
_spec.AddField(importlist.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if value, ok := ilu.mutation.Settings(); ok {
|
|
_spec.SetField(importlist.FieldSettings, field.TypeJSON, value)
|
|
}
|
|
if ilu.mutation.SettingsCleared() {
|
|
_spec.ClearField(importlist.FieldSettings, field.TypeJSON)
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, ilu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{importlist.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
ilu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// ImportListUpdateOne is the builder for updating a single ImportList entity.
|
|
type ImportListUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *ImportListMutation
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (iluo *ImportListUpdateOne) SetName(s string) *ImportListUpdateOne {
|
|
iluo.mutation.SetName(s)
|
|
return iluo
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (iluo *ImportListUpdateOne) SetNillableName(s *string) *ImportListUpdateOne {
|
|
if s != nil {
|
|
iluo.SetName(*s)
|
|
}
|
|
return iluo
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (iluo *ImportListUpdateOne) SetType(i importlist.Type) *ImportListUpdateOne {
|
|
iluo.mutation.SetType(i)
|
|
return iluo
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (iluo *ImportListUpdateOne) SetNillableType(i *importlist.Type) *ImportListUpdateOne {
|
|
if i != nil {
|
|
iluo.SetType(*i)
|
|
}
|
|
return iluo
|
|
}
|
|
|
|
// SetURL sets the "url" field.
|
|
func (iluo *ImportListUpdateOne) SetURL(s string) *ImportListUpdateOne {
|
|
iluo.mutation.SetURL(s)
|
|
return iluo
|
|
}
|
|
|
|
// SetNillableURL sets the "url" field if the given value is not nil.
|
|
func (iluo *ImportListUpdateOne) SetNillableURL(s *string) *ImportListUpdateOne {
|
|
if s != nil {
|
|
iluo.SetURL(*s)
|
|
}
|
|
return iluo
|
|
}
|
|
|
|
// ClearURL clears the value of the "url" field.
|
|
func (iluo *ImportListUpdateOne) ClearURL() *ImportListUpdateOne {
|
|
iluo.mutation.ClearURL()
|
|
return iluo
|
|
}
|
|
|
|
// SetQulity sets the "qulity" field.
|
|
func (iluo *ImportListUpdateOne) SetQulity(s string) *ImportListUpdateOne {
|
|
iluo.mutation.SetQulity(s)
|
|
return iluo
|
|
}
|
|
|
|
// SetNillableQulity sets the "qulity" field if the given value is not nil.
|
|
func (iluo *ImportListUpdateOne) SetNillableQulity(s *string) *ImportListUpdateOne {
|
|
if s != nil {
|
|
iluo.SetQulity(*s)
|
|
}
|
|
return iluo
|
|
}
|
|
|
|
// SetStorageID sets the "storage_id" field.
|
|
func (iluo *ImportListUpdateOne) SetStorageID(i int) *ImportListUpdateOne {
|
|
iluo.mutation.ResetStorageID()
|
|
iluo.mutation.SetStorageID(i)
|
|
return iluo
|
|
}
|
|
|
|
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
|
|
func (iluo *ImportListUpdateOne) SetNillableStorageID(i *int) *ImportListUpdateOne {
|
|
if i != nil {
|
|
iluo.SetStorageID(*i)
|
|
}
|
|
return iluo
|
|
}
|
|
|
|
// AddStorageID adds i to the "storage_id" field.
|
|
func (iluo *ImportListUpdateOne) AddStorageID(i int) *ImportListUpdateOne {
|
|
iluo.mutation.AddStorageID(i)
|
|
return iluo
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (iluo *ImportListUpdateOne) SetSettings(sls schema.ImportListSettings) *ImportListUpdateOne {
|
|
iluo.mutation.SetSettings(sls)
|
|
return iluo
|
|
}
|
|
|
|
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
|
func (iluo *ImportListUpdateOne) SetNillableSettings(sls *schema.ImportListSettings) *ImportListUpdateOne {
|
|
if sls != nil {
|
|
iluo.SetSettings(*sls)
|
|
}
|
|
return iluo
|
|
}
|
|
|
|
// ClearSettings clears the value of the "settings" field.
|
|
func (iluo *ImportListUpdateOne) ClearSettings() *ImportListUpdateOne {
|
|
iluo.mutation.ClearSettings()
|
|
return iluo
|
|
}
|
|
|
|
// Mutation returns the ImportListMutation object of the builder.
|
|
func (iluo *ImportListUpdateOne) Mutation() *ImportListMutation {
|
|
return iluo.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ImportListUpdate builder.
|
|
func (iluo *ImportListUpdateOne) Where(ps ...predicate.ImportList) *ImportListUpdateOne {
|
|
iluo.mutation.Where(ps...)
|
|
return iluo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (iluo *ImportListUpdateOne) Select(field string, fields ...string) *ImportListUpdateOne {
|
|
iluo.fields = append([]string{field}, fields...)
|
|
return iluo
|
|
}
|
|
|
|
// Save executes the query and returns the updated ImportList entity.
|
|
func (iluo *ImportListUpdateOne) Save(ctx context.Context) (*ImportList, error) {
|
|
return withHooks(ctx, iluo.sqlSave, iluo.mutation, iluo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (iluo *ImportListUpdateOne) SaveX(ctx context.Context) *ImportList {
|
|
node, err := iluo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (iluo *ImportListUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := iluo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (iluo *ImportListUpdateOne) ExecX(ctx context.Context) {
|
|
if err := iluo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (iluo *ImportListUpdateOne) check() error {
|
|
if v, ok := iluo.mutation.GetType(); ok {
|
|
if err := importlist.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ImportList.type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (iluo *ImportListUpdateOne) sqlSave(ctx context.Context) (_node *ImportList, err error) {
|
|
if err := iluo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(importlist.Table, importlist.Columns, sqlgraph.NewFieldSpec(importlist.FieldID, field.TypeInt))
|
|
id, ok := iluo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ImportList.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := iluo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, importlist.FieldID)
|
|
for _, f := range fields {
|
|
if !importlist.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != importlist.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := iluo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := iluo.mutation.Name(); ok {
|
|
_spec.SetField(importlist.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := iluo.mutation.GetType(); ok {
|
|
_spec.SetField(importlist.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := iluo.mutation.URL(); ok {
|
|
_spec.SetField(importlist.FieldURL, field.TypeString, value)
|
|
}
|
|
if iluo.mutation.URLCleared() {
|
|
_spec.ClearField(importlist.FieldURL, field.TypeString)
|
|
}
|
|
if value, ok := iluo.mutation.Qulity(); ok {
|
|
_spec.SetField(importlist.FieldQulity, field.TypeString, value)
|
|
}
|
|
if value, ok := iluo.mutation.StorageID(); ok {
|
|
_spec.SetField(importlist.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if value, ok := iluo.mutation.AddedStorageID(); ok {
|
|
_spec.AddField(importlist.FieldStorageID, field.TypeInt, value)
|
|
}
|
|
if value, ok := iluo.mutation.Settings(); ok {
|
|
_spec.SetField(importlist.FieldSettings, field.TypeJSON, value)
|
|
}
|
|
if iluo.mutation.SettingsCleared() {
|
|
_spec.ClearField(importlist.FieldSettings, field.TypeJSON)
|
|
}
|
|
_node = &ImportList{config: iluo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, iluo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{importlist.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
iluo.mutation.done = true
|
|
return _node, nil
|
|
}
|