// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_wms/ent/inventorybatch" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // InventoryBatchCreate is the builder for creating a InventoryBatch entity. type InventoryBatchCreate struct { config mutation *InventoryBatchMutation hooks []Hook conflict []sql.ConflictOption } // SetBatchNo sets the "batch_no" field. func (_c *InventoryBatchCreate) SetBatchNo(v string) *InventoryBatchCreate { _c.mutation.SetBatchNo(v) return _c } // SetMaterialCode sets the "material_code" field. func (_c *InventoryBatchCreate) SetMaterialCode(v string) *InventoryBatchCreate { _c.mutation.SetMaterialCode(v) return _c } // SetMaterialName sets the "material_name" field. func (_c *InventoryBatchCreate) SetMaterialName(v string) *InventoryBatchCreate { _c.mutation.SetMaterialName(v) return _c } // SetNillableMaterialName sets the "material_name" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableMaterialName(v *string) *InventoryBatchCreate { if v != nil { _c.SetMaterialName(*v) } return _c } // SetQuantity sets the "quantity" field. func (_c *InventoryBatchCreate) SetQuantity(v int) *InventoryBatchCreate { _c.mutation.SetQuantity(v) return _c } // SetNillableQuantity sets the "quantity" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableQuantity(v *int) *InventoryBatchCreate { if v != nil { _c.SetQuantity(*v) } return _c } // SetLockedQty sets the "locked_qty" field. func (_c *InventoryBatchCreate) SetLockedQty(v int) *InventoryBatchCreate { _c.mutation.SetLockedQty(v) return _c } // SetNillableLockedQty sets the "locked_qty" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableLockedQty(v *int) *InventoryBatchCreate { if v != nil { _c.SetLockedQty(*v) } return _c } // SetProductionDate sets the "production_date" field. func (_c *InventoryBatchCreate) SetProductionDate(v string) *InventoryBatchCreate { _c.mutation.SetProductionDate(v) return _c } // SetNillableProductionDate sets the "production_date" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableProductionDate(v *string) *InventoryBatchCreate { if v != nil { _c.SetProductionDate(*v) } return _c } // SetSupplier sets the "supplier" field. func (_c *InventoryBatchCreate) SetSupplier(v string) *InventoryBatchCreate { _c.mutation.SetSupplier(v) return _c } // SetNillableSupplier sets the "supplier" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableSupplier(v *string) *InventoryBatchCreate { if v != nil { _c.SetSupplier(*v) } return _c } // SetQualityStatus sets the "quality_status" field. func (_c *InventoryBatchCreate) SetQualityStatus(v string) *InventoryBatchCreate { _c.mutation.SetQualityStatus(v) return _c } // SetNillableQualityStatus sets the "quality_status" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableQualityStatus(v *string) *InventoryBatchCreate { if v != nil { _c.SetQualityStatus(*v) } return _c } // SetZoneCode sets the "zone_code" field. func (_c *InventoryBatchCreate) SetZoneCode(v string) *InventoryBatchCreate { _c.mutation.SetZoneCode(v) return _c } // SetNillableZoneCode sets the "zone_code" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableZoneCode(v *string) *InventoryBatchCreate { if v != nil { _c.SetZoneCode(*v) } return _c } // SetRemark sets the "remark" field. func (_c *InventoryBatchCreate) SetRemark(v string) *InventoryBatchCreate { _c.mutation.SetRemark(v) return _c } // SetNillableRemark sets the "remark" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableRemark(v *string) *InventoryBatchCreate { if v != nil { _c.SetRemark(*v) } return _c } // SetCreatedAt sets the "created_at" field. func (_c *InventoryBatchCreate) SetCreatedAt(v int64) *InventoryBatchCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableCreatedAt(v *int64) *InventoryBatchCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *InventoryBatchCreate) SetUpdatedAt(v int64) *InventoryBatchCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *InventoryBatchCreate) SetNillableUpdatedAt(v *int64) *InventoryBatchCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // Mutation returns the InventoryBatchMutation object of the builder. func (_c *InventoryBatchCreate) Mutation() *InventoryBatchMutation { return _c.mutation } // Save creates the InventoryBatch in the database. func (_c *InventoryBatchCreate) Save(ctx context.Context) (*InventoryBatch, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *InventoryBatchCreate) SaveX(ctx context.Context) *InventoryBatch { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *InventoryBatchCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *InventoryBatchCreate) 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 *InventoryBatchCreate) defaults() { if _, ok := _c.mutation.Quantity(); !ok { v := inventorybatch.DefaultQuantity _c.mutation.SetQuantity(v) } if _, ok := _c.mutation.LockedQty(); !ok { v := inventorybatch.DefaultLockedQty _c.mutation.SetLockedQty(v) } if _, ok := _c.mutation.QualityStatus(); !ok { v := inventorybatch.DefaultQualityStatus _c.mutation.SetQualityStatus(v) } if _, ok := _c.mutation.CreatedAt(); !ok { v := inventorybatch.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := inventorybatch.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *InventoryBatchCreate) check() error { if _, ok := _c.mutation.BatchNo(); !ok { return &ValidationError{Name: "batch_no", err: errors.New(`ent: missing required field "InventoryBatch.batch_no"`)} } if _, ok := _c.mutation.MaterialCode(); !ok { return &ValidationError{Name: "material_code", err: errors.New(`ent: missing required field "InventoryBatch.material_code"`)} } if _, ok := _c.mutation.Quantity(); !ok { return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "InventoryBatch.quantity"`)} } if _, ok := _c.mutation.LockedQty(); !ok { return &ValidationError{Name: "locked_qty", err: errors.New(`ent: missing required field "InventoryBatch.locked_qty"`)} } if _, ok := _c.mutation.QualityStatus(); !ok { return &ValidationError{Name: "quality_status", err: errors.New(`ent: missing required field "InventoryBatch.quality_status"`)} } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "InventoryBatch.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "InventoryBatch.updated_at"`)} } return nil } func (_c *InventoryBatchCreate) sqlSave(ctx context.Context) (*InventoryBatch, 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 *InventoryBatchCreate) createSpec() (*InventoryBatch, *sqlgraph.CreateSpec) { var ( _node = &InventoryBatch{config: _c.config} _spec = sqlgraph.NewCreateSpec(inventorybatch.Table, sqlgraph.NewFieldSpec(inventorybatch.FieldID, field.TypeInt)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.BatchNo(); ok { _spec.SetField(inventorybatch.FieldBatchNo, field.TypeString, value) _node.BatchNo = value } if value, ok := _c.mutation.MaterialCode(); ok { _spec.SetField(inventorybatch.FieldMaterialCode, field.TypeString, value) _node.MaterialCode = value } if value, ok := _c.mutation.MaterialName(); ok { _spec.SetField(inventorybatch.FieldMaterialName, field.TypeString, value) _node.MaterialName = value } if value, ok := _c.mutation.Quantity(); ok { _spec.SetField(inventorybatch.FieldQuantity, field.TypeInt, value) _node.Quantity = value } if value, ok := _c.mutation.LockedQty(); ok { _spec.SetField(inventorybatch.FieldLockedQty, field.TypeInt, value) _node.LockedQty = value } if value, ok := _c.mutation.ProductionDate(); ok { _spec.SetField(inventorybatch.FieldProductionDate, field.TypeString, value) _node.ProductionDate = value } if value, ok := _c.mutation.Supplier(); ok { _spec.SetField(inventorybatch.FieldSupplier, field.TypeString, value) _node.Supplier = value } if value, ok := _c.mutation.QualityStatus(); ok { _spec.SetField(inventorybatch.FieldQualityStatus, field.TypeString, value) _node.QualityStatus = value } if value, ok := _c.mutation.ZoneCode(); ok { _spec.SetField(inventorybatch.FieldZoneCode, field.TypeString, value) _node.ZoneCode = value } if value, ok := _c.mutation.Remark(); ok { _spec.SetField(inventorybatch.FieldRemark, field.TypeString, value) _node.Remark = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(inventorybatch.FieldCreatedAt, field.TypeInt64, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(inventorybatch.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.InventoryBatch.Create(). // SetBatchNo(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.InventoryBatchUpsert) { // SetBatchNo(v+v). // }). // Exec(ctx) func (_c *InventoryBatchCreate) OnConflict(opts ...sql.ConflictOption) *InventoryBatchUpsertOne { _c.conflict = opts return &InventoryBatchUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.InventoryBatch.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *InventoryBatchCreate) OnConflictColumns(columns ...string) *InventoryBatchUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &InventoryBatchUpsertOne{ create: _c, } } type ( // InventoryBatchUpsertOne is the builder for "upsert"-ing // one InventoryBatch node. InventoryBatchUpsertOne struct { create *InventoryBatchCreate } // InventoryBatchUpsert is the "OnConflict" setter. InventoryBatchUpsert struct { *sql.UpdateSet } ) // SetBatchNo sets the "batch_no" field. func (u *InventoryBatchUpsert) SetBatchNo(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldBatchNo, v) return u } // UpdateBatchNo sets the "batch_no" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateBatchNo() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldBatchNo) return u } // SetMaterialCode sets the "material_code" field. func (u *InventoryBatchUpsert) SetMaterialCode(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldMaterialCode, v) return u } // UpdateMaterialCode sets the "material_code" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateMaterialCode() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldMaterialCode) return u } // SetMaterialName sets the "material_name" field. func (u *InventoryBatchUpsert) SetMaterialName(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldMaterialName, v) return u } // UpdateMaterialName sets the "material_name" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateMaterialName() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldMaterialName) return u } // ClearMaterialName clears the value of the "material_name" field. func (u *InventoryBatchUpsert) ClearMaterialName() *InventoryBatchUpsert { u.SetNull(inventorybatch.FieldMaterialName) return u } // SetQuantity sets the "quantity" field. func (u *InventoryBatchUpsert) SetQuantity(v int) *InventoryBatchUpsert { u.Set(inventorybatch.FieldQuantity, v) return u } // UpdateQuantity sets the "quantity" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateQuantity() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldQuantity) return u } // AddQuantity adds v to the "quantity" field. func (u *InventoryBatchUpsert) AddQuantity(v int) *InventoryBatchUpsert { u.Add(inventorybatch.FieldQuantity, v) return u } // SetLockedQty sets the "locked_qty" field. func (u *InventoryBatchUpsert) SetLockedQty(v int) *InventoryBatchUpsert { u.Set(inventorybatch.FieldLockedQty, v) return u } // UpdateLockedQty sets the "locked_qty" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateLockedQty() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldLockedQty) return u } // AddLockedQty adds v to the "locked_qty" field. func (u *InventoryBatchUpsert) AddLockedQty(v int) *InventoryBatchUpsert { u.Add(inventorybatch.FieldLockedQty, v) return u } // SetProductionDate sets the "production_date" field. func (u *InventoryBatchUpsert) SetProductionDate(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldProductionDate, v) return u } // UpdateProductionDate sets the "production_date" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateProductionDate() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldProductionDate) return u } // ClearProductionDate clears the value of the "production_date" field. func (u *InventoryBatchUpsert) ClearProductionDate() *InventoryBatchUpsert { u.SetNull(inventorybatch.FieldProductionDate) return u } // SetSupplier sets the "supplier" field. func (u *InventoryBatchUpsert) SetSupplier(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldSupplier, v) return u } // UpdateSupplier sets the "supplier" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateSupplier() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldSupplier) return u } // ClearSupplier clears the value of the "supplier" field. func (u *InventoryBatchUpsert) ClearSupplier() *InventoryBatchUpsert { u.SetNull(inventorybatch.FieldSupplier) return u } // SetQualityStatus sets the "quality_status" field. func (u *InventoryBatchUpsert) SetQualityStatus(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldQualityStatus, v) return u } // UpdateQualityStatus sets the "quality_status" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateQualityStatus() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldQualityStatus) return u } // SetZoneCode sets the "zone_code" field. func (u *InventoryBatchUpsert) SetZoneCode(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldZoneCode, v) return u } // UpdateZoneCode sets the "zone_code" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateZoneCode() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldZoneCode) return u } // ClearZoneCode clears the value of the "zone_code" field. func (u *InventoryBatchUpsert) ClearZoneCode() *InventoryBatchUpsert { u.SetNull(inventorybatch.FieldZoneCode) return u } // SetRemark sets the "remark" field. func (u *InventoryBatchUpsert) SetRemark(v string) *InventoryBatchUpsert { u.Set(inventorybatch.FieldRemark, v) return u } // UpdateRemark sets the "remark" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateRemark() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldRemark) return u } // ClearRemark clears the value of the "remark" field. func (u *InventoryBatchUpsert) ClearRemark() *InventoryBatchUpsert { u.SetNull(inventorybatch.FieldRemark) return u } // SetCreatedAt sets the "created_at" field. func (u *InventoryBatchUpsert) SetCreatedAt(v int64) *InventoryBatchUpsert { u.Set(inventorybatch.FieldCreatedAt, v) return u } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateCreatedAt() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldCreatedAt) return u } // AddCreatedAt adds v to the "created_at" field. func (u *InventoryBatchUpsert) AddCreatedAt(v int64) *InventoryBatchUpsert { u.Add(inventorybatch.FieldCreatedAt, v) return u } // SetUpdatedAt sets the "updated_at" field. func (u *InventoryBatchUpsert) SetUpdatedAt(v int64) *InventoryBatchUpsert { u.Set(inventorybatch.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *InventoryBatchUpsert) UpdateUpdatedAt() *InventoryBatchUpsert { u.SetExcluded(inventorybatch.FieldUpdatedAt) return u } // AddUpdatedAt adds v to the "updated_at" field. func (u *InventoryBatchUpsert) AddUpdatedAt(v int64) *InventoryBatchUpsert { u.Add(inventorybatch.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.InventoryBatch.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *InventoryBatchUpsertOne) UpdateNewValues() *InventoryBatchUpsertOne { 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.InventoryBatch.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *InventoryBatchUpsertOne) Ignore() *InventoryBatchUpsertOne { 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 *InventoryBatchUpsertOne) DoNothing() *InventoryBatchUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the InventoryBatchCreate.OnConflict // documentation for more info. func (u *InventoryBatchUpsertOne) Update(set func(*InventoryBatchUpsert)) *InventoryBatchUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&InventoryBatchUpsert{UpdateSet: update}) })) return u } // SetBatchNo sets the "batch_no" field. func (u *InventoryBatchUpsertOne) SetBatchNo(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetBatchNo(v) }) } // UpdateBatchNo sets the "batch_no" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateBatchNo() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateBatchNo() }) } // SetMaterialCode sets the "material_code" field. func (u *InventoryBatchUpsertOne) SetMaterialCode(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetMaterialCode(v) }) } // UpdateMaterialCode sets the "material_code" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateMaterialCode() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateMaterialCode() }) } // SetMaterialName sets the "material_name" field. func (u *InventoryBatchUpsertOne) SetMaterialName(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetMaterialName(v) }) } // UpdateMaterialName sets the "material_name" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateMaterialName() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateMaterialName() }) } // ClearMaterialName clears the value of the "material_name" field. func (u *InventoryBatchUpsertOne) ClearMaterialName() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.ClearMaterialName() }) } // SetQuantity sets the "quantity" field. func (u *InventoryBatchUpsertOne) SetQuantity(v int) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetQuantity(v) }) } // AddQuantity adds v to the "quantity" field. func (u *InventoryBatchUpsertOne) AddQuantity(v int) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.AddQuantity(v) }) } // UpdateQuantity sets the "quantity" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateQuantity() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateQuantity() }) } // SetLockedQty sets the "locked_qty" field. func (u *InventoryBatchUpsertOne) SetLockedQty(v int) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetLockedQty(v) }) } // AddLockedQty adds v to the "locked_qty" field. func (u *InventoryBatchUpsertOne) AddLockedQty(v int) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.AddLockedQty(v) }) } // UpdateLockedQty sets the "locked_qty" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateLockedQty() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateLockedQty() }) } // SetProductionDate sets the "production_date" field. func (u *InventoryBatchUpsertOne) SetProductionDate(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetProductionDate(v) }) } // UpdateProductionDate sets the "production_date" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateProductionDate() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateProductionDate() }) } // ClearProductionDate clears the value of the "production_date" field. func (u *InventoryBatchUpsertOne) ClearProductionDate() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.ClearProductionDate() }) } // SetSupplier sets the "supplier" field. func (u *InventoryBatchUpsertOne) SetSupplier(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetSupplier(v) }) } // UpdateSupplier sets the "supplier" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateSupplier() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateSupplier() }) } // ClearSupplier clears the value of the "supplier" field. func (u *InventoryBatchUpsertOne) ClearSupplier() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.ClearSupplier() }) } // SetQualityStatus sets the "quality_status" field. func (u *InventoryBatchUpsertOne) SetQualityStatus(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetQualityStatus(v) }) } // UpdateQualityStatus sets the "quality_status" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateQualityStatus() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateQualityStatus() }) } // SetZoneCode sets the "zone_code" field. func (u *InventoryBatchUpsertOne) SetZoneCode(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetZoneCode(v) }) } // UpdateZoneCode sets the "zone_code" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateZoneCode() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateZoneCode() }) } // ClearZoneCode clears the value of the "zone_code" field. func (u *InventoryBatchUpsertOne) ClearZoneCode() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.ClearZoneCode() }) } // SetRemark sets the "remark" field. func (u *InventoryBatchUpsertOne) SetRemark(v string) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetRemark(v) }) } // UpdateRemark sets the "remark" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateRemark() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateRemark() }) } // ClearRemark clears the value of the "remark" field. func (u *InventoryBatchUpsertOne) ClearRemark() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.ClearRemark() }) } // SetCreatedAt sets the "created_at" field. func (u *InventoryBatchUpsertOne) SetCreatedAt(v int64) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetCreatedAt(v) }) } // AddCreatedAt adds v to the "created_at" field. func (u *InventoryBatchUpsertOne) AddCreatedAt(v int64) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.AddCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateCreatedAt() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateCreatedAt() }) } // SetUpdatedAt sets the "updated_at" field. func (u *InventoryBatchUpsertOne) SetUpdatedAt(v int64) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.SetUpdatedAt(v) }) } // AddUpdatedAt adds v to the "updated_at" field. func (u *InventoryBatchUpsertOne) AddUpdatedAt(v int64) *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.AddUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *InventoryBatchUpsertOne) UpdateUpdatedAt() *InventoryBatchUpsertOne { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *InventoryBatchUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for InventoryBatchCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *InventoryBatchUpsertOne) 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 *InventoryBatchUpsertOne) 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 *InventoryBatchUpsertOne) IDX(ctx context.Context) int { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // InventoryBatchCreateBulk is the builder for creating many InventoryBatch entities in bulk. type InventoryBatchCreateBulk struct { config err error builders []*InventoryBatchCreate conflict []sql.ConflictOption } // Save creates the InventoryBatch entities in the database. func (_c *InventoryBatchCreateBulk) Save(ctx context.Context) ([]*InventoryBatch, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*InventoryBatch, 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.(*InventoryBatchMutation) 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 *InventoryBatchCreateBulk) SaveX(ctx context.Context) []*InventoryBatch { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *InventoryBatchCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *InventoryBatchCreateBulk) 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.InventoryBatch.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.InventoryBatchUpsert) { // SetBatchNo(v+v). // }). // Exec(ctx) func (_c *InventoryBatchCreateBulk) OnConflict(opts ...sql.ConflictOption) *InventoryBatchUpsertBulk { _c.conflict = opts return &InventoryBatchUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.InventoryBatch.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *InventoryBatchCreateBulk) OnConflictColumns(columns ...string) *InventoryBatchUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &InventoryBatchUpsertBulk{ create: _c, } } // InventoryBatchUpsertBulk is the builder for "upsert"-ing // a bulk of InventoryBatch nodes. type InventoryBatchUpsertBulk struct { create *InventoryBatchCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.InventoryBatch.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *InventoryBatchUpsertBulk) UpdateNewValues() *InventoryBatchUpsertBulk { 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.InventoryBatch.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *InventoryBatchUpsertBulk) Ignore() *InventoryBatchUpsertBulk { 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 *InventoryBatchUpsertBulk) DoNothing() *InventoryBatchUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the InventoryBatchCreateBulk.OnConflict // documentation for more info. func (u *InventoryBatchUpsertBulk) Update(set func(*InventoryBatchUpsert)) *InventoryBatchUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&InventoryBatchUpsert{UpdateSet: update}) })) return u } // SetBatchNo sets the "batch_no" field. func (u *InventoryBatchUpsertBulk) SetBatchNo(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetBatchNo(v) }) } // UpdateBatchNo sets the "batch_no" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateBatchNo() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateBatchNo() }) } // SetMaterialCode sets the "material_code" field. func (u *InventoryBatchUpsertBulk) SetMaterialCode(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetMaterialCode(v) }) } // UpdateMaterialCode sets the "material_code" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateMaterialCode() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateMaterialCode() }) } // SetMaterialName sets the "material_name" field. func (u *InventoryBatchUpsertBulk) SetMaterialName(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetMaterialName(v) }) } // UpdateMaterialName sets the "material_name" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateMaterialName() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateMaterialName() }) } // ClearMaterialName clears the value of the "material_name" field. func (u *InventoryBatchUpsertBulk) ClearMaterialName() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.ClearMaterialName() }) } // SetQuantity sets the "quantity" field. func (u *InventoryBatchUpsertBulk) SetQuantity(v int) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetQuantity(v) }) } // AddQuantity adds v to the "quantity" field. func (u *InventoryBatchUpsertBulk) AddQuantity(v int) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.AddQuantity(v) }) } // UpdateQuantity sets the "quantity" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateQuantity() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateQuantity() }) } // SetLockedQty sets the "locked_qty" field. func (u *InventoryBatchUpsertBulk) SetLockedQty(v int) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetLockedQty(v) }) } // AddLockedQty adds v to the "locked_qty" field. func (u *InventoryBatchUpsertBulk) AddLockedQty(v int) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.AddLockedQty(v) }) } // UpdateLockedQty sets the "locked_qty" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateLockedQty() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateLockedQty() }) } // SetProductionDate sets the "production_date" field. func (u *InventoryBatchUpsertBulk) SetProductionDate(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetProductionDate(v) }) } // UpdateProductionDate sets the "production_date" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateProductionDate() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateProductionDate() }) } // ClearProductionDate clears the value of the "production_date" field. func (u *InventoryBatchUpsertBulk) ClearProductionDate() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.ClearProductionDate() }) } // SetSupplier sets the "supplier" field. func (u *InventoryBatchUpsertBulk) SetSupplier(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetSupplier(v) }) } // UpdateSupplier sets the "supplier" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateSupplier() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateSupplier() }) } // ClearSupplier clears the value of the "supplier" field. func (u *InventoryBatchUpsertBulk) ClearSupplier() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.ClearSupplier() }) } // SetQualityStatus sets the "quality_status" field. func (u *InventoryBatchUpsertBulk) SetQualityStatus(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetQualityStatus(v) }) } // UpdateQualityStatus sets the "quality_status" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateQualityStatus() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateQualityStatus() }) } // SetZoneCode sets the "zone_code" field. func (u *InventoryBatchUpsertBulk) SetZoneCode(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetZoneCode(v) }) } // UpdateZoneCode sets the "zone_code" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateZoneCode() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateZoneCode() }) } // ClearZoneCode clears the value of the "zone_code" field. func (u *InventoryBatchUpsertBulk) ClearZoneCode() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.ClearZoneCode() }) } // SetRemark sets the "remark" field. func (u *InventoryBatchUpsertBulk) SetRemark(v string) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetRemark(v) }) } // UpdateRemark sets the "remark" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateRemark() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateRemark() }) } // ClearRemark clears the value of the "remark" field. func (u *InventoryBatchUpsertBulk) ClearRemark() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.ClearRemark() }) } // SetCreatedAt sets the "created_at" field. func (u *InventoryBatchUpsertBulk) SetCreatedAt(v int64) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetCreatedAt(v) }) } // AddCreatedAt adds v to the "created_at" field. func (u *InventoryBatchUpsertBulk) AddCreatedAt(v int64) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.AddCreatedAt(v) }) } // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateCreatedAt() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateCreatedAt() }) } // SetUpdatedAt sets the "updated_at" field. func (u *InventoryBatchUpsertBulk) SetUpdatedAt(v int64) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.SetUpdatedAt(v) }) } // AddUpdatedAt adds v to the "updated_at" field. func (u *InventoryBatchUpsertBulk) AddUpdatedAt(v int64) *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.AddUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *InventoryBatchUpsertBulk) UpdateUpdatedAt() *InventoryBatchUpsertBulk { return u.Update(func(s *InventoryBatchUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *InventoryBatchUpsertBulk) 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 InventoryBatchCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for InventoryBatchCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *InventoryBatchUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }