Files
bj_power/bj_power_wms/ent/inventorylock_create.go
T
2026-08-28 15:06:01 +08:00

1116 lines
34 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/inventorylock"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// InventoryLockCreate is the builder for creating a InventoryLock entity.
type InventoryLockCreate struct {
config
mutation *InventoryLockMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetTargetType sets the "target_type" field.
func (_c *InventoryLockCreate) SetTargetType(v string) *InventoryLockCreate {
_c.mutation.SetTargetType(v)
return _c
}
// SetTargetID sets the "target_id" field.
func (_c *InventoryLockCreate) SetTargetID(v string) *InventoryLockCreate {
_c.mutation.SetTargetID(v)
return _c
}
// SetMaterialCode sets the "material_code" field.
func (_c *InventoryLockCreate) SetMaterialCode(v string) *InventoryLockCreate {
_c.mutation.SetMaterialCode(v)
return _c
}
// SetLockedQty sets the "locked_qty" field.
func (_c *InventoryLockCreate) SetLockedQty(v int) *InventoryLockCreate {
_c.mutation.SetLockedQty(v)
return _c
}
// SetNillableLockedQty sets the "locked_qty" field if the given value is not nil.
func (_c *InventoryLockCreate) SetNillableLockedQty(v *int) *InventoryLockCreate {
if v != nil {
_c.SetLockedQty(*v)
}
return _c
}
// SetOrderNo sets the "order_no" field.
func (_c *InventoryLockCreate) SetOrderNo(v string) *InventoryLockCreate {
_c.mutation.SetOrderNo(v)
return _c
}
// SetStatus sets the "status" field.
func (_c *InventoryLockCreate) SetStatus(v string) *InventoryLockCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *InventoryLockCreate) SetNillableStatus(v *string) *InventoryLockCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetExpiredAt sets the "expired_at" field.
func (_c *InventoryLockCreate) SetExpiredAt(v int64) *InventoryLockCreate {
_c.mutation.SetExpiredAt(v)
return _c
}
// SetNillableExpiredAt sets the "expired_at" field if the given value is not nil.
func (_c *InventoryLockCreate) SetNillableExpiredAt(v *int64) *InventoryLockCreate {
if v != nil {
_c.SetExpiredAt(*v)
}
return _c
}
// SetRemark sets the "remark" field.
func (_c *InventoryLockCreate) SetRemark(v string) *InventoryLockCreate {
_c.mutation.SetRemark(v)
return _c
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_c *InventoryLockCreate) SetNillableRemark(v *string) *InventoryLockCreate {
if v != nil {
_c.SetRemark(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *InventoryLockCreate) SetCreatedAt(v int64) *InventoryLockCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *InventoryLockCreate) SetNillableCreatedAt(v *int64) *InventoryLockCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *InventoryLockCreate) SetUpdatedAt(v int64) *InventoryLockCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *InventoryLockCreate) SetNillableUpdatedAt(v *int64) *InventoryLockCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// Mutation returns the InventoryLockMutation object of the builder.
func (_c *InventoryLockCreate) Mutation() *InventoryLockMutation {
return _c.mutation
}
// Save creates the InventoryLock in the database.
func (_c *InventoryLockCreate) Save(ctx context.Context) (*InventoryLock, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *InventoryLockCreate) SaveX(ctx context.Context) *InventoryLock {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *InventoryLockCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *InventoryLockCreate) 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 *InventoryLockCreate) defaults() {
if _, ok := _c.mutation.LockedQty(); !ok {
v := inventorylock.DefaultLockedQty
_c.mutation.SetLockedQty(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := inventorylock.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := inventorylock.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := inventorylock.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *InventoryLockCreate) check() error {
if _, ok := _c.mutation.TargetType(); !ok {
return &ValidationError{Name: "target_type", err: errors.New(`ent: missing required field "InventoryLock.target_type"`)}
}
if _, ok := _c.mutation.TargetID(); !ok {
return &ValidationError{Name: "target_id", err: errors.New(`ent: missing required field "InventoryLock.target_id"`)}
}
if _, ok := _c.mutation.MaterialCode(); !ok {
return &ValidationError{Name: "material_code", err: errors.New(`ent: missing required field "InventoryLock.material_code"`)}
}
if _, ok := _c.mutation.LockedQty(); !ok {
return &ValidationError{Name: "locked_qty", err: errors.New(`ent: missing required field "InventoryLock.locked_qty"`)}
}
if _, ok := _c.mutation.OrderNo(); !ok {
return &ValidationError{Name: "order_no", err: errors.New(`ent: missing required field "InventoryLock.order_no"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "InventoryLock.status"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "InventoryLock.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "InventoryLock.updated_at"`)}
}
return nil
}
func (_c *InventoryLockCreate) sqlSave(ctx context.Context) (*InventoryLock, 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 *InventoryLockCreate) createSpec() (*InventoryLock, *sqlgraph.CreateSpec) {
var (
_node = &InventoryLock{config: _c.config}
_spec = sqlgraph.NewCreateSpec(inventorylock.Table, sqlgraph.NewFieldSpec(inventorylock.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.TargetType(); ok {
_spec.SetField(inventorylock.FieldTargetType, field.TypeString, value)
_node.TargetType = value
}
if value, ok := _c.mutation.TargetID(); ok {
_spec.SetField(inventorylock.FieldTargetID, field.TypeString, value)
_node.TargetID = value
}
if value, ok := _c.mutation.MaterialCode(); ok {
_spec.SetField(inventorylock.FieldMaterialCode, field.TypeString, value)
_node.MaterialCode = value
}
if value, ok := _c.mutation.LockedQty(); ok {
_spec.SetField(inventorylock.FieldLockedQty, field.TypeInt, value)
_node.LockedQty = value
}
if value, ok := _c.mutation.OrderNo(); ok {
_spec.SetField(inventorylock.FieldOrderNo, field.TypeString, value)
_node.OrderNo = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(inventorylock.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.ExpiredAt(); ok {
_spec.SetField(inventorylock.FieldExpiredAt, field.TypeInt64, value)
_node.ExpiredAt = value
}
if value, ok := _c.mutation.Remark(); ok {
_spec.SetField(inventorylock.FieldRemark, field.TypeString, value)
_node.Remark = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(inventorylock.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(inventorylock.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.InventoryLock.Create().
// SetTargetType(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.InventoryLockUpsert) {
// SetTargetType(v+v).
// }).
// Exec(ctx)
func (_c *InventoryLockCreate) OnConflict(opts ...sql.ConflictOption) *InventoryLockUpsertOne {
_c.conflict = opts
return &InventoryLockUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.InventoryLock.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *InventoryLockCreate) OnConflictColumns(columns ...string) *InventoryLockUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &InventoryLockUpsertOne{
create: _c,
}
}
type (
// InventoryLockUpsertOne is the builder for "upsert"-ing
// one InventoryLock node.
InventoryLockUpsertOne struct {
create *InventoryLockCreate
}
// InventoryLockUpsert is the "OnConflict" setter.
InventoryLockUpsert struct {
*sql.UpdateSet
}
)
// SetTargetType sets the "target_type" field.
func (u *InventoryLockUpsert) SetTargetType(v string) *InventoryLockUpsert {
u.Set(inventorylock.FieldTargetType, v)
return u
}
// UpdateTargetType sets the "target_type" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateTargetType() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldTargetType)
return u
}
// SetTargetID sets the "target_id" field.
func (u *InventoryLockUpsert) SetTargetID(v string) *InventoryLockUpsert {
u.Set(inventorylock.FieldTargetID, v)
return u
}
// UpdateTargetID sets the "target_id" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateTargetID() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldTargetID)
return u
}
// SetMaterialCode sets the "material_code" field.
func (u *InventoryLockUpsert) SetMaterialCode(v string) *InventoryLockUpsert {
u.Set(inventorylock.FieldMaterialCode, v)
return u
}
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateMaterialCode() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldMaterialCode)
return u
}
// SetLockedQty sets the "locked_qty" field.
func (u *InventoryLockUpsert) SetLockedQty(v int) *InventoryLockUpsert {
u.Set(inventorylock.FieldLockedQty, v)
return u
}
// UpdateLockedQty sets the "locked_qty" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateLockedQty() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldLockedQty)
return u
}
// AddLockedQty adds v to the "locked_qty" field.
func (u *InventoryLockUpsert) AddLockedQty(v int) *InventoryLockUpsert {
u.Add(inventorylock.FieldLockedQty, v)
return u
}
// SetOrderNo sets the "order_no" field.
func (u *InventoryLockUpsert) SetOrderNo(v string) *InventoryLockUpsert {
u.Set(inventorylock.FieldOrderNo, v)
return u
}
// UpdateOrderNo sets the "order_no" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateOrderNo() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldOrderNo)
return u
}
// SetStatus sets the "status" field.
func (u *InventoryLockUpsert) SetStatus(v string) *InventoryLockUpsert {
u.Set(inventorylock.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateStatus() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldStatus)
return u
}
// SetExpiredAt sets the "expired_at" field.
func (u *InventoryLockUpsert) SetExpiredAt(v int64) *InventoryLockUpsert {
u.Set(inventorylock.FieldExpiredAt, v)
return u
}
// UpdateExpiredAt sets the "expired_at" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateExpiredAt() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldExpiredAt)
return u
}
// AddExpiredAt adds v to the "expired_at" field.
func (u *InventoryLockUpsert) AddExpiredAt(v int64) *InventoryLockUpsert {
u.Add(inventorylock.FieldExpiredAt, v)
return u
}
// ClearExpiredAt clears the value of the "expired_at" field.
func (u *InventoryLockUpsert) ClearExpiredAt() *InventoryLockUpsert {
u.SetNull(inventorylock.FieldExpiredAt)
return u
}
// SetRemark sets the "remark" field.
func (u *InventoryLockUpsert) SetRemark(v string) *InventoryLockUpsert {
u.Set(inventorylock.FieldRemark, v)
return u
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateRemark() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldRemark)
return u
}
// ClearRemark clears the value of the "remark" field.
func (u *InventoryLockUpsert) ClearRemark() *InventoryLockUpsert {
u.SetNull(inventorylock.FieldRemark)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *InventoryLockUpsert) SetCreatedAt(v int64) *InventoryLockUpsert {
u.Set(inventorylock.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateCreatedAt() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldCreatedAt)
return u
}
// AddCreatedAt adds v to the "created_at" field.
func (u *InventoryLockUpsert) AddCreatedAt(v int64) *InventoryLockUpsert {
u.Add(inventorylock.FieldCreatedAt, v)
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *InventoryLockUpsert) SetUpdatedAt(v int64) *InventoryLockUpsert {
u.Set(inventorylock.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *InventoryLockUpsert) UpdateUpdatedAt() *InventoryLockUpsert {
u.SetExcluded(inventorylock.FieldUpdatedAt)
return u
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *InventoryLockUpsert) AddUpdatedAt(v int64) *InventoryLockUpsert {
u.Add(inventorylock.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.InventoryLock.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *InventoryLockUpsertOne) UpdateNewValues() *InventoryLockUpsertOne {
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.InventoryLock.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *InventoryLockUpsertOne) Ignore() *InventoryLockUpsertOne {
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 *InventoryLockUpsertOne) DoNothing() *InventoryLockUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the InventoryLockCreate.OnConflict
// documentation for more info.
func (u *InventoryLockUpsertOne) Update(set func(*InventoryLockUpsert)) *InventoryLockUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&InventoryLockUpsert{UpdateSet: update})
}))
return u
}
// SetTargetType sets the "target_type" field.
func (u *InventoryLockUpsertOne) SetTargetType(v string) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetTargetType(v)
})
}
// UpdateTargetType sets the "target_type" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateTargetType() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateTargetType()
})
}
// SetTargetID sets the "target_id" field.
func (u *InventoryLockUpsertOne) SetTargetID(v string) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetTargetID(v)
})
}
// UpdateTargetID sets the "target_id" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateTargetID() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateTargetID()
})
}
// SetMaterialCode sets the "material_code" field.
func (u *InventoryLockUpsertOne) SetMaterialCode(v string) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetMaterialCode(v)
})
}
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateMaterialCode() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateMaterialCode()
})
}
// SetLockedQty sets the "locked_qty" field.
func (u *InventoryLockUpsertOne) SetLockedQty(v int) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetLockedQty(v)
})
}
// AddLockedQty adds v to the "locked_qty" field.
func (u *InventoryLockUpsertOne) AddLockedQty(v int) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.AddLockedQty(v)
})
}
// UpdateLockedQty sets the "locked_qty" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateLockedQty() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateLockedQty()
})
}
// SetOrderNo sets the "order_no" field.
func (u *InventoryLockUpsertOne) SetOrderNo(v string) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetOrderNo(v)
})
}
// UpdateOrderNo sets the "order_no" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateOrderNo() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateOrderNo()
})
}
// SetStatus sets the "status" field.
func (u *InventoryLockUpsertOne) SetStatus(v string) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateStatus() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateStatus()
})
}
// SetExpiredAt sets the "expired_at" field.
func (u *InventoryLockUpsertOne) SetExpiredAt(v int64) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetExpiredAt(v)
})
}
// AddExpiredAt adds v to the "expired_at" field.
func (u *InventoryLockUpsertOne) AddExpiredAt(v int64) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.AddExpiredAt(v)
})
}
// UpdateExpiredAt sets the "expired_at" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateExpiredAt() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateExpiredAt()
})
}
// ClearExpiredAt clears the value of the "expired_at" field.
func (u *InventoryLockUpsertOne) ClearExpiredAt() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.ClearExpiredAt()
})
}
// SetRemark sets the "remark" field.
func (u *InventoryLockUpsertOne) SetRemark(v string) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateRemark() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateRemark()
})
}
// ClearRemark clears the value of the "remark" field.
func (u *InventoryLockUpsertOne) ClearRemark() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.ClearRemark()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *InventoryLockUpsertOne) SetCreatedAt(v int64) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *InventoryLockUpsertOne) AddCreatedAt(v int64) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateCreatedAt() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *InventoryLockUpsertOne) SetUpdatedAt(v int64) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.SetUpdatedAt(v)
})
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *InventoryLockUpsertOne) AddUpdatedAt(v int64) *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.AddUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *InventoryLockUpsertOne) UpdateUpdatedAt() *InventoryLockUpsertOne {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *InventoryLockUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for InventoryLockCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *InventoryLockUpsertOne) 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 *InventoryLockUpsertOne) 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 *InventoryLockUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// InventoryLockCreateBulk is the builder for creating many InventoryLock entities in bulk.
type InventoryLockCreateBulk struct {
config
err error
builders []*InventoryLockCreate
conflict []sql.ConflictOption
}
// Save creates the InventoryLock entities in the database.
func (_c *InventoryLockCreateBulk) Save(ctx context.Context) ([]*InventoryLock, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*InventoryLock, 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.(*InventoryLockMutation)
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 *InventoryLockCreateBulk) SaveX(ctx context.Context) []*InventoryLock {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *InventoryLockCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *InventoryLockCreateBulk) 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.InventoryLock.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.InventoryLockUpsert) {
// SetTargetType(v+v).
// }).
// Exec(ctx)
func (_c *InventoryLockCreateBulk) OnConflict(opts ...sql.ConflictOption) *InventoryLockUpsertBulk {
_c.conflict = opts
return &InventoryLockUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.InventoryLock.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *InventoryLockCreateBulk) OnConflictColumns(columns ...string) *InventoryLockUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &InventoryLockUpsertBulk{
create: _c,
}
}
// InventoryLockUpsertBulk is the builder for "upsert"-ing
// a bulk of InventoryLock nodes.
type InventoryLockUpsertBulk struct {
create *InventoryLockCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.InventoryLock.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *InventoryLockUpsertBulk) UpdateNewValues() *InventoryLockUpsertBulk {
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.InventoryLock.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *InventoryLockUpsertBulk) Ignore() *InventoryLockUpsertBulk {
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 *InventoryLockUpsertBulk) DoNothing() *InventoryLockUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the InventoryLockCreateBulk.OnConflict
// documentation for more info.
func (u *InventoryLockUpsertBulk) Update(set func(*InventoryLockUpsert)) *InventoryLockUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&InventoryLockUpsert{UpdateSet: update})
}))
return u
}
// SetTargetType sets the "target_type" field.
func (u *InventoryLockUpsertBulk) SetTargetType(v string) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetTargetType(v)
})
}
// UpdateTargetType sets the "target_type" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateTargetType() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateTargetType()
})
}
// SetTargetID sets the "target_id" field.
func (u *InventoryLockUpsertBulk) SetTargetID(v string) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetTargetID(v)
})
}
// UpdateTargetID sets the "target_id" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateTargetID() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateTargetID()
})
}
// SetMaterialCode sets the "material_code" field.
func (u *InventoryLockUpsertBulk) SetMaterialCode(v string) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetMaterialCode(v)
})
}
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateMaterialCode() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateMaterialCode()
})
}
// SetLockedQty sets the "locked_qty" field.
func (u *InventoryLockUpsertBulk) SetLockedQty(v int) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetLockedQty(v)
})
}
// AddLockedQty adds v to the "locked_qty" field.
func (u *InventoryLockUpsertBulk) AddLockedQty(v int) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.AddLockedQty(v)
})
}
// UpdateLockedQty sets the "locked_qty" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateLockedQty() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateLockedQty()
})
}
// SetOrderNo sets the "order_no" field.
func (u *InventoryLockUpsertBulk) SetOrderNo(v string) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetOrderNo(v)
})
}
// UpdateOrderNo sets the "order_no" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateOrderNo() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateOrderNo()
})
}
// SetStatus sets the "status" field.
func (u *InventoryLockUpsertBulk) SetStatus(v string) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateStatus() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateStatus()
})
}
// SetExpiredAt sets the "expired_at" field.
func (u *InventoryLockUpsertBulk) SetExpiredAt(v int64) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetExpiredAt(v)
})
}
// AddExpiredAt adds v to the "expired_at" field.
func (u *InventoryLockUpsertBulk) AddExpiredAt(v int64) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.AddExpiredAt(v)
})
}
// UpdateExpiredAt sets the "expired_at" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateExpiredAt() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateExpiredAt()
})
}
// ClearExpiredAt clears the value of the "expired_at" field.
func (u *InventoryLockUpsertBulk) ClearExpiredAt() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.ClearExpiredAt()
})
}
// SetRemark sets the "remark" field.
func (u *InventoryLockUpsertBulk) SetRemark(v string) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateRemark() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateRemark()
})
}
// ClearRemark clears the value of the "remark" field.
func (u *InventoryLockUpsertBulk) ClearRemark() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.ClearRemark()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *InventoryLockUpsertBulk) SetCreatedAt(v int64) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *InventoryLockUpsertBulk) AddCreatedAt(v int64) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateCreatedAt() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *InventoryLockUpsertBulk) SetUpdatedAt(v int64) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.SetUpdatedAt(v)
})
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *InventoryLockUpsertBulk) AddUpdatedAt(v int64) *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.AddUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *InventoryLockUpsertBulk) UpdateUpdatedAt() *InventoryLockUpsertBulk {
return u.Update(func(s *InventoryLockUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *InventoryLockUpsertBulk) 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 InventoryLockCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for InventoryLockCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *InventoryLockUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}