872 lines
26 KiB
Go
872 lines
26 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/stocktakeorder"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// StocktakeOrderCreate is the builder for creating a StocktakeOrder entity.
|
|
type StocktakeOrderCreate struct {
|
|
config
|
|
mutation *StocktakeOrderMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetStocktakeNo sets the "stocktake_no" field.
|
|
func (_c *StocktakeOrderCreate) SetStocktakeNo(v string) *StocktakeOrderCreate {
|
|
_c.mutation.SetStocktakeNo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *StocktakeOrderCreate) SetStatus(v string) *StocktakeOrderCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_c *StocktakeOrderCreate) SetNillableStatus(v *string) *StocktakeOrderCreate {
|
|
if v != nil {
|
|
_c.SetStatus(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_c *StocktakeOrderCreate) SetOperator(v string) *StocktakeOrderCreate {
|
|
_c.mutation.SetOperator(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_c *StocktakeOrderCreate) SetNillableOperator(v *string) *StocktakeOrderCreate {
|
|
if v != nil {
|
|
_c.SetOperator(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetTotalTargets sets the "total_targets" field.
|
|
func (_c *StocktakeOrderCreate) SetTotalTargets(v int) *StocktakeOrderCreate {
|
|
_c.mutation.SetTotalTargets(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableTotalTargets sets the "total_targets" field if the given value is not nil.
|
|
func (_c *StocktakeOrderCreate) SetNillableTotalTargets(v *int) *StocktakeOrderCreate {
|
|
if v != nil {
|
|
_c.SetTotalTargets(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *StocktakeOrderCreate) SetCreatedAt(v int64) *StocktakeOrderCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *StocktakeOrderCreate) SetNillableCreatedAt(v *int64) *StocktakeOrderCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetFinishedAt sets the "finished_at" field.
|
|
func (_c *StocktakeOrderCreate) SetFinishedAt(v int64) *StocktakeOrderCreate {
|
|
_c.mutation.SetFinishedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
|
|
func (_c *StocktakeOrderCreate) SetNillableFinishedAt(v *int64) *StocktakeOrderCreate {
|
|
if v != nil {
|
|
_c.SetFinishedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the StocktakeOrderMutation object of the builder.
|
|
func (_c *StocktakeOrderCreate) Mutation() *StocktakeOrderMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the StocktakeOrder in the database.
|
|
func (_c *StocktakeOrderCreate) Save(ctx context.Context) (*StocktakeOrder, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *StocktakeOrderCreate) SaveX(ctx context.Context) *StocktakeOrder {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *StocktakeOrderCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *StocktakeOrderCreate) 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 *StocktakeOrderCreate) defaults() {
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
v := stocktakeorder.DefaultStatus
|
|
_c.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := _c.mutation.TotalTargets(); !ok {
|
|
v := stocktakeorder.DefaultTotalTargets
|
|
_c.mutation.SetTotalTargets(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := stocktakeorder.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *StocktakeOrderCreate) check() error {
|
|
if _, ok := _c.mutation.StocktakeNo(); !ok {
|
|
return &ValidationError{Name: "stocktake_no", err: errors.New(`ent: missing required field "StocktakeOrder.stocktake_no"`)}
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "StocktakeOrder.status"`)}
|
|
}
|
|
if _, ok := _c.mutation.TotalTargets(); !ok {
|
|
return &ValidationError{Name: "total_targets", err: errors.New(`ent: missing required field "StocktakeOrder.total_targets"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "StocktakeOrder.created_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *StocktakeOrderCreate) sqlSave(ctx context.Context) (*StocktakeOrder, 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 *StocktakeOrderCreate) createSpec() (*StocktakeOrder, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &StocktakeOrder{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(stocktakeorder.Table, sqlgraph.NewFieldSpec(stocktakeorder.FieldID, field.TypeInt))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.StocktakeNo(); ok {
|
|
_spec.SetField(stocktakeorder.FieldStocktakeNo, field.TypeString, value)
|
|
_node.StocktakeNo = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(stocktakeorder.FieldStatus, field.TypeString, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.Operator(); ok {
|
|
_spec.SetField(stocktakeorder.FieldOperator, field.TypeString, value)
|
|
_node.Operator = value
|
|
}
|
|
if value, ok := _c.mutation.TotalTargets(); ok {
|
|
_spec.SetField(stocktakeorder.FieldTotalTargets, field.TypeInt, value)
|
|
_node.TotalTargets = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(stocktakeorder.FieldCreatedAt, field.TypeInt64, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.FinishedAt(); ok {
|
|
_spec.SetField(stocktakeorder.FieldFinishedAt, field.TypeInt64, value)
|
|
_node.FinishedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.StocktakeOrder.Create().
|
|
// SetStocktakeNo(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.StocktakeOrderUpsert) {
|
|
// SetStocktakeNo(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *StocktakeOrderCreate) OnConflict(opts ...sql.ConflictOption) *StocktakeOrderUpsertOne {
|
|
_c.conflict = opts
|
|
return &StocktakeOrderUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.StocktakeOrder.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *StocktakeOrderCreate) OnConflictColumns(columns ...string) *StocktakeOrderUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &StocktakeOrderUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// StocktakeOrderUpsertOne is the builder for "upsert"-ing
|
|
// one StocktakeOrder node.
|
|
StocktakeOrderUpsertOne struct {
|
|
create *StocktakeOrderCreate
|
|
}
|
|
|
|
// StocktakeOrderUpsert is the "OnConflict" setter.
|
|
StocktakeOrderUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetStocktakeNo sets the "stocktake_no" field.
|
|
func (u *StocktakeOrderUpsert) SetStocktakeNo(v string) *StocktakeOrderUpsert {
|
|
u.Set(stocktakeorder.FieldStocktakeNo, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateStocktakeNo sets the "stocktake_no" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsert) UpdateStocktakeNo() *StocktakeOrderUpsert {
|
|
u.SetExcluded(stocktakeorder.FieldStocktakeNo)
|
|
return u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *StocktakeOrderUpsert) SetStatus(v string) *StocktakeOrderUpsert {
|
|
u.Set(stocktakeorder.FieldStatus, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsert) UpdateStatus() *StocktakeOrderUpsert {
|
|
u.SetExcluded(stocktakeorder.FieldStatus)
|
|
return u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (u *StocktakeOrderUpsert) SetOperator(v string) *StocktakeOrderUpsert {
|
|
u.Set(stocktakeorder.FieldOperator, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateOperator sets the "operator" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsert) UpdateOperator() *StocktakeOrderUpsert {
|
|
u.SetExcluded(stocktakeorder.FieldOperator)
|
|
return u
|
|
}
|
|
|
|
// ClearOperator clears the value of the "operator" field.
|
|
func (u *StocktakeOrderUpsert) ClearOperator() *StocktakeOrderUpsert {
|
|
u.SetNull(stocktakeorder.FieldOperator)
|
|
return u
|
|
}
|
|
|
|
// SetTotalTargets sets the "total_targets" field.
|
|
func (u *StocktakeOrderUpsert) SetTotalTargets(v int) *StocktakeOrderUpsert {
|
|
u.Set(stocktakeorder.FieldTotalTargets, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateTotalTargets sets the "total_targets" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsert) UpdateTotalTargets() *StocktakeOrderUpsert {
|
|
u.SetExcluded(stocktakeorder.FieldTotalTargets)
|
|
return u
|
|
}
|
|
|
|
// AddTotalTargets adds v to the "total_targets" field.
|
|
func (u *StocktakeOrderUpsert) AddTotalTargets(v int) *StocktakeOrderUpsert {
|
|
u.Add(stocktakeorder.FieldTotalTargets, v)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *StocktakeOrderUpsert) SetCreatedAt(v int64) *StocktakeOrderUpsert {
|
|
u.Set(stocktakeorder.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsert) UpdateCreatedAt() *StocktakeOrderUpsert {
|
|
u.SetExcluded(stocktakeorder.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *StocktakeOrderUpsert) AddCreatedAt(v int64) *StocktakeOrderUpsert {
|
|
u.Add(stocktakeorder.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// SetFinishedAt sets the "finished_at" field.
|
|
func (u *StocktakeOrderUpsert) SetFinishedAt(v int64) *StocktakeOrderUpsert {
|
|
u.Set(stocktakeorder.FieldFinishedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsert) UpdateFinishedAt() *StocktakeOrderUpsert {
|
|
u.SetExcluded(stocktakeorder.FieldFinishedAt)
|
|
return u
|
|
}
|
|
|
|
// AddFinishedAt adds v to the "finished_at" field.
|
|
func (u *StocktakeOrderUpsert) AddFinishedAt(v int64) *StocktakeOrderUpsert {
|
|
u.Add(stocktakeorder.FieldFinishedAt, v)
|
|
return u
|
|
}
|
|
|
|
// ClearFinishedAt clears the value of the "finished_at" field.
|
|
func (u *StocktakeOrderUpsert) ClearFinishedAt() *StocktakeOrderUpsert {
|
|
u.SetNull(stocktakeorder.FieldFinishedAt)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.StocktakeOrder.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *StocktakeOrderUpsertOne) UpdateNewValues() *StocktakeOrderUpsertOne {
|
|
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.StocktakeOrder.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *StocktakeOrderUpsertOne) Ignore() *StocktakeOrderUpsertOne {
|
|
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 *StocktakeOrderUpsertOne) DoNothing() *StocktakeOrderUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the StocktakeOrderCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *StocktakeOrderUpsertOne) Update(set func(*StocktakeOrderUpsert)) *StocktakeOrderUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&StocktakeOrderUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetStocktakeNo sets the "stocktake_no" field.
|
|
func (u *StocktakeOrderUpsertOne) SetStocktakeNo(v string) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetStocktakeNo(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStocktakeNo sets the "stocktake_no" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertOne) UpdateStocktakeNo() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateStocktakeNo()
|
|
})
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *StocktakeOrderUpsertOne) SetStatus(v string) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetStatus(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertOne) UpdateStatus() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateStatus()
|
|
})
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (u *StocktakeOrderUpsertOne) SetOperator(v string) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetOperator(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOperator sets the "operator" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertOne) UpdateOperator() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateOperator()
|
|
})
|
|
}
|
|
|
|
// ClearOperator clears the value of the "operator" field.
|
|
func (u *StocktakeOrderUpsertOne) ClearOperator() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.ClearOperator()
|
|
})
|
|
}
|
|
|
|
// SetTotalTargets sets the "total_targets" field.
|
|
func (u *StocktakeOrderUpsertOne) SetTotalTargets(v int) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetTotalTargets(v)
|
|
})
|
|
}
|
|
|
|
// AddTotalTargets adds v to the "total_targets" field.
|
|
func (u *StocktakeOrderUpsertOne) AddTotalTargets(v int) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.AddTotalTargets(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTotalTargets sets the "total_targets" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertOne) UpdateTotalTargets() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateTotalTargets()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *StocktakeOrderUpsertOne) SetCreatedAt(v int64) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *StocktakeOrderUpsertOne) AddCreatedAt(v int64) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertOne) UpdateCreatedAt() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetFinishedAt sets the "finished_at" field.
|
|
func (u *StocktakeOrderUpsertOne) SetFinishedAt(v int64) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetFinishedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddFinishedAt adds v to the "finished_at" field.
|
|
func (u *StocktakeOrderUpsertOne) AddFinishedAt(v int64) *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.AddFinishedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertOne) UpdateFinishedAt() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateFinishedAt()
|
|
})
|
|
}
|
|
|
|
// ClearFinishedAt clears the value of the "finished_at" field.
|
|
func (u *StocktakeOrderUpsertOne) ClearFinishedAt() *StocktakeOrderUpsertOne {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.ClearFinishedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *StocktakeOrderUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for StocktakeOrderCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *StocktakeOrderUpsertOne) 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 *StocktakeOrderUpsertOne) 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 *StocktakeOrderUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// StocktakeOrderCreateBulk is the builder for creating many StocktakeOrder entities in bulk.
|
|
type StocktakeOrderCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*StocktakeOrderCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the StocktakeOrder entities in the database.
|
|
func (_c *StocktakeOrderCreateBulk) Save(ctx context.Context) ([]*StocktakeOrder, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*StocktakeOrder, 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.(*StocktakeOrderMutation)
|
|
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 *StocktakeOrderCreateBulk) SaveX(ctx context.Context) []*StocktakeOrder {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *StocktakeOrderCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *StocktakeOrderCreateBulk) 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.StocktakeOrder.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.StocktakeOrderUpsert) {
|
|
// SetStocktakeNo(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *StocktakeOrderCreateBulk) OnConflict(opts ...sql.ConflictOption) *StocktakeOrderUpsertBulk {
|
|
_c.conflict = opts
|
|
return &StocktakeOrderUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.StocktakeOrder.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *StocktakeOrderCreateBulk) OnConflictColumns(columns ...string) *StocktakeOrderUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &StocktakeOrderUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// StocktakeOrderUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of StocktakeOrder nodes.
|
|
type StocktakeOrderUpsertBulk struct {
|
|
create *StocktakeOrderCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.StocktakeOrder.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *StocktakeOrderUpsertBulk) UpdateNewValues() *StocktakeOrderUpsertBulk {
|
|
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.StocktakeOrder.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *StocktakeOrderUpsertBulk) Ignore() *StocktakeOrderUpsertBulk {
|
|
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 *StocktakeOrderUpsertBulk) DoNothing() *StocktakeOrderUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the StocktakeOrderCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *StocktakeOrderUpsertBulk) Update(set func(*StocktakeOrderUpsert)) *StocktakeOrderUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&StocktakeOrderUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetStocktakeNo sets the "stocktake_no" field.
|
|
func (u *StocktakeOrderUpsertBulk) SetStocktakeNo(v string) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetStocktakeNo(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStocktakeNo sets the "stocktake_no" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertBulk) UpdateStocktakeNo() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateStocktakeNo()
|
|
})
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *StocktakeOrderUpsertBulk) SetStatus(v string) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetStatus(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertBulk) UpdateStatus() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateStatus()
|
|
})
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (u *StocktakeOrderUpsertBulk) SetOperator(v string) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetOperator(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOperator sets the "operator" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertBulk) UpdateOperator() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateOperator()
|
|
})
|
|
}
|
|
|
|
// ClearOperator clears the value of the "operator" field.
|
|
func (u *StocktakeOrderUpsertBulk) ClearOperator() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.ClearOperator()
|
|
})
|
|
}
|
|
|
|
// SetTotalTargets sets the "total_targets" field.
|
|
func (u *StocktakeOrderUpsertBulk) SetTotalTargets(v int) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetTotalTargets(v)
|
|
})
|
|
}
|
|
|
|
// AddTotalTargets adds v to the "total_targets" field.
|
|
func (u *StocktakeOrderUpsertBulk) AddTotalTargets(v int) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.AddTotalTargets(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTotalTargets sets the "total_targets" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertBulk) UpdateTotalTargets() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateTotalTargets()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *StocktakeOrderUpsertBulk) SetCreatedAt(v int64) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *StocktakeOrderUpsertBulk) AddCreatedAt(v int64) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertBulk) UpdateCreatedAt() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetFinishedAt sets the "finished_at" field.
|
|
func (u *StocktakeOrderUpsertBulk) SetFinishedAt(v int64) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.SetFinishedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddFinishedAt adds v to the "finished_at" field.
|
|
func (u *StocktakeOrderUpsertBulk) AddFinishedAt(v int64) *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.AddFinishedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
|
|
func (u *StocktakeOrderUpsertBulk) UpdateFinishedAt() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.UpdateFinishedAt()
|
|
})
|
|
}
|
|
|
|
// ClearFinishedAt clears the value of the "finished_at" field.
|
|
func (u *StocktakeOrderUpsertBulk) ClearFinishedAt() *StocktakeOrderUpsertBulk {
|
|
return u.Update(func(s *StocktakeOrderUpsert) {
|
|
s.ClearFinishedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *StocktakeOrderUpsertBulk) 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 StocktakeOrderCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for StocktakeOrderCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *StocktakeOrderUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|