mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2026-01-04 12:04:58 +01:00
691 lines
21 KiB
Go
Generated
691 lines
21 KiB
Go
Generated
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entity"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entityfield"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate"
|
|
)
|
|
|
|
// EntityFieldUpdate is the builder for updating EntityField entities.
|
|
type EntityFieldUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *EntityFieldMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the EntityFieldUpdate builder.
|
|
func (_u *EntityFieldUpdate) Where(ps ...predicate.EntityField) *EntityFieldUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *EntityFieldUpdate) SetUpdatedAt(v time.Time) *EntityFieldUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *EntityFieldUpdate) SetName(v string) *EntityFieldUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableName(v *string) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *EntityFieldUpdate) SetDescription(v string) *EntityFieldUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableDescription(v *string) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *EntityFieldUpdate) ClearDescription() *EntityFieldUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *EntityFieldUpdate) SetType(v entityfield.Type) *EntityFieldUpdate {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableType(v *entityfield.Type) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTextValue sets the "text_value" field.
|
|
func (_u *EntityFieldUpdate) SetTextValue(v string) *EntityFieldUpdate {
|
|
_u.mutation.SetTextValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTextValue sets the "text_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableTextValue(v *string) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetTextValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTextValue clears the value of the "text_value" field.
|
|
func (_u *EntityFieldUpdate) ClearTextValue() *EntityFieldUpdate {
|
|
_u.mutation.ClearTextValue()
|
|
return _u
|
|
}
|
|
|
|
// SetNumberValue sets the "number_value" field.
|
|
func (_u *EntityFieldUpdate) SetNumberValue(v int) *EntityFieldUpdate {
|
|
_u.mutation.ResetNumberValue()
|
|
_u.mutation.SetNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNumberValue sets the "number_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableNumberValue(v *int) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetNumberValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddNumberValue adds value to the "number_value" field.
|
|
func (_u *EntityFieldUpdate) AddNumberValue(v int) *EntityFieldUpdate {
|
|
_u.mutation.AddNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearNumberValue clears the value of the "number_value" field.
|
|
func (_u *EntityFieldUpdate) ClearNumberValue() *EntityFieldUpdate {
|
|
_u.mutation.ClearNumberValue()
|
|
return _u
|
|
}
|
|
|
|
// SetBooleanValue sets the "boolean_value" field.
|
|
func (_u *EntityFieldUpdate) SetBooleanValue(v bool) *EntityFieldUpdate {
|
|
_u.mutation.SetBooleanValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableBooleanValue(v *bool) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetBooleanValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTimeValue sets the "time_value" field.
|
|
func (_u *EntityFieldUpdate) SetTimeValue(v time.Time) *EntityFieldUpdate {
|
|
_u.mutation.SetTimeValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTimeValue sets the "time_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableTimeValue(v *time.Time) *EntityFieldUpdate {
|
|
if v != nil {
|
|
_u.SetTimeValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntityID sets the "entity" edge to the Entity entity by ID.
|
|
func (_u *EntityFieldUpdate) SetEntityID(id uuid.UUID) *EntityFieldUpdate {
|
|
_u.mutation.SetEntityID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEntityID sets the "entity" edge to the Entity entity by ID if the given value is not nil.
|
|
func (_u *EntityFieldUpdate) SetNillableEntityID(id *uuid.UUID) *EntityFieldUpdate {
|
|
if id != nil {
|
|
_u = _u.SetEntityID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntity sets the "entity" edge to the Entity entity.
|
|
func (_u *EntityFieldUpdate) SetEntity(v *Entity) *EntityFieldUpdate {
|
|
return _u.SetEntityID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the EntityFieldMutation object of the builder.
|
|
func (_u *EntityFieldUpdate) Mutation() *EntityFieldMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearEntity clears the "entity" edge to the Entity entity.
|
|
func (_u *EntityFieldUpdate) ClearEntity() *EntityFieldUpdate {
|
|
_u.mutation.ClearEntity()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *EntityFieldUpdate) Save(ctx context.Context) (int, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *EntityFieldUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *EntityFieldUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *EntityFieldUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *EntityFieldUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := entityfield.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *EntityFieldUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := entityfield.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "EntityField.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := entityfield.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "EntityField.description": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := entityfield.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "EntityField.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.TextValue(); ok {
|
|
if err := entityfield.TextValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "EntityField.text_value": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *EntityFieldUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(entityfield.Table, entityfield.Columns, sqlgraph.NewFieldSpec(entityfield.FieldID, field.TypeUUID))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(entityfield.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(entityfield.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(entityfield.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(entityfield.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(entityfield.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.TextValue(); ok {
|
|
_spec.SetField(entityfield.FieldTextValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TextValueCleared() {
|
|
_spec.ClearField(entityfield.FieldTextValue, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NumberValue(); ok {
|
|
_spec.SetField(entityfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedNumberValue(); ok {
|
|
_spec.AddField(entityfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.NumberValueCleared() {
|
|
_spec.ClearField(entityfield.FieldNumberValue, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.BooleanValue(); ok {
|
|
_spec.SetField(entityfield.FieldBooleanValue, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.TimeValue(); ok {
|
|
_spec.SetField(entityfield.FieldTimeValue, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.EntityCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: entityfield.EntityTable,
|
|
Columns: []string{entityfield.EntityColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.EntityIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: entityfield.EntityTable,
|
|
Columns: []string{entityfield.EntityColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{entityfield.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// EntityFieldUpdateOne is the builder for updating a single EntityField entity.
|
|
type EntityFieldUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *EntityFieldMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *EntityFieldUpdateOne) SetUpdatedAt(v time.Time) *EntityFieldUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *EntityFieldUpdateOne) SetName(v string) *EntityFieldUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableName(v *string) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *EntityFieldUpdateOne) SetDescription(v string) *EntityFieldUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableDescription(v *string) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *EntityFieldUpdateOne) ClearDescription() *EntityFieldUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *EntityFieldUpdateOne) SetType(v entityfield.Type) *EntityFieldUpdateOne {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableType(v *entityfield.Type) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTextValue sets the "text_value" field.
|
|
func (_u *EntityFieldUpdateOne) SetTextValue(v string) *EntityFieldUpdateOne {
|
|
_u.mutation.SetTextValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTextValue sets the "text_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableTextValue(v *string) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetTextValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTextValue clears the value of the "text_value" field.
|
|
func (_u *EntityFieldUpdateOne) ClearTextValue() *EntityFieldUpdateOne {
|
|
_u.mutation.ClearTextValue()
|
|
return _u
|
|
}
|
|
|
|
// SetNumberValue sets the "number_value" field.
|
|
func (_u *EntityFieldUpdateOne) SetNumberValue(v int) *EntityFieldUpdateOne {
|
|
_u.mutation.ResetNumberValue()
|
|
_u.mutation.SetNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNumberValue sets the "number_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableNumberValue(v *int) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetNumberValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddNumberValue adds value to the "number_value" field.
|
|
func (_u *EntityFieldUpdateOne) AddNumberValue(v int) *EntityFieldUpdateOne {
|
|
_u.mutation.AddNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearNumberValue clears the value of the "number_value" field.
|
|
func (_u *EntityFieldUpdateOne) ClearNumberValue() *EntityFieldUpdateOne {
|
|
_u.mutation.ClearNumberValue()
|
|
return _u
|
|
}
|
|
|
|
// SetBooleanValue sets the "boolean_value" field.
|
|
func (_u *EntityFieldUpdateOne) SetBooleanValue(v bool) *EntityFieldUpdateOne {
|
|
_u.mutation.SetBooleanValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableBooleanValue(v *bool) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetBooleanValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTimeValue sets the "time_value" field.
|
|
func (_u *EntityFieldUpdateOne) SetTimeValue(v time.Time) *EntityFieldUpdateOne {
|
|
_u.mutation.SetTimeValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTimeValue sets the "time_value" field if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableTimeValue(v *time.Time) *EntityFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetTimeValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntityID sets the "entity" edge to the Entity entity by ID.
|
|
func (_u *EntityFieldUpdateOne) SetEntityID(id uuid.UUID) *EntityFieldUpdateOne {
|
|
_u.mutation.SetEntityID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEntityID sets the "entity" edge to the Entity entity by ID if the given value is not nil.
|
|
func (_u *EntityFieldUpdateOne) SetNillableEntityID(id *uuid.UUID) *EntityFieldUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetEntityID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntity sets the "entity" edge to the Entity entity.
|
|
func (_u *EntityFieldUpdateOne) SetEntity(v *Entity) *EntityFieldUpdateOne {
|
|
return _u.SetEntityID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the EntityFieldMutation object of the builder.
|
|
func (_u *EntityFieldUpdateOne) Mutation() *EntityFieldMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearEntity clears the "entity" edge to the Entity entity.
|
|
func (_u *EntityFieldUpdateOne) ClearEntity() *EntityFieldUpdateOne {
|
|
_u.mutation.ClearEntity()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the EntityFieldUpdate builder.
|
|
func (_u *EntityFieldUpdateOne) Where(ps ...predicate.EntityField) *EntityFieldUpdateOne {
|
|
_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 *EntityFieldUpdateOne) Select(field string, fields ...string) *EntityFieldUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated EntityField entity.
|
|
func (_u *EntityFieldUpdateOne) Save(ctx context.Context) (*EntityField, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *EntityFieldUpdateOne) SaveX(ctx context.Context) *EntityField {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *EntityFieldUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *EntityFieldUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *EntityFieldUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := entityfield.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *EntityFieldUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := entityfield.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "EntityField.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := entityfield.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "EntityField.description": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := entityfield.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "EntityField.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.TextValue(); ok {
|
|
if err := entityfield.TextValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "EntityField.text_value": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *EntityFieldUpdateOne) sqlSave(ctx context.Context) (_node *EntityField, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(entityfield.Table, entityfield.Columns, sqlgraph.NewFieldSpec(entityfield.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "EntityField.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, entityfield.FieldID)
|
|
for _, f := range fields {
|
|
if !entityfield.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != entityfield.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 value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(entityfield.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(entityfield.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(entityfield.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(entityfield.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(entityfield.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.TextValue(); ok {
|
|
_spec.SetField(entityfield.FieldTextValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TextValueCleared() {
|
|
_spec.ClearField(entityfield.FieldTextValue, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NumberValue(); ok {
|
|
_spec.SetField(entityfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedNumberValue(); ok {
|
|
_spec.AddField(entityfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.NumberValueCleared() {
|
|
_spec.ClearField(entityfield.FieldNumberValue, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.BooleanValue(); ok {
|
|
_spec.SetField(entityfield.FieldBooleanValue, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.TimeValue(); ok {
|
|
_spec.SetField(entityfield.FieldTimeValue, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.EntityCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: entityfield.EntityTable,
|
|
Columns: []string{entityfield.EntityColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.EntityIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: entityfield.EntityTable,
|
|
Columns: []string{entityfield.EntityColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &EntityField{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{entityfield.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|