mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
450 lines
12 KiB
Go
450 lines
12 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 string) *StorageUpdate {
|
|
su.mutation.SetImplementation(s)
|
|
return su
|
|
}
|
|
|
|
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
|
|
func (su *StorageUpdate) SetNillableImplementation(s *string) *StorageUpdate {
|
|
if s != nil {
|
|
su.SetImplementation(*s)
|
|
}
|
|
return su
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (su *StorageUpdate) SetPath(s string) *StorageUpdate {
|
|
su.mutation.SetPath(s)
|
|
return su
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (su *StorageUpdate) SetNillablePath(s *string) *StorageUpdate {
|
|
if s != nil {
|
|
su.SetPath(*s)
|
|
}
|
|
return su
|
|
}
|
|
|
|
// SetUser sets the "user" field.
|
|
func (su *StorageUpdate) SetUser(s string) *StorageUpdate {
|
|
su.mutation.SetUser(s)
|
|
return su
|
|
}
|
|
|
|
// SetNillableUser sets the "user" field if the given value is not nil.
|
|
func (su *StorageUpdate) SetNillableUser(s *string) *StorageUpdate {
|
|
if s != nil {
|
|
su.SetUser(*s)
|
|
}
|
|
return su
|
|
}
|
|
|
|
// ClearUser clears the value of the "user" field.
|
|
func (su *StorageUpdate) ClearUser() *StorageUpdate {
|
|
su.mutation.ClearUser()
|
|
return su
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (su *StorageUpdate) SetPassword(s string) *StorageUpdate {
|
|
su.mutation.SetPassword(s)
|
|
return su
|
|
}
|
|
|
|
// SetNillablePassword sets the "password" field if the given value is not nil.
|
|
func (su *StorageUpdate) SetNillablePassword(s *string) *StorageUpdate {
|
|
if s != nil {
|
|
su.SetPassword(*s)
|
|
}
|
|
return su
|
|
}
|
|
|
|
// ClearPassword clears the value of the "password" field.
|
|
func (su *StorageUpdate) ClearPassword() *StorageUpdate {
|
|
su.mutation.ClearPassword()
|
|
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)
|
|
}
|
|
}
|
|
|
|
func (su *StorageUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_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.TypeString, value)
|
|
}
|
|
if value, ok := su.mutation.Path(); ok {
|
|
_spec.SetField(storage.FieldPath, field.TypeString, value)
|
|
}
|
|
if value, ok := su.mutation.User(); ok {
|
|
_spec.SetField(storage.FieldUser, field.TypeString, value)
|
|
}
|
|
if su.mutation.UserCleared() {
|
|
_spec.ClearField(storage.FieldUser, field.TypeString)
|
|
}
|
|
if value, ok := su.mutation.Password(); ok {
|
|
_spec.SetField(storage.FieldPassword, field.TypeString, value)
|
|
}
|
|
if su.mutation.PasswordCleared() {
|
|
_spec.ClearField(storage.FieldPassword, 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 string) *StorageUpdateOne {
|
|
suo.mutation.SetImplementation(s)
|
|
return suo
|
|
}
|
|
|
|
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
|
|
func (suo *StorageUpdateOne) SetNillableImplementation(s *string) *StorageUpdateOne {
|
|
if s != nil {
|
|
suo.SetImplementation(*s)
|
|
}
|
|
return suo
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (suo *StorageUpdateOne) SetPath(s string) *StorageUpdateOne {
|
|
suo.mutation.SetPath(s)
|
|
return suo
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (suo *StorageUpdateOne) SetNillablePath(s *string) *StorageUpdateOne {
|
|
if s != nil {
|
|
suo.SetPath(*s)
|
|
}
|
|
return suo
|
|
}
|
|
|
|
// SetUser sets the "user" field.
|
|
func (suo *StorageUpdateOne) SetUser(s string) *StorageUpdateOne {
|
|
suo.mutation.SetUser(s)
|
|
return suo
|
|
}
|
|
|
|
// SetNillableUser sets the "user" field if the given value is not nil.
|
|
func (suo *StorageUpdateOne) SetNillableUser(s *string) *StorageUpdateOne {
|
|
if s != nil {
|
|
suo.SetUser(*s)
|
|
}
|
|
return suo
|
|
}
|
|
|
|
// ClearUser clears the value of the "user" field.
|
|
func (suo *StorageUpdateOne) ClearUser() *StorageUpdateOne {
|
|
suo.mutation.ClearUser()
|
|
return suo
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (suo *StorageUpdateOne) SetPassword(s string) *StorageUpdateOne {
|
|
suo.mutation.SetPassword(s)
|
|
return suo
|
|
}
|
|
|
|
// SetNillablePassword sets the "password" field if the given value is not nil.
|
|
func (suo *StorageUpdateOne) SetNillablePassword(s *string) *StorageUpdateOne {
|
|
if s != nil {
|
|
suo.SetPassword(*s)
|
|
}
|
|
return suo
|
|
}
|
|
|
|
// ClearPassword clears the value of the "password" field.
|
|
func (suo *StorageUpdateOne) ClearPassword() *StorageUpdateOne {
|
|
suo.mutation.ClearPassword()
|
|
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)
|
|
}
|
|
}
|
|
|
|
func (suo *StorageUpdateOne) sqlSave(ctx context.Context) (_node *Storage, err error) {
|
|
_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.TypeString, value)
|
|
}
|
|
if value, ok := suo.mutation.Path(); ok {
|
|
_spec.SetField(storage.FieldPath, field.TypeString, value)
|
|
}
|
|
if value, ok := suo.mutation.User(); ok {
|
|
_spec.SetField(storage.FieldUser, field.TypeString, value)
|
|
}
|
|
if suo.mutation.UserCleared() {
|
|
_spec.ClearField(storage.FieldUser, field.TypeString)
|
|
}
|
|
if value, ok := suo.mutation.Password(); ok {
|
|
_spec.SetField(storage.FieldPassword, field.TypeString, value)
|
|
}
|
|
if suo.mutation.PasswordCleared() {
|
|
_spec.ClearField(storage.FieldPassword, 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
|
|
}
|