631 lines
19 KiB
Go
631 lines
19 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_wms/ent/materialdemand"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// MaterialDemandCreate is the builder for creating a MaterialDemand entity.
|
||
|
|
type MaterialDemandCreate struct {
|
||
|
|
config
|
||
|
|
mutation *MaterialDemandMutation
|
||
|
|
hooks []Hook
|
||
|
|
conflict []sql.ConflictOption
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMaterialCode sets the "material_code" field.
|
||
|
|
func (_c *MaterialDemandCreate) SetMaterialCode(v string) *MaterialDemandCreate {
|
||
|
|
_c.mutation.SetMaterialCode(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetFuture5Qty sets the "future5_qty" field.
|
||
|
|
func (_c *MaterialDemandCreate) SetFuture5Qty(v int) *MaterialDemandCreate {
|
||
|
|
_c.mutation.SetFuture5Qty(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableFuture5Qty sets the "future5_qty" field if the given value is not nil.
|
||
|
|
func (_c *MaterialDemandCreate) SetNillableFuture5Qty(v *int) *MaterialDemandCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetFuture5Qty(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (_c *MaterialDemandCreate) SetUpdatedAt(v int64) *MaterialDemandCreate {
|
||
|
|
_c.mutation.SetUpdatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||
|
|
func (_c *MaterialDemandCreate) SetNillableUpdatedAt(v *int64) *MaterialDemandCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetUpdatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the MaterialDemandMutation object of the builder.
|
||
|
|
func (_c *MaterialDemandCreate) Mutation() *MaterialDemandMutation {
|
||
|
|
return _c.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the MaterialDemand in the database.
|
||
|
|
func (_c *MaterialDemandCreate) Save(ctx context.Context) (*MaterialDemand, error) {
|
||
|
|
_c.defaults()
|
||
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
|
func (_c *MaterialDemandCreate) SaveX(ctx context.Context) *MaterialDemand {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *MaterialDemandCreate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *MaterialDemandCreate) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// defaults sets the default values of the builder before save.
|
||
|
|
func (_c *MaterialDemandCreate) defaults() {
|
||
|
|
if _, ok := _c.mutation.Future5Qty(); !ok {
|
||
|
|
v := materialdemand.DefaultFuture5Qty
|
||
|
|
_c.mutation.SetFuture5Qty(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||
|
|
v := materialdemand.DefaultUpdatedAt()
|
||
|
|
_c.mutation.SetUpdatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_c *MaterialDemandCreate) check() error {
|
||
|
|
if _, ok := _c.mutation.MaterialCode(); !ok {
|
||
|
|
return &ValidationError{Name: "material_code", err: errors.New(`ent: missing required field "MaterialDemand.material_code"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Future5Qty(); !ok {
|
||
|
|
return &ValidationError{Name: "future5_qty", err: errors.New(`ent: missing required field "MaterialDemand.future5_qty"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "MaterialDemand.updated_at"`)}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *MaterialDemandCreate) sqlSave(ctx context.Context) (*MaterialDemand, 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
|
||
|
|
}
|
||
|
|
id := _spec.ID.Value.(int64)
|
||
|
|
_node.ID = int(id)
|
||
|
|
_c.mutation.id = &_node.ID
|
||
|
|
_c.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *MaterialDemandCreate) createSpec() (*MaterialDemand, *sqlgraph.CreateSpec) {
|
||
|
|
var (
|
||
|
|
_node = &MaterialDemand{config: _c.config}
|
||
|
|
_spec = sqlgraph.NewCreateSpec(materialdemand.Table, sqlgraph.NewFieldSpec(materialdemand.FieldID, field.TypeInt))
|
||
|
|
)
|
||
|
|
_spec.OnConflict = _c.conflict
|
||
|
|
if value, ok := _c.mutation.MaterialCode(); ok {
|
||
|
|
_spec.SetField(materialdemand.FieldMaterialCode, field.TypeString, value)
|
||
|
|
_node.MaterialCode = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Future5Qty(); ok {
|
||
|
|
_spec.SetField(materialdemand.FieldFuture5Qty, field.TypeInt, value)
|
||
|
|
_node.Future5Qty = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(materialdemand.FieldUpdatedAt, field.TypeInt64, value)
|
||
|
|
_node.UpdatedAt = value
|
||
|
|
}
|
||
|
|
return _node, _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||
|
|
// of the `INSERT` statement. For example:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// SetMaterialCode(v).
|
||
|
|
// OnConflict(
|
||
|
|
// // Update the row with the new values
|
||
|
|
// // the was proposed for insertion.
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// // Override some of the fields with custom
|
||
|
|
// // update values.
|
||
|
|
// Update(func(u *ent.MaterialDemandUpsert) {
|
||
|
|
// SetMaterialCode(v+v).
|
||
|
|
// }).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *MaterialDemandCreate) OnConflict(opts ...sql.ConflictOption) *MaterialDemandUpsertOne {
|
||
|
|
_c.conflict = opts
|
||
|
|
return &MaterialDemandUpsertOne{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||
|
|
// as conflict target. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *MaterialDemandCreate) OnConflictColumns(columns ...string) *MaterialDemandUpsertOne {
|
||
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||
|
|
return &MaterialDemandUpsertOne{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type (
|
||
|
|
// MaterialDemandUpsertOne is the builder for "upsert"-ing
|
||
|
|
// one MaterialDemand node.
|
||
|
|
MaterialDemandUpsertOne struct {
|
||
|
|
create *MaterialDemandCreate
|
||
|
|
}
|
||
|
|
|
||
|
|
// MaterialDemandUpsert is the "OnConflict" setter.
|
||
|
|
MaterialDemandUpsert struct {
|
||
|
|
*sql.UpdateSet
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
// SetMaterialCode sets the "material_code" field.
|
||
|
|
func (u *MaterialDemandUpsert) SetMaterialCode(v string) *MaterialDemandUpsert {
|
||
|
|
u.Set(materialdemand.FieldMaterialCode, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsert) UpdateMaterialCode() *MaterialDemandUpsert {
|
||
|
|
u.SetExcluded(materialdemand.FieldMaterialCode)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetFuture5Qty sets the "future5_qty" field.
|
||
|
|
func (u *MaterialDemandUpsert) SetFuture5Qty(v int) *MaterialDemandUpsert {
|
||
|
|
u.Set(materialdemand.FieldFuture5Qty, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateFuture5Qty sets the "future5_qty" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsert) UpdateFuture5Qty() *MaterialDemandUpsert {
|
||
|
|
u.SetExcluded(materialdemand.FieldFuture5Qty)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddFuture5Qty adds v to the "future5_qty" field.
|
||
|
|
func (u *MaterialDemandUpsert) AddFuture5Qty(v int) *MaterialDemandUpsert {
|
||
|
|
u.Add(materialdemand.FieldFuture5Qty, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (u *MaterialDemandUpsert) SetUpdatedAt(v int64) *MaterialDemandUpsert {
|
||
|
|
u.Set(materialdemand.FieldUpdatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsert) UpdateUpdatedAt() *MaterialDemandUpsert {
|
||
|
|
u.SetExcluded(materialdemand.FieldUpdatedAt)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
||
|
|
func (u *MaterialDemandUpsert) AddUpdatedAt(v int64) *MaterialDemandUpsert {
|
||
|
|
u.Add(materialdemand.FieldUpdatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// OnConflict(
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *MaterialDemandUpsertOne) UpdateNewValues() *MaterialDemandUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Ignore sets each column to itself in case of conflict.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *MaterialDemandUpsertOne) Ignore() *MaterialDemandUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||
|
|
// Supported only by SQLite and PostgreSQL.
|
||
|
|
func (u *MaterialDemandUpsertOne) DoNothing() *MaterialDemandUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update allows overriding fields `UPDATE` values. See the MaterialDemandCreate.OnConflict
|
||
|
|
// documentation for more info.
|
||
|
|
func (u *MaterialDemandUpsertOne) Update(set func(*MaterialDemandUpsert)) *MaterialDemandUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||
|
|
set(&MaterialDemandUpsert{UpdateSet: update})
|
||
|
|
}))
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMaterialCode sets the "material_code" field.
|
||
|
|
func (u *MaterialDemandUpsertOne) SetMaterialCode(v string) *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.SetMaterialCode(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsertOne) UpdateMaterialCode() *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.UpdateMaterialCode()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetFuture5Qty sets the "future5_qty" field.
|
||
|
|
func (u *MaterialDemandUpsertOne) SetFuture5Qty(v int) *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.SetFuture5Qty(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddFuture5Qty adds v to the "future5_qty" field.
|
||
|
|
func (u *MaterialDemandUpsertOne) AddFuture5Qty(v int) *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.AddFuture5Qty(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateFuture5Qty sets the "future5_qty" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsertOne) UpdateFuture5Qty() *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.UpdateFuture5Qty()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (u *MaterialDemandUpsertOne) SetUpdatedAt(v int64) *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.SetUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
||
|
|
func (u *MaterialDemandUpsertOne) AddUpdatedAt(v int64) *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.AddUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsertOne) UpdateUpdatedAt() *MaterialDemandUpsertOne {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.UpdateUpdatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (u *MaterialDemandUpsertOne) Exec(ctx context.Context) error {
|
||
|
|
if len(u.create.conflict) == 0 {
|
||
|
|
return errors.New("ent: missing options for MaterialDemandCreate.OnConflict")
|
||
|
|
}
|
||
|
|
return u.create.Exec(ctx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (u *MaterialDemandUpsertOne) ExecX(ctx context.Context) {
|
||
|
|
if err := u.create.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||
|
|
func (u *MaterialDemandUpsertOne) ID(ctx context.Context) (id int, err error) {
|
||
|
|
node, err := u.create.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
return id, err
|
||
|
|
}
|
||
|
|
return node.ID, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// IDX is like ID, but panics if an error occurs.
|
||
|
|
func (u *MaterialDemandUpsertOne) IDX(ctx context.Context) int {
|
||
|
|
id, err := u.ID(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
|
||
|
|
// MaterialDemandCreateBulk is the builder for creating many MaterialDemand entities in bulk.
|
||
|
|
type MaterialDemandCreateBulk struct {
|
||
|
|
config
|
||
|
|
err error
|
||
|
|
builders []*MaterialDemandCreate
|
||
|
|
conflict []sql.ConflictOption
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the MaterialDemand entities in the database.
|
||
|
|
func (_c *MaterialDemandCreateBulk) Save(ctx context.Context) ([]*MaterialDemand, error) {
|
||
|
|
if _c.err != nil {
|
||
|
|
return nil, _c.err
|
||
|
|
}
|
||
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||
|
|
nodes := make([]*MaterialDemand, 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.(*MaterialDemandMutation)
|
||
|
|
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
|
||
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
||
|
|
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
|
||
|
|
if specs[i].ID.Value != nil {
|
||
|
|
id := specs[i].ID.Value.(int64)
|
||
|
|
nodes[i].ID = int(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
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_c *MaterialDemandCreateBulk) SaveX(ctx context.Context) []*MaterialDemand {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *MaterialDemandCreateBulk) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *MaterialDemandCreateBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||
|
|
// of the `INSERT` statement. For example:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.CreateBulk(builders...).
|
||
|
|
// OnConflict(
|
||
|
|
// // Update the row with the new values
|
||
|
|
// // the was proposed for insertion.
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// // Override some of the fields with custom
|
||
|
|
// // update values.
|
||
|
|
// Update(func(u *ent.MaterialDemandUpsert) {
|
||
|
|
// SetMaterialCode(v+v).
|
||
|
|
// }).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *MaterialDemandCreateBulk) OnConflict(opts ...sql.ConflictOption) *MaterialDemandUpsertBulk {
|
||
|
|
_c.conflict = opts
|
||
|
|
return &MaterialDemandUpsertBulk{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||
|
|
// as conflict target. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *MaterialDemandCreateBulk) OnConflictColumns(columns ...string) *MaterialDemandUpsertBulk {
|
||
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||
|
|
return &MaterialDemandUpsertBulk{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// MaterialDemandUpsertBulk is the builder for "upsert"-ing
|
||
|
|
// a bulk of MaterialDemand nodes.
|
||
|
|
type MaterialDemandUpsertBulk struct {
|
||
|
|
create *MaterialDemandCreateBulk
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
||
|
|
// were set on create. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// OnConflict(
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *MaterialDemandUpsertBulk) UpdateNewValues() *MaterialDemandUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Ignore sets each column to itself in case of conflict.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.MaterialDemand.Create().
|
||
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *MaterialDemandUpsertBulk) Ignore() *MaterialDemandUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||
|
|
// Supported only by SQLite and PostgreSQL.
|
||
|
|
func (u *MaterialDemandUpsertBulk) DoNothing() *MaterialDemandUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update allows overriding fields `UPDATE` values. See the MaterialDemandCreateBulk.OnConflict
|
||
|
|
// documentation for more info.
|
||
|
|
func (u *MaterialDemandUpsertBulk) Update(set func(*MaterialDemandUpsert)) *MaterialDemandUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||
|
|
set(&MaterialDemandUpsert{UpdateSet: update})
|
||
|
|
}))
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMaterialCode sets the "material_code" field.
|
||
|
|
func (u *MaterialDemandUpsertBulk) SetMaterialCode(v string) *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.SetMaterialCode(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsertBulk) UpdateMaterialCode() *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.UpdateMaterialCode()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetFuture5Qty sets the "future5_qty" field.
|
||
|
|
func (u *MaterialDemandUpsertBulk) SetFuture5Qty(v int) *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.SetFuture5Qty(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddFuture5Qty adds v to the "future5_qty" field.
|
||
|
|
func (u *MaterialDemandUpsertBulk) AddFuture5Qty(v int) *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.AddFuture5Qty(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateFuture5Qty sets the "future5_qty" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsertBulk) UpdateFuture5Qty() *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.UpdateFuture5Qty()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (u *MaterialDemandUpsertBulk) SetUpdatedAt(v int64) *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.SetUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
||
|
|
func (u *MaterialDemandUpsertBulk) AddUpdatedAt(v int64) *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.AddUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||
|
|
func (u *MaterialDemandUpsertBulk) UpdateUpdatedAt() *MaterialDemandUpsertBulk {
|
||
|
|
return u.Update(func(s *MaterialDemandUpsert) {
|
||
|
|
s.UpdateUpdatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (u *MaterialDemandUpsertBulk) 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("ent: OnConflict was set for builder %d. Set it on the MaterialDemandCreateBulk instead", i)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(u.create.conflict) == 0 {
|
||
|
|
return errors.New("ent: missing options for MaterialDemandCreateBulk.OnConflict")
|
||
|
|
}
|
||
|
|
return u.create.Exec(ctx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (u *MaterialDemandUpsertBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := u.create.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|