// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "voidraft/internal/models/ent/predicate" "voidraft/internal/models/ent/theme" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // ThemeUpdate is the builder for updating Theme entities. type ThemeUpdate struct { config hooks []Hook mutation *ThemeMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the ThemeUpdate builder. func (_u *ThemeUpdate) Where(ps ...predicate.Theme) *ThemeUpdate { _u.mutation.Where(ps...) return _u } // SetUpdatedAt sets the "updated_at" field. func (_u *ThemeUpdate) SetUpdatedAt(v string) *ThemeUpdate { _u.mutation.SetUpdatedAt(v) return _u } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_u *ThemeUpdate) SetNillableUpdatedAt(v *string) *ThemeUpdate { if v != nil { _u.SetUpdatedAt(*v) } return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *ThemeUpdate) SetDeletedAt(v string) *ThemeUpdate { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *ThemeUpdate) SetNillableDeletedAt(v *string) *ThemeUpdate { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *ThemeUpdate) ClearDeletedAt() *ThemeUpdate { _u.mutation.ClearDeletedAt() return _u } // SetKey sets the "key" field. func (_u *ThemeUpdate) SetKey(v string) *ThemeUpdate { _u.mutation.SetKey(v) return _u } // SetNillableKey sets the "key" field if the given value is not nil. func (_u *ThemeUpdate) SetNillableKey(v *string) *ThemeUpdate { if v != nil { _u.SetKey(*v) } return _u } // SetType sets the "type" field. func (_u *ThemeUpdate) SetType(v theme.Type) *ThemeUpdate { _u.mutation.SetType(v) return _u } // SetNillableType sets the "type" field if the given value is not nil. func (_u *ThemeUpdate) SetNillableType(v *theme.Type) *ThemeUpdate { if v != nil { _u.SetType(*v) } return _u } // SetColors sets the "colors" field. func (_u *ThemeUpdate) SetColors(v map[string]interface{}) *ThemeUpdate { _u.mutation.SetColors(v) return _u } // ClearColors clears the value of the "colors" field. func (_u *ThemeUpdate) ClearColors() *ThemeUpdate { _u.mutation.ClearColors() return _u } // Mutation returns the ThemeMutation object of the builder. func (_u *ThemeUpdate) Mutation() *ThemeMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *ThemeUpdate) 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 *ThemeUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *ThemeUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ThemeUpdate) 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 *ThemeUpdate) check() error { if v, ok := _u.mutation.Key(); ok { if err := theme.KeyValidator(v); err != nil { return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "Theme.key": %w`, err)} } } if v, ok := _u.mutation.GetType(); ok { if err := theme.TypeValidator(v); err != nil { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Theme.type": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *ThemeUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ThemeUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *ThemeUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(theme.Table, theme.Columns, sqlgraph.NewFieldSpec(theme.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(theme.FieldUUID, field.TypeString) } if value, ok := _u.mutation.UpdatedAt(); ok { _spec.SetField(theme.FieldUpdatedAt, field.TypeString, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(theme.FieldDeletedAt, field.TypeString, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(theme.FieldDeletedAt, field.TypeString) } if value, ok := _u.mutation.Key(); ok { _spec.SetField(theme.FieldKey, field.TypeString, value) } if value, ok := _u.mutation.GetType(); ok { _spec.SetField(theme.FieldType, field.TypeEnum, value) } if value, ok := _u.mutation.Colors(); ok { _spec.SetField(theme.FieldColors, field.TypeJSON, value) } if _u.mutation.ColorsCleared() { _spec.ClearField(theme.FieldColors, 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{theme.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // ThemeUpdateOne is the builder for updating a single Theme entity. type ThemeUpdateOne struct { config fields []string hooks []Hook mutation *ThemeMutation modifiers []func(*sql.UpdateBuilder) } // SetUpdatedAt sets the "updated_at" field. func (_u *ThemeUpdateOne) SetUpdatedAt(v string) *ThemeUpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_u *ThemeUpdateOne) SetNillableUpdatedAt(v *string) *ThemeUpdateOne { if v != nil { _u.SetUpdatedAt(*v) } return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *ThemeUpdateOne) SetDeletedAt(v string) *ThemeUpdateOne { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *ThemeUpdateOne) SetNillableDeletedAt(v *string) *ThemeUpdateOne { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *ThemeUpdateOne) ClearDeletedAt() *ThemeUpdateOne { _u.mutation.ClearDeletedAt() return _u } // SetKey sets the "key" field. func (_u *ThemeUpdateOne) SetKey(v string) *ThemeUpdateOne { _u.mutation.SetKey(v) return _u } // SetNillableKey sets the "key" field if the given value is not nil. func (_u *ThemeUpdateOne) SetNillableKey(v *string) *ThemeUpdateOne { if v != nil { _u.SetKey(*v) } return _u } // SetType sets the "type" field. func (_u *ThemeUpdateOne) SetType(v theme.Type) *ThemeUpdateOne { _u.mutation.SetType(v) return _u } // SetNillableType sets the "type" field if the given value is not nil. func (_u *ThemeUpdateOne) SetNillableType(v *theme.Type) *ThemeUpdateOne { if v != nil { _u.SetType(*v) } return _u } // SetColors sets the "colors" field. func (_u *ThemeUpdateOne) SetColors(v map[string]interface{}) *ThemeUpdateOne { _u.mutation.SetColors(v) return _u } // ClearColors clears the value of the "colors" field. func (_u *ThemeUpdateOne) ClearColors() *ThemeUpdateOne { _u.mutation.ClearColors() return _u } // Mutation returns the ThemeMutation object of the builder. func (_u *ThemeUpdateOne) Mutation() *ThemeMutation { return _u.mutation } // Where appends a list predicates to the ThemeUpdate builder. func (_u *ThemeUpdateOne) Where(ps ...predicate.Theme) *ThemeUpdateOne { _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 *ThemeUpdateOne) Select(field string, fields ...string) *ThemeUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated Theme entity. func (_u *ThemeUpdateOne) Save(ctx context.Context) (*Theme, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *ThemeUpdateOne) SaveX(ctx context.Context) *Theme { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *ThemeUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ThemeUpdateOne) 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 *ThemeUpdateOne) check() error { if v, ok := _u.mutation.Key(); ok { if err := theme.KeyValidator(v); err != nil { return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "Theme.key": %w`, err)} } } if v, ok := _u.mutation.GetType(); ok { if err := theme.TypeValidator(v); err != nil { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Theme.type": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *ThemeUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ThemeUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *ThemeUpdateOne) sqlSave(ctx context.Context) (_node *Theme, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(theme.Table, theme.Columns, sqlgraph.NewFieldSpec(theme.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Theme.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, theme.FieldID) for _, f := range fields { if !theme.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != theme.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(theme.FieldUUID, field.TypeString) } if value, ok := _u.mutation.UpdatedAt(); ok { _spec.SetField(theme.FieldUpdatedAt, field.TypeString, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(theme.FieldDeletedAt, field.TypeString, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(theme.FieldDeletedAt, field.TypeString) } if value, ok := _u.mutation.Key(); ok { _spec.SetField(theme.FieldKey, field.TypeString, value) } if value, ok := _u.mutation.GetType(); ok { _spec.SetField(theme.FieldType, field.TypeEnum, value) } if value, ok := _u.mutation.Colors(); ok { _spec.SetField(theme.FieldColors, field.TypeJSON, value) } if _u.mutation.ColorsCleared() { _spec.ClearField(theme.FieldColors, field.TypeJSON) } _spec.AddModifiers(_u.modifiers...) _node = &Theme{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{theme.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }