mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-23 15:26:31 +00:00
595 lines
17 KiB
Go
595 lines
17 KiB
Go
|
// 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/hay-kot/homebox/backend/internal/data/ent/item"
|
||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||
|
)
|
||
|
|
||
|
// MaintenanceEntryUpdate is the builder for updating MaintenanceEntry entities.
|
||
|
type MaintenanceEntryUpdate struct {
|
||
|
config
|
||
|
hooks []Hook
|
||
|
mutation *MaintenanceEntryMutation
|
||
|
}
|
||
|
|
||
|
// Where appends a list predicates to the MaintenanceEntryUpdate builder.
|
||
|
func (meu *MaintenanceEntryUpdate) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.Where(ps...)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (meu *MaintenanceEntryUpdate) SetUpdatedAt(t time.Time) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.SetUpdatedAt(t)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetItemID sets the "item_id" field.
|
||
|
func (meu *MaintenanceEntryUpdate) SetItemID(u uuid.UUID) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.SetItemID(u)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetDate sets the "date" field.
|
||
|
func (meu *MaintenanceEntryUpdate) SetDate(t time.Time) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.SetDate(t)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
||
|
func (meu *MaintenanceEntryUpdate) SetNillableDate(t *time.Time) *MaintenanceEntryUpdate {
|
||
|
if t != nil {
|
||
|
meu.SetDate(*t)
|
||
|
}
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetName sets the "name" field.
|
||
|
func (meu *MaintenanceEntryUpdate) SetName(s string) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.SetName(s)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetDescription sets the "description" field.
|
||
|
func (meu *MaintenanceEntryUpdate) SetDescription(s string) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.SetDescription(s)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||
|
func (meu *MaintenanceEntryUpdate) SetNillableDescription(s *string) *MaintenanceEntryUpdate {
|
||
|
if s != nil {
|
||
|
meu.SetDescription(*s)
|
||
|
}
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// ClearDescription clears the value of the "description" field.
|
||
|
func (meu *MaintenanceEntryUpdate) ClearDescription() *MaintenanceEntryUpdate {
|
||
|
meu.mutation.ClearDescription()
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetCost sets the "cost" field.
|
||
|
func (meu *MaintenanceEntryUpdate) SetCost(f float64) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.ResetCost()
|
||
|
meu.mutation.SetCost(f)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
||
|
func (meu *MaintenanceEntryUpdate) SetNillableCost(f *float64) *MaintenanceEntryUpdate {
|
||
|
if f != nil {
|
||
|
meu.SetCost(*f)
|
||
|
}
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// AddCost adds f to the "cost" field.
|
||
|
func (meu *MaintenanceEntryUpdate) AddCost(f float64) *MaintenanceEntryUpdate {
|
||
|
meu.mutation.AddCost(f)
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// SetItem sets the "item" edge to the Item entity.
|
||
|
func (meu *MaintenanceEntryUpdate) SetItem(i *Item) *MaintenanceEntryUpdate {
|
||
|
return meu.SetItemID(i.ID)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
||
|
func (meu *MaintenanceEntryUpdate) Mutation() *MaintenanceEntryMutation {
|
||
|
return meu.mutation
|
||
|
}
|
||
|
|
||
|
// ClearItem clears the "item" edge to the Item entity.
|
||
|
func (meu *MaintenanceEntryUpdate) ClearItem() *MaintenanceEntryUpdate {
|
||
|
meu.mutation.ClearItem()
|
||
|
return meu
|
||
|
}
|
||
|
|
||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||
|
func (meu *MaintenanceEntryUpdate) Save(ctx context.Context) (int, error) {
|
||
|
var (
|
||
|
err error
|
||
|
affected int
|
||
|
)
|
||
|
meu.defaults()
|
||
|
if len(meu.hooks) == 0 {
|
||
|
if err = meu.check(); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
affected, err = meu.sqlSave(ctx)
|
||
|
} else {
|
||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||
|
if !ok {
|
||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||
|
}
|
||
|
if err = meu.check(); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
meu.mutation = mutation
|
||
|
affected, err = meu.sqlSave(ctx)
|
||
|
mutation.done = true
|
||
|
return affected, err
|
||
|
})
|
||
|
for i := len(meu.hooks) - 1; i >= 0; i-- {
|
||
|
if meu.hooks[i] == nil {
|
||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||
|
}
|
||
|
mut = meu.hooks[i](mut)
|
||
|
}
|
||
|
if _, err := mut.Mutate(ctx, meu.mutation); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
}
|
||
|
return affected, err
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (meu *MaintenanceEntryUpdate) SaveX(ctx context.Context) int {
|
||
|
affected, err := meu.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return affected
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (meu *MaintenanceEntryUpdate) Exec(ctx context.Context) error {
|
||
|
_, err := meu.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (meu *MaintenanceEntryUpdate) ExecX(ctx context.Context) {
|
||
|
if err := meu.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (meu *MaintenanceEntryUpdate) defaults() {
|
||
|
if _, ok := meu.mutation.UpdatedAt(); !ok {
|
||
|
v := maintenanceentry.UpdateDefaultUpdatedAt()
|
||
|
meu.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (meu *MaintenanceEntryUpdate) check() error {
|
||
|
if v, ok := meu.mutation.Name(); ok {
|
||
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if v, ok := meu.mutation.Description(); ok {
|
||
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if _, ok := meu.mutation.ItemID(); meu.mutation.ItemCleared() && !ok {
|
||
|
return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (meu *MaintenanceEntryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||
|
_spec := &sqlgraph.UpdateSpec{
|
||
|
Node: &sqlgraph.NodeSpec{
|
||
|
Table: maintenanceentry.Table,
|
||
|
Columns: maintenanceentry.Columns,
|
||
|
ID: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: maintenanceentry.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
if ps := meu.mutation.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if value, ok := meu.mutation.UpdatedAt(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
||
|
}
|
||
|
if value, ok := meu.mutation.Date(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
||
|
}
|
||
|
if value, ok := meu.mutation.Name(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
||
|
}
|
||
|
if value, ok := meu.mutation.Description(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
||
|
}
|
||
|
if meu.mutation.DescriptionCleared() {
|
||
|
_spec.ClearField(maintenanceentry.FieldDescription, field.TypeString)
|
||
|
}
|
||
|
if value, ok := meu.mutation.Cost(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||
|
}
|
||
|
if value, ok := meu.mutation.AddedCost(); ok {
|
||
|
_spec.AddField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||
|
}
|
||
|
if meu.mutation.ItemCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: maintenanceentry.ItemTable,
|
||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := meu.mutation.ItemIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: maintenanceentry.ItemTable,
|
||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if n, err = sqlgraph.UpdateNodes(ctx, meu.driver, _spec); err != nil {
|
||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
err = &NotFoundError{maintenanceentry.Label}
|
||
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
}
|
||
|
return 0, err
|
||
|
}
|
||
|
return n, nil
|
||
|
}
|
||
|
|
||
|
// MaintenanceEntryUpdateOne is the builder for updating a single MaintenanceEntry entity.
|
||
|
type MaintenanceEntryUpdateOne struct {
|
||
|
config
|
||
|
fields []string
|
||
|
hooks []Hook
|
||
|
mutation *MaintenanceEntryMutation
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetUpdatedAt(t time.Time) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.SetUpdatedAt(t)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetItemID sets the "item_id" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetItemID(u uuid.UUID) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.SetItemID(u)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetDate sets the "date" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetDate(t time.Time) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.SetDate(t)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetNillableDate(t *time.Time) *MaintenanceEntryUpdateOne {
|
||
|
if t != nil {
|
||
|
meuo.SetDate(*t)
|
||
|
}
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetName sets the "name" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetName(s string) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.SetName(s)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetDescription sets the "description" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetDescription(s string) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.SetDescription(s)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetNillableDescription(s *string) *MaintenanceEntryUpdateOne {
|
||
|
if s != nil {
|
||
|
meuo.SetDescription(*s)
|
||
|
}
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// ClearDescription clears the value of the "description" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) ClearDescription() *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.ClearDescription()
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetCost sets the "cost" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetCost(f float64) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.ResetCost()
|
||
|
meuo.mutation.SetCost(f)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetNillableCost(f *float64) *MaintenanceEntryUpdateOne {
|
||
|
if f != nil {
|
||
|
meuo.SetCost(*f)
|
||
|
}
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// AddCost adds f to the "cost" field.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) AddCost(f float64) *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.AddCost(f)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// SetItem sets the "item" edge to the Item entity.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SetItem(i *Item) *MaintenanceEntryUpdateOne {
|
||
|
return meuo.SetItemID(i.ID)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) Mutation() *MaintenanceEntryMutation {
|
||
|
return meuo.mutation
|
||
|
}
|
||
|
|
||
|
// ClearItem clears the "item" edge to the Item entity.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) ClearItem() *MaintenanceEntryUpdateOne {
|
||
|
meuo.mutation.ClearItem()
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||
|
// The default is selecting all fields defined in the entity schema.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) Select(field string, fields ...string) *MaintenanceEntryUpdateOne {
|
||
|
meuo.fields = append([]string{field}, fields...)
|
||
|
return meuo
|
||
|
}
|
||
|
|
||
|
// Save executes the query and returns the updated MaintenanceEntry entity.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) Save(ctx context.Context) (*MaintenanceEntry, error) {
|
||
|
var (
|
||
|
err error
|
||
|
node *MaintenanceEntry
|
||
|
)
|
||
|
meuo.defaults()
|
||
|
if len(meuo.hooks) == 0 {
|
||
|
if err = meuo.check(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
node, err = meuo.sqlSave(ctx)
|
||
|
} else {
|
||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||
|
if !ok {
|
||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||
|
}
|
||
|
if err = meuo.check(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
meuo.mutation = mutation
|
||
|
node, err = meuo.sqlSave(ctx)
|
||
|
mutation.done = true
|
||
|
return node, err
|
||
|
})
|
||
|
for i := len(meuo.hooks) - 1; i >= 0; i-- {
|
||
|
if meuo.hooks[i] == nil {
|
||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||
|
}
|
||
|
mut = meuo.hooks[i](mut)
|
||
|
}
|
||
|
v, err := mut.Mutate(ctx, meuo.mutation)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
nv, ok := v.(*MaintenanceEntry)
|
||
|
if !ok {
|
||
|
return nil, fmt.Errorf("unexpected node type %T returned from MaintenanceEntryMutation", v)
|
||
|
}
|
||
|
node = nv
|
||
|
}
|
||
|
return node, err
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) SaveX(ctx context.Context) *MaintenanceEntry {
|
||
|
node, err := meuo.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// Exec executes the query on the entity.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) Exec(ctx context.Context) error {
|
||
|
_, err := meuo.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) ExecX(ctx context.Context) {
|
||
|
if err := meuo.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) defaults() {
|
||
|
if _, ok := meuo.mutation.UpdatedAt(); !ok {
|
||
|
v := maintenanceentry.UpdateDefaultUpdatedAt()
|
||
|
meuo.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (meuo *MaintenanceEntryUpdateOne) check() error {
|
||
|
if v, ok := meuo.mutation.Name(); ok {
|
||
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if v, ok := meuo.mutation.Description(); ok {
|
||
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if _, ok := meuo.mutation.ItemID(); meuo.mutation.ItemCleared() && !ok {
|
||
|
return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (meuo *MaintenanceEntryUpdateOne) sqlSave(ctx context.Context) (_node *MaintenanceEntry, err error) {
|
||
|
_spec := &sqlgraph.UpdateSpec{
|
||
|
Node: &sqlgraph.NodeSpec{
|
||
|
Table: maintenanceentry.Table,
|
||
|
Columns: maintenanceentry.Columns,
|
||
|
ID: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: maintenanceentry.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
id, ok := meuo.mutation.ID()
|
||
|
if !ok {
|
||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MaintenanceEntry.id" for update`)}
|
||
|
}
|
||
|
_spec.Node.ID.Value = id
|
||
|
if fields := meuo.fields; len(fields) > 0 {
|
||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, maintenanceentry.FieldID)
|
||
|
for _, f := range fields {
|
||
|
if !maintenanceentry.ValidColumn(f) {
|
||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
}
|
||
|
if f != maintenanceentry.FieldID {
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if ps := meuo.mutation.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if value, ok := meuo.mutation.UpdatedAt(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
||
|
}
|
||
|
if value, ok := meuo.mutation.Date(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
||
|
}
|
||
|
if value, ok := meuo.mutation.Name(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
||
|
}
|
||
|
if value, ok := meuo.mutation.Description(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
||
|
}
|
||
|
if meuo.mutation.DescriptionCleared() {
|
||
|
_spec.ClearField(maintenanceentry.FieldDescription, field.TypeString)
|
||
|
}
|
||
|
if value, ok := meuo.mutation.Cost(); ok {
|
||
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||
|
}
|
||
|
if value, ok := meuo.mutation.AddedCost(); ok {
|
||
|
_spec.AddField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||
|
}
|
||
|
if meuo.mutation.ItemCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: maintenanceentry.ItemTable,
|
||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := meuo.mutation.ItemIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: maintenanceentry.ItemTable,
|
||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
_node = &MaintenanceEntry{config: meuo.config}
|
||
|
_spec.Assign = _node.assignValues
|
||
|
_spec.ScanValues = _node.scanValues
|
||
|
if err = sqlgraph.UpdateNode(ctx, meuo.driver, _spec); err != nil {
|
||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
err = &NotFoundError{maintenanceentry.Label}
|
||
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
return _node, nil
|
||
|
}
|