| |
|
|
| package db |
|
|
| import ( |
| "context" |
| "errors" |
| "fmt" |
| "time" |
|
|
| "entgo.io/ent/dialect" |
| "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" |
| ) |
|
|
| |
| type Example2Create struct { |
| config |
| mutation *Example2Mutation |
| hooks []Hook |
| conflict []sql.ConflictOption |
| } |
|
|
| |
| func (_c *Example2Create) SetCreatedAt(v time.Time) *Example2Create { |
| _c.mutation.SetCreatedAt(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetNillableCreatedAt(v *time.Time) *Example2Create { |
| if v != nil { |
| _c.SetCreatedAt(*v) |
| } |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetUpdatedAt(v time.Time) *Example2Create { |
| _c.mutation.SetUpdatedAt(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetNillableUpdatedAt(v *time.Time) *Example2Create { |
| if v != nil { |
| _c.SetUpdatedAt(*v) |
| } |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetDeletedAt(v time.Time) *Example2Create { |
| _c.mutation.SetDeletedAt(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetNillableDeletedAt(v *time.Time) *Example2Create { |
| if v != nil { |
| _c.SetDeletedAt(*v) |
| } |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetExampleValue2(v string) *Example2Create { |
| _c.mutation.SetExampleValue2(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) SetID(v string) *Example2Create { |
| _c.mutation.SetID(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example2Create) Mutation() *Example2Mutation { |
| return _c.mutation |
| } |
|
|
| |
| func (_c *Example2Create) Save(ctx context.Context) (*Example2, error) { |
| _c.defaults() |
| return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) |
| } |
|
|
| |
| func (_c *Example2Create) SaveX(ctx context.Context) *Example2 { |
| v, err := _c.Save(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return v |
| } |
|
|
| |
| func (_c *Example2Create) Exec(ctx context.Context) error { |
| _, err := _c.Save(ctx) |
| return err |
| } |
|
|
| |
| func (_c *Example2Create) ExecX(ctx context.Context) { |
| if err := _c.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| func (_c *Example2Create) defaults() { |
| if _, ok := _c.mutation.CreatedAt(); !ok { |
| v := example2.DefaultCreatedAt() |
| _c.mutation.SetCreatedAt(v) |
| } |
| if _, ok := _c.mutation.UpdatedAt(); !ok { |
| v := example2.DefaultUpdatedAt() |
| _c.mutation.SetUpdatedAt(v) |
| } |
| } |
|
|
| |
| func (_c *Example2Create) check() error { |
| if _, ok := _c.mutation.CreatedAt(); !ok { |
| return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Example2.created_at"`)} |
| } |
| if _, ok := _c.mutation.UpdatedAt(); !ok { |
| return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Example2.updated_at"`)} |
| } |
| if _, ok := _c.mutation.ExampleValue2(); !ok { |
| return &ValidationError{Name: "example_value_2", err: errors.New(`db: missing required field "Example2.example_value_2"`)} |
| } |
| return nil |
| } |
|
|
| func (_c *Example2Create) sqlSave(ctx context.Context) (*Example2, error) { |
| if err := _c.check(); err != nil { |
| return nil, err |
| } |
| _node, _spec := _c.createSpec() |
| if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { |
| if sqlgraph.IsConstraintError(err) { |
| err = &ConstraintError{msg: err.Error(), wrap: err} |
| } |
| return nil, err |
| } |
| if _spec.ID.Value != nil { |
| if id, ok := _spec.ID.Value.(string); ok { |
| _node.ID = id |
| } else { |
| return nil, fmt.Errorf("unexpected Example2.ID type: %T", _spec.ID.Value) |
| } |
| } |
| _c.mutation.id = &_node.ID |
| _c.mutation.done = true |
| return _node, nil |
| } |
|
|
| func (_c *Example2Create) createSpec() (*Example2, *sqlgraph.CreateSpec) { |
| var ( |
| _node = &Example2{config: _c.config} |
| _spec = sqlgraph.NewCreateSpec(example2.Table, sqlgraph.NewFieldSpec(example2.FieldID, field.TypeString)) |
| ) |
| _spec.OnConflict = _c.conflict |
| if id, ok := _c.mutation.ID(); ok { |
| _node.ID = id |
| _spec.ID.Value = id |
| } |
| if value, ok := _c.mutation.CreatedAt(); ok { |
| _spec.SetField(example2.FieldCreatedAt, field.TypeTime, value) |
| _node.CreatedAt = value |
| } |
| if value, ok := _c.mutation.UpdatedAt(); ok { |
| _spec.SetField(example2.FieldUpdatedAt, field.TypeTime, value) |
| _node.UpdatedAt = value |
| } |
| if value, ok := _c.mutation.DeletedAt(); ok { |
| _spec.SetField(example2.FieldDeletedAt, field.TypeTime, value) |
| _node.DeletedAt = &value |
| } |
| if value, ok := _c.mutation.ExampleValue2(); ok { |
| _spec.SetField(example2.FieldExampleValue2, field.TypeString, value) |
| _node.ExampleValue2 = value |
| } |
| return _node, _spec |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (_c *Example2Create) OnConflict(opts ...sql.ConflictOption) *Example2UpsertOne { |
| _c.conflict = opts |
| return &Example2UpsertOne{ |
| create: _c, |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (_c *Example2Create) OnConflictColumns(columns ...string) *Example2UpsertOne { |
| _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) |
| return &Example2UpsertOne{ |
| create: _c, |
| } |
| } |
|
|
| type ( |
| |
| |
| Example2UpsertOne struct { |
| create *Example2Create |
| } |
|
|
| |
| Example2Upsert struct { |
| *sql.UpdateSet |
| } |
| ) |
|
|
| |
| func (u *Example2Upsert) SetUpdatedAt(v time.Time) *Example2Upsert { |
| u.Set(example2.FieldUpdatedAt, v) |
| return u |
| } |
|
|
| |
| func (u *Example2Upsert) UpdateUpdatedAt() *Example2Upsert { |
| u.SetExcluded(example2.FieldUpdatedAt) |
| return u |
| } |
|
|
| |
| func (u *Example2Upsert) SetDeletedAt(v time.Time) *Example2Upsert { |
| u.Set(example2.FieldDeletedAt, v) |
| return u |
| } |
|
|
| |
| func (u *Example2Upsert) UpdateDeletedAt() *Example2Upsert { |
| u.SetExcluded(example2.FieldDeletedAt) |
| return u |
| } |
|
|
| |
| func (u *Example2Upsert) ClearDeletedAt() *Example2Upsert { |
| u.SetNull(example2.FieldDeletedAt) |
| return u |
| } |
|
|
| |
| func (u *Example2Upsert) SetExampleValue2(v string) *Example2Upsert { |
| u.Set(example2.FieldExampleValue2, v) |
| return u |
| } |
|
|
| |
| func (u *Example2Upsert) UpdateExampleValue2() *Example2Upsert { |
| u.SetExcluded(example2.FieldExampleValue2) |
| return u |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (u *Example2UpsertOne) UpdateNewValues() *Example2UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) |
| u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { |
| if _, exists := u.create.mutation.ID(); exists { |
| s.SetIgnore(example2.FieldID) |
| } |
| if _, exists := u.create.mutation.CreatedAt(); exists { |
| s.SetIgnore(example2.FieldCreatedAt) |
| } |
| })) |
| return u |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (u *Example2UpsertOne) Ignore() *Example2UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example2UpsertOne) DoNothing() *Example2UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.DoNothing()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example2UpsertOne) Update(set func(*Example2Upsert)) *Example2UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { |
| set(&Example2Upsert{UpdateSet: update}) |
| })) |
| return u |
| } |
|
|
| |
| func (u *Example2UpsertOne) SetUpdatedAt(v time.Time) *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.SetUpdatedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) UpdateUpdatedAt() *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.UpdateUpdatedAt() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) SetDeletedAt(v time.Time) *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.SetDeletedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) UpdateDeletedAt() *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.UpdateDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) ClearDeletedAt() *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.ClearDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) SetExampleValue2(v string) *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.SetExampleValue2(v) |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) UpdateExampleValue2() *Example2UpsertOne { |
| return u.Update(func(s *Example2Upsert) { |
| s.UpdateExampleValue2() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertOne) Exec(ctx context.Context) error { |
| if len(u.create.conflict) == 0 { |
| return errors.New("db: missing options for Example2Create.OnConflict") |
| } |
| return u.create.Exec(ctx) |
| } |
|
|
| |
| func (u *Example2UpsertOne) ExecX(ctx context.Context) { |
| if err := u.create.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| func (u *Example2UpsertOne) ID(ctx context.Context) (id string, err error) { |
| if u.create.driver.Dialect() == dialect.MySQL { |
| |
| |
| return id, errors.New("db: Example2UpsertOne.ID is not supported by MySQL driver. Use Example2UpsertOne.Exec instead") |
| } |
| node, err := u.create.Save(ctx) |
| if err != nil { |
| return id, err |
| } |
| return node.ID, nil |
| } |
|
|
| |
| func (u *Example2UpsertOne) IDX(ctx context.Context) string { |
| id, err := u.ID(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return id |
| } |
|
|
| |
| type Example2CreateBulk struct { |
| config |
| err error |
| builders []*Example2Create |
| conflict []sql.ConflictOption |
| } |
|
|
| |
| func (_c *Example2CreateBulk) Save(ctx context.Context) ([]*Example2, error) { |
| if _c.err != nil { |
| return nil, _c.err |
| } |
| specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) |
| nodes := make([]*Example2, len(_c.builders)) |
| mutators := make([]Mutator, len(_c.builders)) |
| for i := range _c.builders { |
| func(i int, root context.Context) { |
| builder := _c.builders[i] |
| builder.defaults() |
| var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
| mutation, ok := m.(*Example2Mutation) |
| if !ok { |
| return nil, fmt.Errorf("unexpected mutation type %T", m) |
| } |
| if err := builder.check(); err != nil { |
| return nil, err |
| } |
| builder.mutation = mutation |
| var err error |
| nodes[i], specs[i] = builder.createSpec() |
| if i < len(mutators)-1 { |
| _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) |
| } else { |
| spec := &sqlgraph.BatchCreateSpec{Nodes: specs} |
| spec.OnConflict = _c.conflict |
| |
| if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { |
| if sqlgraph.IsConstraintError(err) { |
| err = &ConstraintError{msg: err.Error(), wrap: err} |
| } |
| } |
| } |
| if err != nil { |
| return nil, err |
| } |
| mutation.id = &nodes[i].ID |
| mutation.done = true |
| return nodes[i], nil |
| }) |
| for i := len(builder.hooks) - 1; i >= 0; i-- { |
| mut = builder.hooks[i](mut) |
| } |
| mutators[i] = mut |
| }(i, ctx) |
| } |
| if len(mutators) > 0 { |
| if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { |
| return nil, err |
| } |
| } |
| return nodes, nil |
| } |
|
|
| |
| func (_c *Example2CreateBulk) SaveX(ctx context.Context) []*Example2 { |
| v, err := _c.Save(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return v |
| } |
|
|
| |
| func (_c *Example2CreateBulk) Exec(ctx context.Context) error { |
| _, err := _c.Save(ctx) |
| return err |
| } |
|
|
| |
| func (_c *Example2CreateBulk) ExecX(ctx context.Context) { |
| if err := _c.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (_c *Example2CreateBulk) OnConflict(opts ...sql.ConflictOption) *Example2UpsertBulk { |
| _c.conflict = opts |
| return &Example2UpsertBulk{ |
| create: _c, |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (_c *Example2CreateBulk) OnConflictColumns(columns ...string) *Example2UpsertBulk { |
| _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) |
| return &Example2UpsertBulk{ |
| create: _c, |
| } |
| } |
|
|
| |
| |
| type Example2UpsertBulk struct { |
| create *Example2CreateBulk |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (u *Example2UpsertBulk) UpdateNewValues() *Example2UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) |
| u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { |
| for _, b := range u.create.builders { |
| if _, exists := b.mutation.ID(); exists { |
| s.SetIgnore(example2.FieldID) |
| } |
| if _, exists := b.mutation.CreatedAt(); exists { |
| s.SetIgnore(example2.FieldCreatedAt) |
| } |
| } |
| })) |
| return u |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (u *Example2UpsertBulk) Ignore() *Example2UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example2UpsertBulk) DoNothing() *Example2UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.DoNothing()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example2UpsertBulk) Update(set func(*Example2Upsert)) *Example2UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { |
| set(&Example2Upsert{UpdateSet: update}) |
| })) |
| return u |
| } |
|
|
| |
| func (u *Example2UpsertBulk) SetUpdatedAt(v time.Time) *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.SetUpdatedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) UpdateUpdatedAt() *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.UpdateUpdatedAt() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) SetDeletedAt(v time.Time) *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.SetDeletedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) UpdateDeletedAt() *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.UpdateDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) ClearDeletedAt() *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.ClearDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) SetExampleValue2(v string) *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.SetExampleValue2(v) |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) UpdateExampleValue2() *Example2UpsertBulk { |
| return u.Update(func(s *Example2Upsert) { |
| s.UpdateExampleValue2() |
| }) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) Exec(ctx context.Context) error { |
| if u.create.err != nil { |
| return u.create.err |
| } |
| for i, b := range u.create.builders { |
| if len(b.conflict) != 0 { |
| return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the Example2CreateBulk instead", i) |
| } |
| } |
| if len(u.create.conflict) == 0 { |
| return errors.New("db: missing options for Example2CreateBulk.OnConflict") |
| } |
| return u.create.Exec(ctx) |
| } |
|
|
| |
| func (u *Example2UpsertBulk) ExecX(ctx context.Context) { |
| if err := u.create.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|