414 lines
12 KiB
Go
414 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"voidraft/internal/models/ent/extension"
|
|
"voidraft/internal/models/ent/predicate"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ExtensionUpdate is the builder for updating Extension entities.
|
|
type ExtensionUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *ExtensionMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the ExtensionUpdate builder.
|
|
func (_u *ExtensionUpdate) Where(ps ...predicate.Extension) *ExtensionUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *ExtensionUpdate) SetUpdatedAt(v string) *ExtensionUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *ExtensionUpdate) SetNillableUpdatedAt(v *string) *ExtensionUpdate {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_u *ExtensionUpdate) SetDeletedAt(v string) *ExtensionUpdate {
|
|
_u.mutation.SetDeletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_u *ExtensionUpdate) SetNillableDeletedAt(v *string) *ExtensionUpdate {
|
|
if v != nil {
|
|
_u.SetDeletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (_u *ExtensionUpdate) ClearDeletedAt() *ExtensionUpdate {
|
|
_u.mutation.ClearDeletedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (_u *ExtensionUpdate) SetKey(v string) *ExtensionUpdate {
|
|
_u.mutation.SetKey(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
|
func (_u *ExtensionUpdate) SetNillableKey(v *string) *ExtensionUpdate {
|
|
if v != nil {
|
|
_u.SetKey(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_u *ExtensionUpdate) SetEnabled(v bool) *ExtensionUpdate {
|
|
_u.mutation.SetEnabled(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_u *ExtensionUpdate) SetNillableEnabled(v *bool) *ExtensionUpdate {
|
|
if v != nil {
|
|
_u.SetEnabled(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetConfig sets the "config" field.
|
|
func (_u *ExtensionUpdate) SetConfig(v map[string]interface{}) *ExtensionUpdate {
|
|
_u.mutation.SetConfig(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearConfig clears the value of the "config" field.
|
|
func (_u *ExtensionUpdate) ClearConfig() *ExtensionUpdate {
|
|
_u.mutation.ClearConfig()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the ExtensionMutation object of the builder.
|
|
func (_u *ExtensionUpdate) Mutation() *ExtensionMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *ExtensionUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *ExtensionUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *ExtensionUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ExtensionUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *ExtensionUpdate) check() error {
|
|
if v, ok := _u.mutation.Key(); ok {
|
|
if err := extension.KeyValidator(v); err != nil {
|
|
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "Extension.key": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *ExtensionUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ExtensionUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *ExtensionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(extension.Table, extension.Columns, sqlgraph.NewFieldSpec(extension.FieldID, field.TypeInt))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if _u.mutation.UUIDCleared() {
|
|
_spec.ClearField(extension.FieldUUID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(extension.FieldUpdatedAt, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.DeletedAt(); ok {
|
|
_spec.SetField(extension.FieldDeletedAt, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DeletedAtCleared() {
|
|
_spec.ClearField(extension.FieldDeletedAt, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Key(); ok {
|
|
_spec.SetField(extension.FieldKey, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(extension.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Config(); ok {
|
|
_spec.SetField(extension.FieldConfig, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.ConfigCleared() {
|
|
_spec.ClearField(extension.FieldConfig, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{extension.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// ExtensionUpdateOne is the builder for updating a single Extension entity.
|
|
type ExtensionUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *ExtensionMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *ExtensionUpdateOne) SetUpdatedAt(v string) *ExtensionUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *ExtensionUpdateOne) SetNillableUpdatedAt(v *string) *ExtensionUpdateOne {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_u *ExtensionUpdateOne) SetDeletedAt(v string) *ExtensionUpdateOne {
|
|
_u.mutation.SetDeletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_u *ExtensionUpdateOne) SetNillableDeletedAt(v *string) *ExtensionUpdateOne {
|
|
if v != nil {
|
|
_u.SetDeletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (_u *ExtensionUpdateOne) ClearDeletedAt() *ExtensionUpdateOne {
|
|
_u.mutation.ClearDeletedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (_u *ExtensionUpdateOne) SetKey(v string) *ExtensionUpdateOne {
|
|
_u.mutation.SetKey(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
|
func (_u *ExtensionUpdateOne) SetNillableKey(v *string) *ExtensionUpdateOne {
|
|
if v != nil {
|
|
_u.SetKey(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_u *ExtensionUpdateOne) SetEnabled(v bool) *ExtensionUpdateOne {
|
|
_u.mutation.SetEnabled(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_u *ExtensionUpdateOne) SetNillableEnabled(v *bool) *ExtensionUpdateOne {
|
|
if v != nil {
|
|
_u.SetEnabled(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetConfig sets the "config" field.
|
|
func (_u *ExtensionUpdateOne) SetConfig(v map[string]interface{}) *ExtensionUpdateOne {
|
|
_u.mutation.SetConfig(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearConfig clears the value of the "config" field.
|
|
func (_u *ExtensionUpdateOne) ClearConfig() *ExtensionUpdateOne {
|
|
_u.mutation.ClearConfig()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the ExtensionMutation object of the builder.
|
|
func (_u *ExtensionUpdateOne) Mutation() *ExtensionMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ExtensionUpdate builder.
|
|
func (_u *ExtensionUpdateOne) Where(ps ...predicate.Extension) *ExtensionUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *ExtensionUpdateOne) Select(field string, fields ...string) *ExtensionUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Extension entity.
|
|
func (_u *ExtensionUpdateOne) Save(ctx context.Context) (*Extension, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *ExtensionUpdateOne) SaveX(ctx context.Context) *Extension {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *ExtensionUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ExtensionUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *ExtensionUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Key(); ok {
|
|
if err := extension.KeyValidator(v); err != nil {
|
|
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "Extension.key": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *ExtensionUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ExtensionUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *ExtensionUpdateOne) sqlSave(ctx context.Context) (_node *Extension, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(extension.Table, extension.Columns, sqlgraph.NewFieldSpec(extension.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Extension.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, extension.FieldID)
|
|
for _, f := range fields {
|
|
if !extension.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != extension.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if _u.mutation.UUIDCleared() {
|
|
_spec.ClearField(extension.FieldUUID, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(extension.FieldUpdatedAt, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.DeletedAt(); ok {
|
|
_spec.SetField(extension.FieldDeletedAt, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DeletedAtCleared() {
|
|
_spec.ClearField(extension.FieldDeletedAt, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Key(); ok {
|
|
_spec.SetField(extension.FieldKey, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(extension.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Config(); ok {
|
|
_spec.SetField(extension.FieldConfig, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.ConfigCleared() {
|
|
_spec.ClearField(extension.FieldConfig, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &Extension{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{extension.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|