Files
polaris/ent/storage_update.go
2024-07-14 18:16:17 +08:00

390 lines
11 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/predicate"
"polaris/ent/storage"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StorageUpdate is the builder for updating Storage entities.
type StorageUpdate struct {
config
hooks []Hook
mutation *StorageMutation
}
// Where appends a list predicates to the StorageUpdate builder.
func (su *StorageUpdate) Where(ps ...predicate.Storage) *StorageUpdate {
su.mutation.Where(ps...)
return su
}
// SetName sets the "name" field.
func (su *StorageUpdate) SetName(s string) *StorageUpdate {
su.mutation.SetName(s)
return su
}
// SetNillableName sets the "name" field if the given value is not nil.
func (su *StorageUpdate) SetNillableName(s *string) *StorageUpdate {
if s != nil {
su.SetName(*s)
}
return su
}
// SetImplementation sets the "implementation" field.
func (su *StorageUpdate) SetImplementation(s storage.Implementation) *StorageUpdate {
su.mutation.SetImplementation(s)
return su
}
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
func (su *StorageUpdate) SetNillableImplementation(s *storage.Implementation) *StorageUpdate {
if s != nil {
su.SetImplementation(*s)
}
return su
}
// SetSettings sets the "settings" field.
func (su *StorageUpdate) SetSettings(s string) *StorageUpdate {
su.mutation.SetSettings(s)
return su
}
// SetNillableSettings sets the "settings" field if the given value is not nil.
func (su *StorageUpdate) SetNillableSettings(s *string) *StorageUpdate {
if s != nil {
su.SetSettings(*s)
}
return su
}
// ClearSettings clears the value of the "settings" field.
func (su *StorageUpdate) ClearSettings() *StorageUpdate {
su.mutation.ClearSettings()
return su
}
// SetDeleted sets the "deleted" field.
func (su *StorageUpdate) SetDeleted(b bool) *StorageUpdate {
su.mutation.SetDeleted(b)
return su
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (su *StorageUpdate) SetNillableDeleted(b *bool) *StorageUpdate {
if b != nil {
su.SetDeleted(*b)
}
return su
}
// SetDefault sets the "default" field.
func (su *StorageUpdate) SetDefault(b bool) *StorageUpdate {
su.mutation.SetDefault(b)
return su
}
// SetNillableDefault sets the "default" field if the given value is not nil.
func (su *StorageUpdate) SetNillableDefault(b *bool) *StorageUpdate {
if b != nil {
su.SetDefault(*b)
}
return su
}
// Mutation returns the StorageMutation object of the builder.
func (su *StorageUpdate) Mutation() *StorageMutation {
return su.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (su *StorageUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (su *StorageUpdate) SaveX(ctx context.Context) int {
affected, err := su.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (su *StorageUpdate) Exec(ctx context.Context) error {
_, err := su.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (su *StorageUpdate) ExecX(ctx context.Context) {
if err := su.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (su *StorageUpdate) check() error {
if v, ok := su.mutation.Implementation(); ok {
if err := storage.ImplementationValidator(v); err != nil {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "Storage.implementation": %w`, err)}
}
}
return nil
}
func (su *StorageUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := su.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(storage.Table, storage.Columns, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
if ps := su.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := su.mutation.Name(); ok {
_spec.SetField(storage.FieldName, field.TypeString, value)
}
if value, ok := su.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeEnum, value)
}
if value, ok := su.mutation.Settings(); ok {
_spec.SetField(storage.FieldSettings, field.TypeString, value)
}
if su.mutation.SettingsCleared() {
_spec.ClearField(storage.FieldSettings, field.TypeString)
}
if value, ok := su.mutation.Deleted(); ok {
_spec.SetField(storage.FieldDeleted, field.TypeBool, value)
}
if value, ok := su.mutation.Default(); ok {
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{storage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
su.mutation.done = true
return n, nil
}
// StorageUpdateOne is the builder for updating a single Storage entity.
type StorageUpdateOne struct {
config
fields []string
hooks []Hook
mutation *StorageMutation
}
// SetName sets the "name" field.
func (suo *StorageUpdateOne) SetName(s string) *StorageUpdateOne {
suo.mutation.SetName(s)
return suo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableName(s *string) *StorageUpdateOne {
if s != nil {
suo.SetName(*s)
}
return suo
}
// SetImplementation sets the "implementation" field.
func (suo *StorageUpdateOne) SetImplementation(s storage.Implementation) *StorageUpdateOne {
suo.mutation.SetImplementation(s)
return suo
}
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableImplementation(s *storage.Implementation) *StorageUpdateOne {
if s != nil {
suo.SetImplementation(*s)
}
return suo
}
// SetSettings sets the "settings" field.
func (suo *StorageUpdateOne) SetSettings(s string) *StorageUpdateOne {
suo.mutation.SetSettings(s)
return suo
}
// SetNillableSettings sets the "settings" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableSettings(s *string) *StorageUpdateOne {
if s != nil {
suo.SetSettings(*s)
}
return suo
}
// ClearSettings clears the value of the "settings" field.
func (suo *StorageUpdateOne) ClearSettings() *StorageUpdateOne {
suo.mutation.ClearSettings()
return suo
}
// SetDeleted sets the "deleted" field.
func (suo *StorageUpdateOne) SetDeleted(b bool) *StorageUpdateOne {
suo.mutation.SetDeleted(b)
return suo
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableDeleted(b *bool) *StorageUpdateOne {
if b != nil {
suo.SetDeleted(*b)
}
return suo
}
// SetDefault sets the "default" field.
func (suo *StorageUpdateOne) SetDefault(b bool) *StorageUpdateOne {
suo.mutation.SetDefault(b)
return suo
}
// SetNillableDefault sets the "default" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableDefault(b *bool) *StorageUpdateOne {
if b != nil {
suo.SetDefault(*b)
}
return suo
}
// Mutation returns the StorageMutation object of the builder.
func (suo *StorageUpdateOne) Mutation() *StorageMutation {
return suo.mutation
}
// Where appends a list predicates to the StorageUpdate builder.
func (suo *StorageUpdateOne) Where(ps ...predicate.Storage) *StorageUpdateOne {
suo.mutation.Where(ps...)
return suo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (suo *StorageUpdateOne) Select(field string, fields ...string) *StorageUpdateOne {
suo.fields = append([]string{field}, fields...)
return suo
}
// Save executes the query and returns the updated Storage entity.
func (suo *StorageUpdateOne) Save(ctx context.Context) (*Storage, error) {
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (suo *StorageUpdateOne) SaveX(ctx context.Context) *Storage {
node, err := suo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (suo *StorageUpdateOne) Exec(ctx context.Context) error {
_, err := suo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (suo *StorageUpdateOne) ExecX(ctx context.Context) {
if err := suo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (suo *StorageUpdateOne) check() error {
if v, ok := suo.mutation.Implementation(); ok {
if err := storage.ImplementationValidator(v); err != nil {
return &ValidationError{Name: "implementation", err: fmt.Errorf(`ent: validator failed for field "Storage.implementation": %w`, err)}
}
}
return nil
}
func (suo *StorageUpdateOne) sqlSave(ctx context.Context) (_node *Storage, err error) {
if err := suo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(storage.Table, storage.Columns, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
id, ok := suo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Storage.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := suo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, storage.FieldID)
for _, f := range fields {
if !storage.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != storage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := suo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := suo.mutation.Name(); ok {
_spec.SetField(storage.FieldName, field.TypeString, value)
}
if value, ok := suo.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeEnum, value)
}
if value, ok := suo.mutation.Settings(); ok {
_spec.SetField(storage.FieldSettings, field.TypeString, value)
}
if suo.mutation.SettingsCleared() {
_spec.ClearField(storage.FieldSettings, field.TypeString)
}
if value, ok := suo.mutation.Deleted(); ok {
_spec.SetField(storage.FieldDeleted, field.TypeBool, value)
}
if value, ok := suo.mutation.Default(); ok {
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
}
_node = &Storage{config: suo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{storage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
suo.mutation.done = true
return _node, nil
}