Files
bj_power/bj_power_wms/ent/ordermaterialledger_create.go
T

1075 lines
34 KiB
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/ordermaterialledger"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// OrderMaterialLedgerCreate is the builder for creating a OrderMaterialLedger entity.
type OrderMaterialLedgerCreate struct {
config
mutation *OrderMaterialLedgerMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetOrderNo sets the "order_no" field.
func (_c *OrderMaterialLedgerCreate) SetOrderNo(v string) *OrderMaterialLedgerCreate {
_c.mutation.SetOrderNo(v)
return _c
}
// SetMaterialCode sets the "material_code" field.
func (_c *OrderMaterialLedgerCreate) SetMaterialCode(v string) *OrderMaterialLedgerCreate {
_c.mutation.SetMaterialCode(v)
return _c
}
// SetMaterialName sets the "material_name" field.
func (_c *OrderMaterialLedgerCreate) SetMaterialName(v string) *OrderMaterialLedgerCreate {
_c.mutation.SetMaterialName(v)
return _c
}
// SetNillableMaterialName sets the "material_name" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableMaterialName(v *string) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetMaterialName(*v)
}
return _c
}
// SetTotalQty sets the "total_qty" field.
func (_c *OrderMaterialLedgerCreate) SetTotalQty(v int) *OrderMaterialLedgerCreate {
_c.mutation.SetTotalQty(v)
return _c
}
// SetNillableTotalQty sets the "total_qty" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableTotalQty(v *int) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetTotalQty(*v)
}
return _c
}
// SetOutQty sets the "out_qty" field.
func (_c *OrderMaterialLedgerCreate) SetOutQty(v int) *OrderMaterialLedgerCreate {
_c.mutation.SetOutQty(v)
return _c
}
// SetNillableOutQty sets the "out_qty" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableOutQty(v *int) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetOutQty(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *OrderMaterialLedgerCreate) SetStatus(v string) *OrderMaterialLedgerCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableStatus(v *string) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetRemark sets the "remark" field.
func (_c *OrderMaterialLedgerCreate) SetRemark(v string) *OrderMaterialLedgerCreate {
_c.mutation.SetRemark(v)
return _c
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableRemark(v *string) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetRemark(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *OrderMaterialLedgerCreate) SetCreatedAt(v int64) *OrderMaterialLedgerCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableCreatedAt(v *int64) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *OrderMaterialLedgerCreate) SetUpdatedAt(v int64) *OrderMaterialLedgerCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *OrderMaterialLedgerCreate) SetNillableUpdatedAt(v *int64) *OrderMaterialLedgerCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// Mutation returns the OrderMaterialLedgerMutation object of the builder.
func (_c *OrderMaterialLedgerCreate) Mutation() *OrderMaterialLedgerMutation {
return _c.mutation
}
// Save creates the OrderMaterialLedger in the database.
func (_c *OrderMaterialLedgerCreate) Save(ctx context.Context) (*OrderMaterialLedger, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *OrderMaterialLedgerCreate) SaveX(ctx context.Context) *OrderMaterialLedger {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *OrderMaterialLedgerCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *OrderMaterialLedgerCreate) 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 *OrderMaterialLedgerCreate) defaults() {
if _, ok := _c.mutation.TotalQty(); !ok {
v := ordermaterialledger.DefaultTotalQty
_c.mutation.SetTotalQty(v)
}
if _, ok := _c.mutation.OutQty(); !ok {
v := ordermaterialledger.DefaultOutQty
_c.mutation.SetOutQty(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := ordermaterialledger.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := ordermaterialledger.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := ordermaterialledger.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *OrderMaterialLedgerCreate) check() error {
if _, ok := _c.mutation.OrderNo(); !ok {
return &ValidationError{Name: "order_no", err: errors.New(`ent: missing required field "OrderMaterialLedger.order_no"`)}
}
if _, ok := _c.mutation.MaterialCode(); !ok {
return &ValidationError{Name: "material_code", err: errors.New(`ent: missing required field "OrderMaterialLedger.material_code"`)}
}
if _, ok := _c.mutation.TotalQty(); !ok {
return &ValidationError{Name: "total_qty", err: errors.New(`ent: missing required field "OrderMaterialLedger.total_qty"`)}
}
if _, ok := _c.mutation.OutQty(); !ok {
return &ValidationError{Name: "out_qty", err: errors.New(`ent: missing required field "OrderMaterialLedger.out_qty"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "OrderMaterialLedger.status"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "OrderMaterialLedger.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "OrderMaterialLedger.updated_at"`)}
}
return nil
}
func (_c *OrderMaterialLedgerCreate) sqlSave(ctx context.Context) (*OrderMaterialLedger, 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 *OrderMaterialLedgerCreate) createSpec() (*OrderMaterialLedger, *sqlgraph.CreateSpec) {
var (
_node = &OrderMaterialLedger{config: _c.config}
_spec = sqlgraph.NewCreateSpec(ordermaterialledger.Table, sqlgraph.NewFieldSpec(ordermaterialledger.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.OrderNo(); ok {
_spec.SetField(ordermaterialledger.FieldOrderNo, field.TypeString, value)
_node.OrderNo = value
}
if value, ok := _c.mutation.MaterialCode(); ok {
_spec.SetField(ordermaterialledger.FieldMaterialCode, field.TypeString, value)
_node.MaterialCode = value
}
if value, ok := _c.mutation.MaterialName(); ok {
_spec.SetField(ordermaterialledger.FieldMaterialName, field.TypeString, value)
_node.MaterialName = value
}
if value, ok := _c.mutation.TotalQty(); ok {
_spec.SetField(ordermaterialledger.FieldTotalQty, field.TypeInt, value)
_node.TotalQty = value
}
if value, ok := _c.mutation.OutQty(); ok {
_spec.SetField(ordermaterialledger.FieldOutQty, field.TypeInt, value)
_node.OutQty = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(ordermaterialledger.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.Remark(); ok {
_spec.SetField(ordermaterialledger.FieldRemark, field.TypeString, value)
_node.Remark = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(ordermaterialledger.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(ordermaterialledger.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.OrderMaterialLedger.Create().
// SetOrderNo(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.OrderMaterialLedgerUpsert) {
// SetOrderNo(v+v).
// }).
// Exec(ctx)
func (_c *OrderMaterialLedgerCreate) OnConflict(opts ...sql.ConflictOption) *OrderMaterialLedgerUpsertOne {
_c.conflict = opts
return &OrderMaterialLedgerUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.OrderMaterialLedger.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *OrderMaterialLedgerCreate) OnConflictColumns(columns ...string) *OrderMaterialLedgerUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &OrderMaterialLedgerUpsertOne{
create: _c,
}
}
type (
// OrderMaterialLedgerUpsertOne is the builder for "upsert"-ing
// one OrderMaterialLedger node.
OrderMaterialLedgerUpsertOne struct {
create *OrderMaterialLedgerCreate
}
// OrderMaterialLedgerUpsert is the "OnConflict" setter.
OrderMaterialLedgerUpsert struct {
*sql.UpdateSet
}
)
// SetOrderNo sets the "order_no" field.
func (u *OrderMaterialLedgerUpsert) SetOrderNo(v string) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldOrderNo, v)
return u
}
// UpdateOrderNo sets the "order_no" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateOrderNo() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldOrderNo)
return u
}
// SetMaterialCode sets the "material_code" field.
func (u *OrderMaterialLedgerUpsert) SetMaterialCode(v string) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldMaterialCode, v)
return u
}
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateMaterialCode() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldMaterialCode)
return u
}
// SetMaterialName sets the "material_name" field.
func (u *OrderMaterialLedgerUpsert) SetMaterialName(v string) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldMaterialName, v)
return u
}
// UpdateMaterialName sets the "material_name" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateMaterialName() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldMaterialName)
return u
}
// ClearMaterialName clears the value of the "material_name" field.
func (u *OrderMaterialLedgerUpsert) ClearMaterialName() *OrderMaterialLedgerUpsert {
u.SetNull(ordermaterialledger.FieldMaterialName)
return u
}
// SetTotalQty sets the "total_qty" field.
func (u *OrderMaterialLedgerUpsert) SetTotalQty(v int) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldTotalQty, v)
return u
}
// UpdateTotalQty sets the "total_qty" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateTotalQty() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldTotalQty)
return u
}
// AddTotalQty adds v to the "total_qty" field.
func (u *OrderMaterialLedgerUpsert) AddTotalQty(v int) *OrderMaterialLedgerUpsert {
u.Add(ordermaterialledger.FieldTotalQty, v)
return u
}
// SetOutQty sets the "out_qty" field.
func (u *OrderMaterialLedgerUpsert) SetOutQty(v int) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldOutQty, v)
return u
}
// UpdateOutQty sets the "out_qty" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateOutQty() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldOutQty)
return u
}
// AddOutQty adds v to the "out_qty" field.
func (u *OrderMaterialLedgerUpsert) AddOutQty(v int) *OrderMaterialLedgerUpsert {
u.Add(ordermaterialledger.FieldOutQty, v)
return u
}
// SetStatus sets the "status" field.
func (u *OrderMaterialLedgerUpsert) SetStatus(v string) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateStatus() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldStatus)
return u
}
// SetRemark sets the "remark" field.
func (u *OrderMaterialLedgerUpsert) SetRemark(v string) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldRemark, v)
return u
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateRemark() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldRemark)
return u
}
// ClearRemark clears the value of the "remark" field.
func (u *OrderMaterialLedgerUpsert) ClearRemark() *OrderMaterialLedgerUpsert {
u.SetNull(ordermaterialledger.FieldRemark)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *OrderMaterialLedgerUpsert) SetCreatedAt(v int64) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateCreatedAt() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldCreatedAt)
return u
}
// AddCreatedAt adds v to the "created_at" field.
func (u *OrderMaterialLedgerUpsert) AddCreatedAt(v int64) *OrderMaterialLedgerUpsert {
u.Add(ordermaterialledger.FieldCreatedAt, v)
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *OrderMaterialLedgerUpsert) SetUpdatedAt(v int64) *OrderMaterialLedgerUpsert {
u.Set(ordermaterialledger.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsert) UpdateUpdatedAt() *OrderMaterialLedgerUpsert {
u.SetExcluded(ordermaterialledger.FieldUpdatedAt)
return u
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *OrderMaterialLedgerUpsert) AddUpdatedAt(v int64) *OrderMaterialLedgerUpsert {
u.Add(ordermaterialledger.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.OrderMaterialLedger.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *OrderMaterialLedgerUpsertOne) UpdateNewValues() *OrderMaterialLedgerUpsertOne {
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.OrderMaterialLedger.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *OrderMaterialLedgerUpsertOne) Ignore() *OrderMaterialLedgerUpsertOne {
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 *OrderMaterialLedgerUpsertOne) DoNothing() *OrderMaterialLedgerUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the OrderMaterialLedgerCreate.OnConflict
// documentation for more info.
func (u *OrderMaterialLedgerUpsertOne) Update(set func(*OrderMaterialLedgerUpsert)) *OrderMaterialLedgerUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&OrderMaterialLedgerUpsert{UpdateSet: update})
}))
return u
}
// SetOrderNo sets the "order_no" field.
func (u *OrderMaterialLedgerUpsertOne) SetOrderNo(v string) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetOrderNo(v)
})
}
// UpdateOrderNo sets the "order_no" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateOrderNo() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateOrderNo()
})
}
// SetMaterialCode sets the "material_code" field.
func (u *OrderMaterialLedgerUpsertOne) SetMaterialCode(v string) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetMaterialCode(v)
})
}
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateMaterialCode() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateMaterialCode()
})
}
// SetMaterialName sets the "material_name" field.
func (u *OrderMaterialLedgerUpsertOne) SetMaterialName(v string) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetMaterialName(v)
})
}
// UpdateMaterialName sets the "material_name" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateMaterialName() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateMaterialName()
})
}
// ClearMaterialName clears the value of the "material_name" field.
func (u *OrderMaterialLedgerUpsertOne) ClearMaterialName() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.ClearMaterialName()
})
}
// SetTotalQty sets the "total_qty" field.
func (u *OrderMaterialLedgerUpsertOne) SetTotalQty(v int) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetTotalQty(v)
})
}
// AddTotalQty adds v to the "total_qty" field.
func (u *OrderMaterialLedgerUpsertOne) AddTotalQty(v int) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddTotalQty(v)
})
}
// UpdateTotalQty sets the "total_qty" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateTotalQty() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateTotalQty()
})
}
// SetOutQty sets the "out_qty" field.
func (u *OrderMaterialLedgerUpsertOne) SetOutQty(v int) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetOutQty(v)
})
}
// AddOutQty adds v to the "out_qty" field.
func (u *OrderMaterialLedgerUpsertOne) AddOutQty(v int) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddOutQty(v)
})
}
// UpdateOutQty sets the "out_qty" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateOutQty() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateOutQty()
})
}
// SetStatus sets the "status" field.
func (u *OrderMaterialLedgerUpsertOne) SetStatus(v string) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateStatus() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateStatus()
})
}
// SetRemark sets the "remark" field.
func (u *OrderMaterialLedgerUpsertOne) SetRemark(v string) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateRemark() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateRemark()
})
}
// ClearRemark clears the value of the "remark" field.
func (u *OrderMaterialLedgerUpsertOne) ClearRemark() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.ClearRemark()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *OrderMaterialLedgerUpsertOne) SetCreatedAt(v int64) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *OrderMaterialLedgerUpsertOne) AddCreatedAt(v int64) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateCreatedAt() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *OrderMaterialLedgerUpsertOne) SetUpdatedAt(v int64) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetUpdatedAt(v)
})
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *OrderMaterialLedgerUpsertOne) AddUpdatedAt(v int64) *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertOne) UpdateUpdatedAt() *OrderMaterialLedgerUpsertOne {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *OrderMaterialLedgerUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for OrderMaterialLedgerCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *OrderMaterialLedgerUpsertOne) 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 *OrderMaterialLedgerUpsertOne) 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 *OrderMaterialLedgerUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// OrderMaterialLedgerCreateBulk is the builder for creating many OrderMaterialLedger entities in bulk.
type OrderMaterialLedgerCreateBulk struct {
config
err error
builders []*OrderMaterialLedgerCreate
conflict []sql.ConflictOption
}
// Save creates the OrderMaterialLedger entities in the database.
func (_c *OrderMaterialLedgerCreateBulk) Save(ctx context.Context) ([]*OrderMaterialLedger, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*OrderMaterialLedger, 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.(*OrderMaterialLedgerMutation)
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 *OrderMaterialLedgerCreateBulk) SaveX(ctx context.Context) []*OrderMaterialLedger {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *OrderMaterialLedgerCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *OrderMaterialLedgerCreateBulk) 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.OrderMaterialLedger.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.OrderMaterialLedgerUpsert) {
// SetOrderNo(v+v).
// }).
// Exec(ctx)
func (_c *OrderMaterialLedgerCreateBulk) OnConflict(opts ...sql.ConflictOption) *OrderMaterialLedgerUpsertBulk {
_c.conflict = opts
return &OrderMaterialLedgerUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.OrderMaterialLedger.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *OrderMaterialLedgerCreateBulk) OnConflictColumns(columns ...string) *OrderMaterialLedgerUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &OrderMaterialLedgerUpsertBulk{
create: _c,
}
}
// OrderMaterialLedgerUpsertBulk is the builder for "upsert"-ing
// a bulk of OrderMaterialLedger nodes.
type OrderMaterialLedgerUpsertBulk struct {
create *OrderMaterialLedgerCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.OrderMaterialLedger.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *OrderMaterialLedgerUpsertBulk) UpdateNewValues() *OrderMaterialLedgerUpsertBulk {
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.OrderMaterialLedger.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *OrderMaterialLedgerUpsertBulk) Ignore() *OrderMaterialLedgerUpsertBulk {
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 *OrderMaterialLedgerUpsertBulk) DoNothing() *OrderMaterialLedgerUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the OrderMaterialLedgerCreateBulk.OnConflict
// documentation for more info.
func (u *OrderMaterialLedgerUpsertBulk) Update(set func(*OrderMaterialLedgerUpsert)) *OrderMaterialLedgerUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&OrderMaterialLedgerUpsert{UpdateSet: update})
}))
return u
}
// SetOrderNo sets the "order_no" field.
func (u *OrderMaterialLedgerUpsertBulk) SetOrderNo(v string) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetOrderNo(v)
})
}
// UpdateOrderNo sets the "order_no" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateOrderNo() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateOrderNo()
})
}
// SetMaterialCode sets the "material_code" field.
func (u *OrderMaterialLedgerUpsertBulk) SetMaterialCode(v string) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetMaterialCode(v)
})
}
// UpdateMaterialCode sets the "material_code" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateMaterialCode() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateMaterialCode()
})
}
// SetMaterialName sets the "material_name" field.
func (u *OrderMaterialLedgerUpsertBulk) SetMaterialName(v string) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetMaterialName(v)
})
}
// UpdateMaterialName sets the "material_name" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateMaterialName() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateMaterialName()
})
}
// ClearMaterialName clears the value of the "material_name" field.
func (u *OrderMaterialLedgerUpsertBulk) ClearMaterialName() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.ClearMaterialName()
})
}
// SetTotalQty sets the "total_qty" field.
func (u *OrderMaterialLedgerUpsertBulk) SetTotalQty(v int) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetTotalQty(v)
})
}
// AddTotalQty adds v to the "total_qty" field.
func (u *OrderMaterialLedgerUpsertBulk) AddTotalQty(v int) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddTotalQty(v)
})
}
// UpdateTotalQty sets the "total_qty" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateTotalQty() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateTotalQty()
})
}
// SetOutQty sets the "out_qty" field.
func (u *OrderMaterialLedgerUpsertBulk) SetOutQty(v int) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetOutQty(v)
})
}
// AddOutQty adds v to the "out_qty" field.
func (u *OrderMaterialLedgerUpsertBulk) AddOutQty(v int) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddOutQty(v)
})
}
// UpdateOutQty sets the "out_qty" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateOutQty() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateOutQty()
})
}
// SetStatus sets the "status" field.
func (u *OrderMaterialLedgerUpsertBulk) SetStatus(v string) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateStatus() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateStatus()
})
}
// SetRemark sets the "remark" field.
func (u *OrderMaterialLedgerUpsertBulk) SetRemark(v string) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateRemark() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateRemark()
})
}
// ClearRemark clears the value of the "remark" field.
func (u *OrderMaterialLedgerUpsertBulk) ClearRemark() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.ClearRemark()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *OrderMaterialLedgerUpsertBulk) SetCreatedAt(v int64) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *OrderMaterialLedgerUpsertBulk) AddCreatedAt(v int64) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateCreatedAt() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *OrderMaterialLedgerUpsertBulk) SetUpdatedAt(v int64) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.SetUpdatedAt(v)
})
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *OrderMaterialLedgerUpsertBulk) AddUpdatedAt(v int64) *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.AddUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *OrderMaterialLedgerUpsertBulk) UpdateUpdatedAt() *OrderMaterialLedgerUpsertBulk {
return u.Update(func(s *OrderMaterialLedgerUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *OrderMaterialLedgerUpsertBulk) 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 OrderMaterialLedgerCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for OrderMaterialLedgerCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *OrderMaterialLedgerUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}