Files

601 lines
17 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/sysconfig"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// SysConfigCreate is the builder for creating a SysConfig entity.
type SysConfigCreate struct {
config
mutation *SysConfigMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetKey sets the "key" field.
func (_c *SysConfigCreate) SetKey(v string) *SysConfigCreate {
_c.mutation.SetKey(v)
return _c
}
// SetValue sets the "value" field.
func (_c *SysConfigCreate) SetValue(v string) *SysConfigCreate {
_c.mutation.SetValue(v)
return _c
}
// SetRemark sets the "remark" field.
func (_c *SysConfigCreate) SetRemark(v string) *SysConfigCreate {
_c.mutation.SetRemark(v)
return _c
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_c *SysConfigCreate) SetNillableRemark(v *string) *SysConfigCreate {
if v != nil {
_c.SetRemark(*v)
}
return _c
}
// Mutation returns the SysConfigMutation object of the builder.
func (_c *SysConfigCreate) Mutation() *SysConfigMutation {
return _c.mutation
}
// Save creates the SysConfig in the database.
func (_c *SysConfigCreate) Save(ctx context.Context) (*SysConfig, error) {
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *SysConfigCreate) SaveX(ctx context.Context) *SysConfig {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SysConfigCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SysConfigCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *SysConfigCreate) check() error {
if _, ok := _c.mutation.Key(); !ok {
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "SysConfig.key"`)}
}
if v, ok := _c.mutation.Key(); ok {
if err := sysconfig.KeyValidator(v); err != nil {
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "SysConfig.key": %w`, err)}
}
}
if _, ok := _c.mutation.Value(); !ok {
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "SysConfig.value"`)}
}
if v, ok := _c.mutation.Value(); ok {
if err := sysconfig.ValueValidator(v); err != nil {
return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "SysConfig.value": %w`, err)}
}
}
if v, ok := _c.mutation.Remark(); ok {
if err := sysconfig.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "SysConfig.remark": %w`, err)}
}
}
return nil
}
func (_c *SysConfigCreate) sqlSave(ctx context.Context) (*SysConfig, 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 *SysConfigCreate) createSpec() (*SysConfig, *sqlgraph.CreateSpec) {
var (
_node = &SysConfig{config: _c.config}
_spec = sqlgraph.NewCreateSpec(sysconfig.Table, sqlgraph.NewFieldSpec(sysconfig.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.Key(); ok {
_spec.SetField(sysconfig.FieldKey, field.TypeString, value)
_node.Key = value
}
if value, ok := _c.mutation.Value(); ok {
_spec.SetField(sysconfig.FieldValue, field.TypeString, value)
_node.Value = value
}
if value, ok := _c.mutation.Remark(); ok {
_spec.SetField(sysconfig.FieldRemark, field.TypeString, value)
_node.Remark = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.SysConfig.Create().
// SetKey(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.SysConfigUpsert) {
// SetKey(v+v).
// }).
// Exec(ctx)
func (_c *SysConfigCreate) OnConflict(opts ...sql.ConflictOption) *SysConfigUpsertOne {
_c.conflict = opts
return &SysConfigUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.SysConfig.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *SysConfigCreate) OnConflictColumns(columns ...string) *SysConfigUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &SysConfigUpsertOne{
create: _c,
}
}
type (
// SysConfigUpsertOne is the builder for "upsert"-ing
// one SysConfig node.
SysConfigUpsertOne struct {
create *SysConfigCreate
}
// SysConfigUpsert is the "OnConflict" setter.
SysConfigUpsert struct {
*sql.UpdateSet
}
)
// SetKey sets the "key" field.
func (u *SysConfigUpsert) SetKey(v string) *SysConfigUpsert {
u.Set(sysconfig.FieldKey, v)
return u
}
// UpdateKey sets the "key" field to the value that was provided on create.
func (u *SysConfigUpsert) UpdateKey() *SysConfigUpsert {
u.SetExcluded(sysconfig.FieldKey)
return u
}
// SetValue sets the "value" field.
func (u *SysConfigUpsert) SetValue(v string) *SysConfigUpsert {
u.Set(sysconfig.FieldValue, v)
return u
}
// UpdateValue sets the "value" field to the value that was provided on create.
func (u *SysConfigUpsert) UpdateValue() *SysConfigUpsert {
u.SetExcluded(sysconfig.FieldValue)
return u
}
// SetRemark sets the "remark" field.
func (u *SysConfigUpsert) SetRemark(v string) *SysConfigUpsert {
u.Set(sysconfig.FieldRemark, v)
return u
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *SysConfigUpsert) UpdateRemark() *SysConfigUpsert {
u.SetExcluded(sysconfig.FieldRemark)
return u
}
// ClearRemark clears the value of the "remark" field.
func (u *SysConfigUpsert) ClearRemark() *SysConfigUpsert {
u.SetNull(sysconfig.FieldRemark)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.SysConfig.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *SysConfigUpsertOne) UpdateNewValues() *SysConfigUpsertOne {
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.SysConfig.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *SysConfigUpsertOne) Ignore() *SysConfigUpsertOne {
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 *SysConfigUpsertOne) DoNothing() *SysConfigUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the SysConfigCreate.OnConflict
// documentation for more info.
func (u *SysConfigUpsertOne) Update(set func(*SysConfigUpsert)) *SysConfigUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&SysConfigUpsert{UpdateSet: update})
}))
return u
}
// SetKey sets the "key" field.
func (u *SysConfigUpsertOne) SetKey(v string) *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.SetKey(v)
})
}
// UpdateKey sets the "key" field to the value that was provided on create.
func (u *SysConfigUpsertOne) UpdateKey() *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.UpdateKey()
})
}
// SetValue sets the "value" field.
func (u *SysConfigUpsertOne) SetValue(v string) *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.SetValue(v)
})
}
// UpdateValue sets the "value" field to the value that was provided on create.
func (u *SysConfigUpsertOne) UpdateValue() *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.UpdateValue()
})
}
// SetRemark sets the "remark" field.
func (u *SysConfigUpsertOne) SetRemark(v string) *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *SysConfigUpsertOne) UpdateRemark() *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.UpdateRemark()
})
}
// ClearRemark clears the value of the "remark" field.
func (u *SysConfigUpsertOne) ClearRemark() *SysConfigUpsertOne {
return u.Update(func(s *SysConfigUpsert) {
s.ClearRemark()
})
}
// Exec executes the query.
func (u *SysConfigUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for SysConfigCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *SysConfigUpsertOne) 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 *SysConfigUpsertOne) 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 *SysConfigUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// SysConfigCreateBulk is the builder for creating many SysConfig entities in bulk.
type SysConfigCreateBulk struct {
config
err error
builders []*SysConfigCreate
conflict []sql.ConflictOption
}
// Save creates the SysConfig entities in the database.
func (_c *SysConfigCreateBulk) Save(ctx context.Context) ([]*SysConfig, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*SysConfig, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*SysConfigMutation)
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 *SysConfigCreateBulk) SaveX(ctx context.Context) []*SysConfig {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SysConfigCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SysConfigCreateBulk) 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.SysConfig.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.SysConfigUpsert) {
// SetKey(v+v).
// }).
// Exec(ctx)
func (_c *SysConfigCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysConfigUpsertBulk {
_c.conflict = opts
return &SysConfigUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.SysConfig.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *SysConfigCreateBulk) OnConflictColumns(columns ...string) *SysConfigUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &SysConfigUpsertBulk{
create: _c,
}
}
// SysConfigUpsertBulk is the builder for "upsert"-ing
// a bulk of SysConfig nodes.
type SysConfigUpsertBulk struct {
create *SysConfigCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.SysConfig.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *SysConfigUpsertBulk) UpdateNewValues() *SysConfigUpsertBulk {
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.SysConfig.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *SysConfigUpsertBulk) Ignore() *SysConfigUpsertBulk {
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 *SysConfigUpsertBulk) DoNothing() *SysConfigUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the SysConfigCreateBulk.OnConflict
// documentation for more info.
func (u *SysConfigUpsertBulk) Update(set func(*SysConfigUpsert)) *SysConfigUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&SysConfigUpsert{UpdateSet: update})
}))
return u
}
// SetKey sets the "key" field.
func (u *SysConfigUpsertBulk) SetKey(v string) *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.SetKey(v)
})
}
// UpdateKey sets the "key" field to the value that was provided on create.
func (u *SysConfigUpsertBulk) UpdateKey() *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.UpdateKey()
})
}
// SetValue sets the "value" field.
func (u *SysConfigUpsertBulk) SetValue(v string) *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.SetValue(v)
})
}
// UpdateValue sets the "value" field to the value that was provided on create.
func (u *SysConfigUpsertBulk) UpdateValue() *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.UpdateValue()
})
}
// SetRemark sets the "remark" field.
func (u *SysConfigUpsertBulk) SetRemark(v string) *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *SysConfigUpsertBulk) UpdateRemark() *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.UpdateRemark()
})
}
// ClearRemark clears the value of the "remark" field.
func (u *SysConfigUpsertBulk) ClearRemark() *SysConfigUpsertBulk {
return u.Update(func(s *SysConfigUpsert) {
s.ClearRemark()
})
}
// Exec executes the query.
func (u *SysConfigUpsertBulk) 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 SysConfigCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for SysConfigCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *SysConfigUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}