| |
|
|
| 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" |
| ) |
|
|
| |
| type Example1Update struct { |
| config |
| hooks []Hook |
| mutation *Example1Mutation |
| } |
|
|
| |
| func (_u *Example1Update) Where(ps ...predicate.Example1) *Example1Update { |
| _u.mutation.Where(ps...) |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) SetUpdatedAt(v time.Time) *Example1Update { |
| _u.mutation.SetUpdatedAt(v) |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) SetDeletedAt(v time.Time) *Example1Update { |
| _u.mutation.SetDeletedAt(v) |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) SetNillableDeletedAt(v *time.Time) *Example1Update { |
| if v != nil { |
| _u.SetDeletedAt(*v) |
| } |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) ClearDeletedAt() *Example1Update { |
| _u.mutation.ClearDeletedAt() |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) SetExampleValue1(v string) *Example1Update { |
| _u.mutation.SetExampleValue1(v) |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) SetNillableExampleValue1(v *string) *Example1Update { |
| if v != nil { |
| _u.SetExampleValue1(*v) |
| } |
| return _u |
| } |
|
|
| |
| func (_u *Example1Update) Mutation() *Example1Mutation { |
| return _u.mutation |
| } |
|
|
| |
| func (_u *Example1Update) Save(ctx context.Context) (int, error) { |
| _u.defaults() |
| return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) |
| } |
|
|
| |
| func (_u *Example1Update) SaveX(ctx context.Context) int { |
| affected, err := _u.Save(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return affected |
| } |
|
|
| |
| func (_u *Example1Update) Exec(ctx context.Context) error { |
| _, err := _u.Save(ctx) |
| return err |
| } |
|
|
| |
| func (_u *Example1Update) ExecX(ctx context.Context) { |
| if err := _u.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| 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 |
| } |
|
|
| |
| type Example1UpdateOne struct { |
| config |
| fields []string |
| hooks []Hook |
| mutation *Example1Mutation |
| } |
|
|
| |
| func (_u *Example1UpdateOne) SetUpdatedAt(v time.Time) *Example1UpdateOne { |
| _u.mutation.SetUpdatedAt(v) |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) SetDeletedAt(v time.Time) *Example1UpdateOne { |
| _u.mutation.SetDeletedAt(v) |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) SetNillableDeletedAt(v *time.Time) *Example1UpdateOne { |
| if v != nil { |
| _u.SetDeletedAt(*v) |
| } |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) ClearDeletedAt() *Example1UpdateOne { |
| _u.mutation.ClearDeletedAt() |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) SetExampleValue1(v string) *Example1UpdateOne { |
| _u.mutation.SetExampleValue1(v) |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) SetNillableExampleValue1(v *string) *Example1UpdateOne { |
| if v != nil { |
| _u.SetExampleValue1(*v) |
| } |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) Mutation() *Example1Mutation { |
| return _u.mutation |
| } |
|
|
| |
| func (_u *Example1UpdateOne) Where(ps ...predicate.Example1) *Example1UpdateOne { |
| _u.mutation.Where(ps...) |
| return _u |
| } |
|
|
| |
| |
| func (_u *Example1UpdateOne) Select(field string, fields ...string) *Example1UpdateOne { |
| _u.fields = append([]string{field}, fields...) |
| return _u |
| } |
|
|
| |
| func (_u *Example1UpdateOne) Save(ctx context.Context) (*Example1, error) { |
| _u.defaults() |
| return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) |
| } |
|
|
| |
| func (_u *Example1UpdateOne) SaveX(ctx context.Context) *Example1 { |
| node, err := _u.Save(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return node |
| } |
|
|
| |
| func (_u *Example1UpdateOne) Exec(ctx context.Context) error { |
| _, err := _u.Save(ctx) |
| return err |
| } |
|
|
| |
| func (_u *Example1UpdateOne) ExecX(ctx context.Context) { |
| if err := _u.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| 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 |
| } |
|
|