// Code generated by ent, DO NOT EDIT. package db import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/pkg/framework/entutils/testutils/ent1/db/example1" "github.com/openmeterio/openmeter/pkg/framework/entutils/testutils/ent1/db/predicate" ) // Example1Update is the builder for updating Example1 entities. type Example1Update struct { config hooks []Hook mutation *Example1Mutation } // Where appends a list predicates to the Example1Update builder. func (_u *Example1Update) Where(ps ...predicate.Example1) *Example1Update { _u.mutation.Where(ps...) return _u } // SetUpdatedAt sets the "updated_at" field. func (_u *Example1Update) SetUpdatedAt(v time.Time) *Example1Update { _u.mutation.SetUpdatedAt(v) return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *Example1Update) SetDeletedAt(v time.Time) *Example1Update { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *Example1Update) SetNillableDeletedAt(v *time.Time) *Example1Update { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *Example1Update) ClearDeletedAt() *Example1Update { _u.mutation.ClearDeletedAt() return _u } // SetExampleValue1 sets the "example_value_1" field. func (_u *Example1Update) SetExampleValue1(v string) *Example1Update { _u.mutation.SetExampleValue1(v) return _u } // SetNillableExampleValue1 sets the "example_value_1" field if the given value is not nil. func (_u *Example1Update) SetNillableExampleValue1(v *string) *Example1Update { if v != nil { _u.SetExampleValue1(*v) } return _u } // Mutation returns the Example1Mutation object of the builder. func (_u *Example1Update) Mutation() *Example1Mutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *Example1Update) 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 *Example1Update) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *Example1Update) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *Example1Update) 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 *Example1Update) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := example1.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } func (_u *Example1Update) sqlSave(ctx context.Context) (_node int, err error) { _spec := sqlgraph.NewUpdateSpec(example1.Table, example1.Columns, sqlgraph.NewFieldSpec(example1.FieldID, field.TypeString)) 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(example1.FieldUpdatedAt, field.TypeTime, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(example1.FieldDeletedAt, field.TypeTime, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(example1.FieldDeletedAt, field.TypeTime) } if value, ok := _u.mutation.ExampleValue1(); ok { _spec.SetField(example1.FieldExampleValue1, field.TypeString, value) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{example1.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // Example1UpdateOne is the builder for updating a single Example1 entity. type Example1UpdateOne struct { config fields []string hooks []Hook mutation *Example1Mutation } // SetUpdatedAt sets the "updated_at" field. func (_u *Example1UpdateOne) SetUpdatedAt(v time.Time) *Example1UpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *Example1UpdateOne) SetDeletedAt(v time.Time) *Example1UpdateOne { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *Example1UpdateOne) SetNillableDeletedAt(v *time.Time) *Example1UpdateOne { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *Example1UpdateOne) ClearDeletedAt() *Example1UpdateOne { _u.mutation.ClearDeletedAt() return _u } // SetExampleValue1 sets the "example_value_1" field. func (_u *Example1UpdateOne) SetExampleValue1(v string) *Example1UpdateOne { _u.mutation.SetExampleValue1(v) return _u } // SetNillableExampleValue1 sets the "example_value_1" field if the given value is not nil. func (_u *Example1UpdateOne) SetNillableExampleValue1(v *string) *Example1UpdateOne { if v != nil { _u.SetExampleValue1(*v) } return _u } // Mutation returns the Example1Mutation object of the builder. func (_u *Example1UpdateOne) Mutation() *Example1Mutation { return _u.mutation } // Where appends a list predicates to the Example1Update builder. func (_u *Example1UpdateOne) Where(ps ...predicate.Example1) *Example1UpdateOne { _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 *Example1UpdateOne) Select(field string, fields ...string) *Example1UpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated Example1 entity. func (_u *Example1UpdateOne) Save(ctx context.Context) (*Example1, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *Example1UpdateOne) SaveX(ctx context.Context) *Example1 { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *Example1UpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *Example1UpdateOne) 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 *Example1UpdateOne) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := example1.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } func (_u *Example1UpdateOne) sqlSave(ctx context.Context) (_node *Example1, err error) { _spec := sqlgraph.NewUpdateSpec(example1.Table, example1.Columns, sqlgraph.NewFieldSpec(example1.FieldID, field.TypeString)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Example1.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, example1.FieldID) for _, f := range fields { if !example1.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } if f != example1.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(example1.FieldUpdatedAt, field.TypeTime, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(example1.FieldDeletedAt, field.TypeTime, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(example1.FieldDeletedAt, field.TypeTime) } if value, ok := _u.mutation.ExampleValue1(); ok { _spec.SetField(example1.FieldExampleValue1, field.TypeString, value) } _node = &Example1{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{example1.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }