| |
|
|
| 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/ent1/db/example1" |
| ) |
|
|
| |
| type Example1Create struct { |
| config |
| mutation *Example1Mutation |
| hooks []Hook |
| conflict []sql.ConflictOption |
| } |
|
|
| |
| func (_c *Example1Create) SetCreatedAt(v time.Time) *Example1Create { |
| _c.mutation.SetCreatedAt(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetNillableCreatedAt(v *time.Time) *Example1Create { |
| if v != nil { |
| _c.SetCreatedAt(*v) |
| } |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetUpdatedAt(v time.Time) *Example1Create { |
| _c.mutation.SetUpdatedAt(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetNillableUpdatedAt(v *time.Time) *Example1Create { |
| if v != nil { |
| _c.SetUpdatedAt(*v) |
| } |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetDeletedAt(v time.Time) *Example1Create { |
| _c.mutation.SetDeletedAt(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetNillableDeletedAt(v *time.Time) *Example1Create { |
| if v != nil { |
| _c.SetDeletedAt(*v) |
| } |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetExampleValue1(v string) *Example1Create { |
| _c.mutation.SetExampleValue1(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) SetID(v string) *Example1Create { |
| _c.mutation.SetID(v) |
| return _c |
| } |
|
|
| |
| func (_c *Example1Create) Mutation() *Example1Mutation { |
| return _c.mutation |
| } |
|
|
| |
| func (_c *Example1Create) Save(ctx context.Context) (*Example1, error) { |
| _c.defaults() |
| return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) |
| } |
|
|
| |
| func (_c *Example1Create) SaveX(ctx context.Context) *Example1 { |
| v, err := _c.Save(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return v |
| } |
|
|
| |
| func (_c *Example1Create) Exec(ctx context.Context) error { |
| _, err := _c.Save(ctx) |
| return err |
| } |
|
|
| |
| func (_c *Example1Create) ExecX(ctx context.Context) { |
| if err := _c.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| func (_c *Example1Create) defaults() { |
| if _, ok := _c.mutation.CreatedAt(); !ok { |
| v := example1.DefaultCreatedAt() |
| _c.mutation.SetCreatedAt(v) |
| } |
| if _, ok := _c.mutation.UpdatedAt(); !ok { |
| v := example1.DefaultUpdatedAt() |
| _c.mutation.SetUpdatedAt(v) |
| } |
| } |
|
|
| |
| func (_c *Example1Create) check() error { |
| if _, ok := _c.mutation.CreatedAt(); !ok { |
| return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Example1.created_at"`)} |
| } |
| if _, ok := _c.mutation.UpdatedAt(); !ok { |
| return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Example1.updated_at"`)} |
| } |
| if _, ok := _c.mutation.ExampleValue1(); !ok { |
| return &ValidationError{Name: "example_value_1", err: errors.New(`db: missing required field "Example1.example_value_1"`)} |
| } |
| return nil |
| } |
|
|
| func (_c *Example1Create) sqlSave(ctx context.Context) (*Example1, 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 Example1.ID type: %T", _spec.ID.Value) |
| } |
| } |
| _c.mutation.id = &_node.ID |
| _c.mutation.done = true |
| return _node, nil |
| } |
|
|
| func (_c *Example1Create) createSpec() (*Example1, *sqlgraph.CreateSpec) { |
| var ( |
| _node = &Example1{config: _c.config} |
| _spec = sqlgraph.NewCreateSpec(example1.Table, sqlgraph.NewFieldSpec(example1.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(example1.FieldCreatedAt, field.TypeTime, value) |
| _node.CreatedAt = value |
| } |
| if value, ok := _c.mutation.UpdatedAt(); ok { |
| _spec.SetField(example1.FieldUpdatedAt, field.TypeTime, value) |
| _node.UpdatedAt = value |
| } |
| if value, ok := _c.mutation.DeletedAt(); ok { |
| _spec.SetField(example1.FieldDeletedAt, field.TypeTime, value) |
| _node.DeletedAt = &value |
| } |
| if value, ok := _c.mutation.ExampleValue1(); ok { |
| _spec.SetField(example1.FieldExampleValue1, field.TypeString, value) |
| _node.ExampleValue1 = value |
| } |
| return _node, _spec |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (_c *Example1Create) OnConflict(opts ...sql.ConflictOption) *Example1UpsertOne { |
| _c.conflict = opts |
| return &Example1UpsertOne{ |
| create: _c, |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (_c *Example1Create) OnConflictColumns(columns ...string) *Example1UpsertOne { |
| _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) |
| return &Example1UpsertOne{ |
| create: _c, |
| } |
| } |
|
|
| type ( |
| |
| |
| Example1UpsertOne struct { |
| create *Example1Create |
| } |
|
|
| |
| Example1Upsert struct { |
| *sql.UpdateSet |
| } |
| ) |
|
|
| |
| func (u *Example1Upsert) SetUpdatedAt(v time.Time) *Example1Upsert { |
| u.Set(example1.FieldUpdatedAt, v) |
| return u |
| } |
|
|
| |
| func (u *Example1Upsert) UpdateUpdatedAt() *Example1Upsert { |
| u.SetExcluded(example1.FieldUpdatedAt) |
| return u |
| } |
|
|
| |
| func (u *Example1Upsert) SetDeletedAt(v time.Time) *Example1Upsert { |
| u.Set(example1.FieldDeletedAt, v) |
| return u |
| } |
|
|
| |
| func (u *Example1Upsert) UpdateDeletedAt() *Example1Upsert { |
| u.SetExcluded(example1.FieldDeletedAt) |
| return u |
| } |
|
|
| |
| func (u *Example1Upsert) ClearDeletedAt() *Example1Upsert { |
| u.SetNull(example1.FieldDeletedAt) |
| return u |
| } |
|
|
| |
| func (u *Example1Upsert) SetExampleValue1(v string) *Example1Upsert { |
| u.Set(example1.FieldExampleValue1, v) |
| return u |
| } |
|
|
| |
| func (u *Example1Upsert) UpdateExampleValue1() *Example1Upsert { |
| u.SetExcluded(example1.FieldExampleValue1) |
| return u |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (u *Example1UpsertOne) UpdateNewValues() *Example1UpsertOne { |
| 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(example1.FieldID) |
| } |
| if _, exists := u.create.mutation.CreatedAt(); exists { |
| s.SetIgnore(example1.FieldCreatedAt) |
| } |
| })) |
| return u |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (u *Example1UpsertOne) Ignore() *Example1UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example1UpsertOne) DoNothing() *Example1UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.DoNothing()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example1UpsertOne) Update(set func(*Example1Upsert)) *Example1UpsertOne { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { |
| set(&Example1Upsert{UpdateSet: update}) |
| })) |
| return u |
| } |
|
|
| |
| func (u *Example1UpsertOne) SetUpdatedAt(v time.Time) *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.SetUpdatedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) UpdateUpdatedAt() *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.UpdateUpdatedAt() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) SetDeletedAt(v time.Time) *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.SetDeletedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) UpdateDeletedAt() *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.UpdateDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) ClearDeletedAt() *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.ClearDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) SetExampleValue1(v string) *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.SetExampleValue1(v) |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) UpdateExampleValue1() *Example1UpsertOne { |
| return u.Update(func(s *Example1Upsert) { |
| s.UpdateExampleValue1() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertOne) Exec(ctx context.Context) error { |
| if len(u.create.conflict) == 0 { |
| return errors.New("db: missing options for Example1Create.OnConflict") |
| } |
| return u.create.Exec(ctx) |
| } |
|
|
| |
| func (u *Example1UpsertOne) ExecX(ctx context.Context) { |
| if err := u.create.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| func (u *Example1UpsertOne) ID(ctx context.Context) (id string, err error) { |
| if u.create.driver.Dialect() == dialect.MySQL { |
| |
| |
| return id, errors.New("db: Example1UpsertOne.ID is not supported by MySQL driver. Use Example1UpsertOne.Exec instead") |
| } |
| node, err := u.create.Save(ctx) |
| if err != nil { |
| return id, err |
| } |
| return node.ID, nil |
| } |
|
|
| |
| func (u *Example1UpsertOne) IDX(ctx context.Context) string { |
| id, err := u.ID(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return id |
| } |
|
|
| |
| type Example1CreateBulk struct { |
| config |
| err error |
| builders []*Example1Create |
| conflict []sql.ConflictOption |
| } |
|
|
| |
| func (_c *Example1CreateBulk) Save(ctx context.Context) ([]*Example1, error) { |
| if _c.err != nil { |
| return nil, _c.err |
| } |
| specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) |
| nodes := make([]*Example1, 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.(*Example1Mutation) |
| 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 *Example1CreateBulk) SaveX(ctx context.Context) []*Example1 { |
| v, err := _c.Save(ctx) |
| if err != nil { |
| panic(err) |
| } |
| return v |
| } |
|
|
| |
| func (_c *Example1CreateBulk) Exec(ctx context.Context) error { |
| _, err := _c.Save(ctx) |
| return err |
| } |
|
|
| |
| func (_c *Example1CreateBulk) ExecX(ctx context.Context) { |
| if err := _c.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (_c *Example1CreateBulk) OnConflict(opts ...sql.ConflictOption) *Example1UpsertBulk { |
| _c.conflict = opts |
| return &Example1UpsertBulk{ |
| create: _c, |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (_c *Example1CreateBulk) OnConflictColumns(columns ...string) *Example1UpsertBulk { |
| _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) |
| return &Example1UpsertBulk{ |
| create: _c, |
| } |
| } |
|
|
| |
| |
| type Example1UpsertBulk struct { |
| create *Example1CreateBulk |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (u *Example1UpsertBulk) UpdateNewValues() *Example1UpsertBulk { |
| 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(example1.FieldID) |
| } |
| if _, exists := b.mutation.CreatedAt(); exists { |
| s.SetIgnore(example1.FieldCreatedAt) |
| } |
| } |
| })) |
| return u |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func (u *Example1UpsertBulk) Ignore() *Example1UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example1UpsertBulk) DoNothing() *Example1UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.DoNothing()) |
| return u |
| } |
|
|
| |
| |
| func (u *Example1UpsertBulk) Update(set func(*Example1Upsert)) *Example1UpsertBulk { |
| u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { |
| set(&Example1Upsert{UpdateSet: update}) |
| })) |
| return u |
| } |
|
|
| |
| func (u *Example1UpsertBulk) SetUpdatedAt(v time.Time) *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.SetUpdatedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) UpdateUpdatedAt() *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.UpdateUpdatedAt() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) SetDeletedAt(v time.Time) *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.SetDeletedAt(v) |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) UpdateDeletedAt() *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.UpdateDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) ClearDeletedAt() *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.ClearDeletedAt() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) SetExampleValue1(v string) *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.SetExampleValue1(v) |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) UpdateExampleValue1() *Example1UpsertBulk { |
| return u.Update(func(s *Example1Upsert) { |
| s.UpdateExampleValue1() |
| }) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) 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 Example1CreateBulk instead", i) |
| } |
| } |
| if len(u.create.conflict) == 0 { |
| return errors.New("db: missing options for Example1CreateBulk.OnConflict") |
| } |
| return u.create.Exec(ctx) |
| } |
|
|
| |
| func (u *Example1UpsertBulk) ExecX(ctx context.Context) { |
| if err := u.create.Exec(ctx); err != nil { |
| panic(err) |
| } |
| } |
|
|