840 lines
25 KiB
Go
840 lines
25 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/inbounddetail"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// InboundDetailCreate is the builder for creating a InboundDetail entity.
|
|
type InboundDetailCreate struct {
|
|
config
|
|
mutation *InboundDetailMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetInboundNo sets the "inbound_no" field.
|
|
func (_c *InboundDetailCreate) SetInboundNo(v string) *InboundDetailCreate {
|
|
_c.mutation.SetInboundNo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSnCode sets the "sn_code" field.
|
|
func (_c *InboundDetailCreate) SetSnCode(v string) *InboundDetailCreate {
|
|
_c.mutation.SetSnCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableSnCode sets the "sn_code" field if the given value is not nil.
|
|
func (_c *InboundDetailCreate) SetNillableSnCode(v *string) *InboundDetailCreate {
|
|
if v != nil {
|
|
_c.SetSnCode(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetBatchNo sets the "batch_no" field.
|
|
func (_c *InboundDetailCreate) SetBatchNo(v string) *InboundDetailCreate {
|
|
_c.mutation.SetBatchNo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
|
|
func (_c *InboundDetailCreate) SetNillableBatchNo(v *string) *InboundDetailCreate {
|
|
if v != nil {
|
|
_c.SetBatchNo(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetMaterialCode sets the "material_code" field.
|
|
func (_c *InboundDetailCreate) SetMaterialCode(v string) *InboundDetailCreate {
|
|
_c.mutation.SetMaterialCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetQuantity sets the "quantity" field.
|
|
func (_c *InboundDetailCreate) SetQuantity(v int) *InboundDetailCreate {
|
|
_c.mutation.SetQuantity(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
|
|
func (_c *InboundDetailCreate) SetNillableQuantity(v *int) *InboundDetailCreate {
|
|
if v != nil {
|
|
_c.SetQuantity(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *InboundDetailCreate) SetCreatedAt(v int64) *InboundDetailCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *InboundDetailCreate) SetNillableCreatedAt(v *int64) *InboundDetailCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the InboundDetailMutation object of the builder.
|
|
func (_c *InboundDetailCreate) Mutation() *InboundDetailMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the InboundDetail in the database.
|
|
func (_c *InboundDetailCreate) Save(ctx context.Context) (*InboundDetail, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *InboundDetailCreate) SaveX(ctx context.Context) *InboundDetail {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *InboundDetailCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *InboundDetailCreate) 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 *InboundDetailCreate) defaults() {
|
|
if _, ok := _c.mutation.Quantity(); !ok {
|
|
v := inbounddetail.DefaultQuantity
|
|
_c.mutation.SetQuantity(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := inbounddetail.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *InboundDetailCreate) check() error {
|
|
if _, ok := _c.mutation.InboundNo(); !ok {
|
|
return &ValidationError{Name: "inbound_no", err: errors.New(`ent: missing required field "InboundDetail.inbound_no"`)}
|
|
}
|
|
if _, ok := _c.mutation.MaterialCode(); !ok {
|
|
return &ValidationError{Name: "material_code", err: errors.New(`ent: missing required field "InboundDetail.material_code"`)}
|
|
}
|
|
if _, ok := _c.mutation.Quantity(); !ok {
|
|
return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "InboundDetail.quantity"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "InboundDetail.created_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *InboundDetailCreate) sqlSave(ctx context.Context) (*InboundDetail, 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 *InboundDetailCreate) createSpec() (*InboundDetail, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &InboundDetail{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(inbounddetail.Table, sqlgraph.NewFieldSpec(inbounddetail.FieldID, field.TypeInt))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.InboundNo(); ok {
|
|
_spec.SetField(inbounddetail.FieldInboundNo, field.TypeString, value)
|
|
_node.InboundNo = value
|
|
}
|
|
if value, ok := _c.mutation.SnCode(); ok {
|
|
_spec.SetField(inbounddetail.FieldSnCode, field.TypeString, value)
|
|
_node.SnCode = value
|
|
}
|
|
if value, ok := _c.mutation.BatchNo(); ok {
|
|
_spec.SetField(inbounddetail.FieldBatchNo, field.TypeString, value)
|
|
_node.BatchNo = value
|
|
}
|
|
if value, ok := _c.mutation.MaterialCode(); ok {
|
|
_spec.SetField(inbounddetail.FieldMaterialCode, field.TypeString, value)
|
|
_node.MaterialCode = value
|
|
}
|
|
if value, ok := _c.mutation.Quantity(); ok {
|
|
_spec.SetField(inbounddetail.FieldQuantity, field.TypeInt, value)
|
|
_node.Quantity = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(inbounddetail.FieldCreatedAt, field.TypeInt64, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.InboundDetail.Create().
|
|
// SetInboundNo(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.InboundDetailUpsert) {
|
|
// SetInboundNo(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *InboundDetailCreate) OnConflict(opts ...sql.ConflictOption) *InboundDetailUpsertOne {
|
|
_c.conflict = opts
|
|
return &InboundDetailUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.InboundDetail.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *InboundDetailCreate) OnConflictColumns(columns ...string) *InboundDetailUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &InboundDetailUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// InboundDetailUpsertOne is the builder for "upsert"-ing
|
|
// one InboundDetail node.
|
|
InboundDetailUpsertOne struct {
|
|
create *InboundDetailCreate
|
|
}
|
|
|
|
// InboundDetailUpsert is the "OnConflict" setter.
|
|
InboundDetailUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetInboundNo sets the "inbound_no" field.
|
|
func (u *InboundDetailUpsert) SetInboundNo(v string) *InboundDetailUpsert {
|
|
u.Set(inbounddetail.FieldInboundNo, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateInboundNo sets the "inbound_no" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsert) UpdateInboundNo() *InboundDetailUpsert {
|
|
u.SetExcluded(inbounddetail.FieldInboundNo)
|
|
return u
|
|
}
|
|
|
|
// SetSnCode sets the "sn_code" field.
|
|
func (u *InboundDetailUpsert) SetSnCode(v string) *InboundDetailUpsert {
|
|
u.Set(inbounddetail.FieldSnCode, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateSnCode sets the "sn_code" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsert) UpdateSnCode() *InboundDetailUpsert {
|
|
u.SetExcluded(inbounddetail.FieldSnCode)
|
|
return u
|
|
}
|
|
|
|
// ClearSnCode clears the value of the "sn_code" field.
|
|
func (u *InboundDetailUpsert) ClearSnCode() *InboundDetailUpsert {
|
|
u.SetNull(inbounddetail.FieldSnCode)
|
|
return u
|
|
}
|
|
|
|
// SetBatchNo sets the "batch_no" field.
|
|
func (u *InboundDetailUpsert) SetBatchNo(v string) *InboundDetailUpsert {
|
|
u.Set(inbounddetail.FieldBatchNo, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsert) UpdateBatchNo() *InboundDetailUpsert {
|
|
u.SetExcluded(inbounddetail.FieldBatchNo)
|
|
return u
|
|
}
|
|
|
|
// ClearBatchNo clears the value of the "batch_no" field.
|
|
func (u *InboundDetailUpsert) ClearBatchNo() *InboundDetailUpsert {
|
|
u.SetNull(inbounddetail.FieldBatchNo)
|
|
return u
|
|
}
|
|
|
|
// SetMaterialCode sets the "material_code" field.
|
|
func (u *InboundDetailUpsert) SetMaterialCode(v string) *InboundDetailUpsert {
|
|
u.Set(inbounddetail.FieldMaterialCode, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsert) UpdateMaterialCode() *InboundDetailUpsert {
|
|
u.SetExcluded(inbounddetail.FieldMaterialCode)
|
|
return u
|
|
}
|
|
|
|
// SetQuantity sets the "quantity" field.
|
|
func (u *InboundDetailUpsert) SetQuantity(v int) *InboundDetailUpsert {
|
|
u.Set(inbounddetail.FieldQuantity, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateQuantity sets the "quantity" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsert) UpdateQuantity() *InboundDetailUpsert {
|
|
u.SetExcluded(inbounddetail.FieldQuantity)
|
|
return u
|
|
}
|
|
|
|
// AddQuantity adds v to the "quantity" field.
|
|
func (u *InboundDetailUpsert) AddQuantity(v int) *InboundDetailUpsert {
|
|
u.Add(inbounddetail.FieldQuantity, v)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *InboundDetailUpsert) SetCreatedAt(v int64) *InboundDetailUpsert {
|
|
u.Set(inbounddetail.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsert) UpdateCreatedAt() *InboundDetailUpsert {
|
|
u.SetExcluded(inbounddetail.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *InboundDetailUpsert) AddCreatedAt(v int64) *InboundDetailUpsert {
|
|
u.Add(inbounddetail.FieldCreatedAt, 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.InboundDetail.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *InboundDetailUpsertOne) UpdateNewValues() *InboundDetailUpsertOne {
|
|
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.InboundDetail.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *InboundDetailUpsertOne) Ignore() *InboundDetailUpsertOne {
|
|
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 *InboundDetailUpsertOne) DoNothing() *InboundDetailUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the InboundDetailCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *InboundDetailUpsertOne) Update(set func(*InboundDetailUpsert)) *InboundDetailUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&InboundDetailUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetInboundNo sets the "inbound_no" field.
|
|
func (u *InboundDetailUpsertOne) SetInboundNo(v string) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetInboundNo(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInboundNo sets the "inbound_no" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertOne) UpdateInboundNo() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateInboundNo()
|
|
})
|
|
}
|
|
|
|
// SetSnCode sets the "sn_code" field.
|
|
func (u *InboundDetailUpsertOne) SetSnCode(v string) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetSnCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSnCode sets the "sn_code" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertOne) UpdateSnCode() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateSnCode()
|
|
})
|
|
}
|
|
|
|
// ClearSnCode clears the value of the "sn_code" field.
|
|
func (u *InboundDetailUpsertOne) ClearSnCode() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.ClearSnCode()
|
|
})
|
|
}
|
|
|
|
// SetBatchNo sets the "batch_no" field.
|
|
func (u *InboundDetailUpsertOne) SetBatchNo(v string) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetBatchNo(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertOne) UpdateBatchNo() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateBatchNo()
|
|
})
|
|
}
|
|
|
|
// ClearBatchNo clears the value of the "batch_no" field.
|
|
func (u *InboundDetailUpsertOne) ClearBatchNo() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.ClearBatchNo()
|
|
})
|
|
}
|
|
|
|
// SetMaterialCode sets the "material_code" field.
|
|
func (u *InboundDetailUpsertOne) SetMaterialCode(v string) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetMaterialCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertOne) UpdateMaterialCode() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateMaterialCode()
|
|
})
|
|
}
|
|
|
|
// SetQuantity sets the "quantity" field.
|
|
func (u *InboundDetailUpsertOne) SetQuantity(v int) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetQuantity(v)
|
|
})
|
|
}
|
|
|
|
// AddQuantity adds v to the "quantity" field.
|
|
func (u *InboundDetailUpsertOne) AddQuantity(v int) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.AddQuantity(v)
|
|
})
|
|
}
|
|
|
|
// UpdateQuantity sets the "quantity" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertOne) UpdateQuantity() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateQuantity()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *InboundDetailUpsertOne) SetCreatedAt(v int64) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *InboundDetailUpsertOne) AddCreatedAt(v int64) *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertOne) UpdateCreatedAt() *InboundDetailUpsertOne {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *InboundDetailUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for InboundDetailCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *InboundDetailUpsertOne) 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 *InboundDetailUpsertOne) 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 *InboundDetailUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// InboundDetailCreateBulk is the builder for creating many InboundDetail entities in bulk.
|
|
type InboundDetailCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*InboundDetailCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the InboundDetail entities in the database.
|
|
func (_c *InboundDetailCreateBulk) Save(ctx context.Context) ([]*InboundDetail, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*InboundDetail, 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.(*InboundDetailMutation)
|
|
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 *InboundDetailCreateBulk) SaveX(ctx context.Context) []*InboundDetail {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *InboundDetailCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *InboundDetailCreateBulk) 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.InboundDetail.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.InboundDetailUpsert) {
|
|
// SetInboundNo(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *InboundDetailCreateBulk) OnConflict(opts ...sql.ConflictOption) *InboundDetailUpsertBulk {
|
|
_c.conflict = opts
|
|
return &InboundDetailUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.InboundDetail.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *InboundDetailCreateBulk) OnConflictColumns(columns ...string) *InboundDetailUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &InboundDetailUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// InboundDetailUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of InboundDetail nodes.
|
|
type InboundDetailUpsertBulk struct {
|
|
create *InboundDetailCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.InboundDetail.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *InboundDetailUpsertBulk) UpdateNewValues() *InboundDetailUpsertBulk {
|
|
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.InboundDetail.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *InboundDetailUpsertBulk) Ignore() *InboundDetailUpsertBulk {
|
|
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 *InboundDetailUpsertBulk) DoNothing() *InboundDetailUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the InboundDetailCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *InboundDetailUpsertBulk) Update(set func(*InboundDetailUpsert)) *InboundDetailUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&InboundDetailUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetInboundNo sets the "inbound_no" field.
|
|
func (u *InboundDetailUpsertBulk) SetInboundNo(v string) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetInboundNo(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInboundNo sets the "inbound_no" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertBulk) UpdateInboundNo() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateInboundNo()
|
|
})
|
|
}
|
|
|
|
// SetSnCode sets the "sn_code" field.
|
|
func (u *InboundDetailUpsertBulk) SetSnCode(v string) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetSnCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSnCode sets the "sn_code" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertBulk) UpdateSnCode() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateSnCode()
|
|
})
|
|
}
|
|
|
|
// ClearSnCode clears the value of the "sn_code" field.
|
|
func (u *InboundDetailUpsertBulk) ClearSnCode() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.ClearSnCode()
|
|
})
|
|
}
|
|
|
|
// SetBatchNo sets the "batch_no" field.
|
|
func (u *InboundDetailUpsertBulk) SetBatchNo(v string) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetBatchNo(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertBulk) UpdateBatchNo() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateBatchNo()
|
|
})
|
|
}
|
|
|
|
// ClearBatchNo clears the value of the "batch_no" field.
|
|
func (u *InboundDetailUpsertBulk) ClearBatchNo() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.ClearBatchNo()
|
|
})
|
|
}
|
|
|
|
// SetMaterialCode sets the "material_code" field.
|
|
func (u *InboundDetailUpsertBulk) SetMaterialCode(v string) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetMaterialCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertBulk) UpdateMaterialCode() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateMaterialCode()
|
|
})
|
|
}
|
|
|
|
// SetQuantity sets the "quantity" field.
|
|
func (u *InboundDetailUpsertBulk) SetQuantity(v int) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetQuantity(v)
|
|
})
|
|
}
|
|
|
|
// AddQuantity adds v to the "quantity" field.
|
|
func (u *InboundDetailUpsertBulk) AddQuantity(v int) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.AddQuantity(v)
|
|
})
|
|
}
|
|
|
|
// UpdateQuantity sets the "quantity" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertBulk) UpdateQuantity() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateQuantity()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *InboundDetailUpsertBulk) SetCreatedAt(v int64) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *InboundDetailUpsertBulk) AddCreatedAt(v int64) *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *InboundDetailUpsertBulk) UpdateCreatedAt() *InboundDetailUpsertBulk {
|
|
return u.Update(func(s *InboundDetailUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *InboundDetailUpsertBulk) 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 InboundDetailCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for InboundDetailCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *InboundDetailUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|