openmeter / pkg /framework /entutils /testutils /ent2 /db /example2_update.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 9)
fea99b3 verified
Raw
History Blame Contribute Delete
8.81 kB
// 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/ent2/db/example2"
"github.com/openmeterio/openmeter/pkg/framework/entutils/testutils/ent2/db/predicate"
)
// Example2Update is the builder for updating Example2 entities.
type Example2Update struct {
config
hooks []Hook
mutation *Example2Mutation
}
// Where appends a list predicates to the Example2Update builder.
func (_u *Example2Update) Where(ps ...predicate.Example2) *Example2Update {
_u.mutation.Where(ps...)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *Example2Update) SetUpdatedAt(v time.Time) *Example2Update {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *Example2Update) SetDeletedAt(v time.Time) *Example2Update {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *Example2Update) SetNillableDeletedAt(v *time.Time) *Example2Update {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *Example2Update) ClearDeletedAt() *Example2Update {
_u.mutation.ClearDeletedAt()
return _u
}
// SetExampleValue2 sets the "example_value_2" field.
func (_u *Example2Update) SetExampleValue2(v string) *Example2Update {
_u.mutation.SetExampleValue2(v)
return _u
}
// SetNillableExampleValue2 sets the "example_value_2" field if the given value is not nil.
func (_u *Example2Update) SetNillableExampleValue2(v *string) *Example2Update {
if v != nil {
_u.SetExampleValue2(*v)
}
return _u
}
// Mutation returns the Example2Mutation object of the builder.
func (_u *Example2Update) Mutation() *Example2Mutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *Example2Update) 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 *Example2Update) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *Example2Update) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *Example2Update) 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 *Example2Update) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := example2.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *Example2Update) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(example2.Table, example2.Columns, sqlgraph.NewFieldSpec(example2.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(example2.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.DeletedAt(); ok {
_spec.SetField(example2.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(example2.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.ExampleValue2(); ok {
_spec.SetField(example2.FieldExampleValue2, field.TypeString, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{example2.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// Example2UpdateOne is the builder for updating a single Example2 entity.
type Example2UpdateOne struct {
config
fields []string
hooks []Hook
mutation *Example2Mutation
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *Example2UpdateOne) SetUpdatedAt(v time.Time) *Example2UpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *Example2UpdateOne) SetDeletedAt(v time.Time) *Example2UpdateOne {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *Example2UpdateOne) SetNillableDeletedAt(v *time.Time) *Example2UpdateOne {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *Example2UpdateOne) ClearDeletedAt() *Example2UpdateOne {
_u.mutation.ClearDeletedAt()
return _u
}
// SetExampleValue2 sets the "example_value_2" field.
func (_u *Example2UpdateOne) SetExampleValue2(v string) *Example2UpdateOne {
_u.mutation.SetExampleValue2(v)
return _u
}
// SetNillableExampleValue2 sets the "example_value_2" field if the given value is not nil.
func (_u *Example2UpdateOne) SetNillableExampleValue2(v *string) *Example2UpdateOne {
if v != nil {
_u.SetExampleValue2(*v)
}
return _u
}
// Mutation returns the Example2Mutation object of the builder.
func (_u *Example2UpdateOne) Mutation() *Example2Mutation {
return _u.mutation
}
// Where appends a list predicates to the Example2Update builder.
func (_u *Example2UpdateOne) Where(ps ...predicate.Example2) *Example2UpdateOne {
_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 *Example2UpdateOne) Select(field string, fields ...string) *Example2UpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Example2 entity.
func (_u *Example2UpdateOne) Save(ctx context.Context) (*Example2, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *Example2UpdateOne) SaveX(ctx context.Context) *Example2 {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *Example2UpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *Example2UpdateOne) 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 *Example2UpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := example2.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *Example2UpdateOne) sqlSave(ctx context.Context) (_node *Example2, err error) {
_spec := sqlgraph.NewUpdateSpec(example2.Table, example2.Columns, sqlgraph.NewFieldSpec(example2.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Example2.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, example2.FieldID)
for _, f := range fields {
if !example2.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != example2.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(example2.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.DeletedAt(); ok {
_spec.SetField(example2.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(example2.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.ExampleValue2(); ok {
_spec.SetField(example2.FieldExampleValue2, field.TypeString, value)
}
_node = &Example2{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{example2.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}