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