280 lines
8.1 KiB
Go
280 lines
8.1 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"online-order/ent/business"
|
||
|
"online-order/ent/businessconfig"
|
||
|
"online-order/ent/schema"
|
||
|
|
||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
)
|
||
|
|
||
|
// BusinessConfigCreate is the builder for creating a BusinessConfig entity.
|
||
|
type BusinessConfigCreate struct {
|
||
|
config
|
||
|
mutation *BusinessConfigMutation
|
||
|
hooks []Hook
|
||
|
}
|
||
|
|
||
|
// SetCompany sets the "company" field.
|
||
|
func (bcc *BusinessConfigCreate) SetCompany(s string) *BusinessConfigCreate {
|
||
|
bcc.mutation.SetCompany(s)
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetNillableCompany sets the "company" field if the given value is not nil.
|
||
|
func (bcc *BusinessConfigCreate) SetNillableCompany(s *string) *BusinessConfigCreate {
|
||
|
if s != nil {
|
||
|
bcc.SetCompany(*s)
|
||
|
}
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetAuthConfig sets the "auth_config" field.
|
||
|
func (bcc *BusinessConfigCreate) SetAuthConfig(sc schema.AuthConfig) *BusinessConfigCreate {
|
||
|
bcc.mutation.SetAuthConfig(sc)
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetConfig sets the "config" field.
|
||
|
func (bcc *BusinessConfigCreate) SetConfig(s []string) *BusinessConfigCreate {
|
||
|
bcc.mutation.SetConfig(s)
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetBusinessID sets the "business_id" field.
|
||
|
func (bcc *BusinessConfigCreate) SetBusinessID(i int) *BusinessConfigCreate {
|
||
|
bcc.mutation.SetBusinessID(i)
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetNillableBusinessID sets the "business_id" field if the given value is not nil.
|
||
|
func (bcc *BusinessConfigCreate) SetNillableBusinessID(i *int) *BusinessConfigCreate {
|
||
|
if i != nil {
|
||
|
bcc.SetBusinessID(*i)
|
||
|
}
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetBusinessesID sets the "businesses" edge to the Business entity by ID.
|
||
|
func (bcc *BusinessConfigCreate) SetBusinessesID(id int) *BusinessConfigCreate {
|
||
|
bcc.mutation.SetBusinessesID(id)
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetNillableBusinessesID sets the "businesses" edge to the Business entity by ID if the given value is not nil.
|
||
|
func (bcc *BusinessConfigCreate) SetNillableBusinessesID(id *int) *BusinessConfigCreate {
|
||
|
if id != nil {
|
||
|
bcc = bcc.SetBusinessesID(*id)
|
||
|
}
|
||
|
return bcc
|
||
|
}
|
||
|
|
||
|
// SetBusinesses sets the "businesses" edge to the Business entity.
|
||
|
func (bcc *BusinessConfigCreate) SetBusinesses(b *Business) *BusinessConfigCreate {
|
||
|
return bcc.SetBusinessesID(b.ID)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the BusinessConfigMutation object of the builder.
|
||
|
func (bcc *BusinessConfigCreate) Mutation() *BusinessConfigMutation {
|
||
|
return bcc.mutation
|
||
|
}
|
||
|
|
||
|
// Save creates the BusinessConfig in the database.
|
||
|
func (bcc *BusinessConfigCreate) Save(ctx context.Context) (*BusinessConfig, error) {
|
||
|
bcc.defaults()
|
||
|
return withHooks(ctx, bcc.sqlSave, bcc.mutation, bcc.hooks)
|
||
|
}
|
||
|
|
||
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
func (bcc *BusinessConfigCreate) SaveX(ctx context.Context) *BusinessConfig {
|
||
|
v, err := bcc.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (bcc *BusinessConfigCreate) Exec(ctx context.Context) error {
|
||
|
_, err := bcc.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (bcc *BusinessConfigCreate) ExecX(ctx context.Context) {
|
||
|
if err := bcc.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (bcc *BusinessConfigCreate) defaults() {
|
||
|
if _, ok := bcc.mutation.Company(); !ok {
|
||
|
v := businessconfig.DefaultCompany
|
||
|
bcc.mutation.SetCompany(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (bcc *BusinessConfigCreate) check() error {
|
||
|
if _, ok := bcc.mutation.Company(); !ok {
|
||
|
return &ValidationError{Name: "company", err: errors.New(`ent: missing required field "BusinessConfig.company"`)}
|
||
|
}
|
||
|
if _, ok := bcc.mutation.AuthConfig(); !ok {
|
||
|
return &ValidationError{Name: "auth_config", err: errors.New(`ent: missing required field "BusinessConfig.auth_config"`)}
|
||
|
}
|
||
|
if _, ok := bcc.mutation.Config(); !ok {
|
||
|
return &ValidationError{Name: "config", err: errors.New(`ent: missing required field "BusinessConfig.config"`)}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (bcc *BusinessConfigCreate) sqlSave(ctx context.Context) (*BusinessConfig, error) {
|
||
|
if err := bcc.check(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
_node, _spec := bcc.createSpec()
|
||
|
if err := sqlgraph.CreateNode(ctx, bcc.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)
|
||
|
bcc.mutation.id = &_node.ID
|
||
|
bcc.mutation.done = true
|
||
|
return _node, nil
|
||
|
}
|
||
|
|
||
|
func (bcc *BusinessConfigCreate) createSpec() (*BusinessConfig, *sqlgraph.CreateSpec) {
|
||
|
var (
|
||
|
_node = &BusinessConfig{config: bcc.config}
|
||
|
_spec = sqlgraph.NewCreateSpec(businessconfig.Table, sqlgraph.NewFieldSpec(businessconfig.FieldID, field.TypeInt))
|
||
|
)
|
||
|
if value, ok := bcc.mutation.Company(); ok {
|
||
|
_spec.SetField(businessconfig.FieldCompany, field.TypeString, value)
|
||
|
_node.Company = value
|
||
|
}
|
||
|
if value, ok := bcc.mutation.AuthConfig(); ok {
|
||
|
_spec.SetField(businessconfig.FieldAuthConfig, field.TypeJSON, value)
|
||
|
_node.AuthConfig = value
|
||
|
}
|
||
|
if value, ok := bcc.mutation.Config(); ok {
|
||
|
_spec.SetField(businessconfig.FieldConfig, field.TypeJSON, value)
|
||
|
_node.Config = value
|
||
|
}
|
||
|
if nodes := bcc.mutation.BusinessesIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: businessconfig.BusinessesTable,
|
||
|
Columns: []string{businessconfig.BusinessesColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: sqlgraph.NewFieldSpec(business.FieldID, field.TypeInt),
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_node.BusinessID = &nodes[0]
|
||
|
_spec.Edges = append(_spec.Edges, edge)
|
||
|
}
|
||
|
return _node, _spec
|
||
|
}
|
||
|
|
||
|
// BusinessConfigCreateBulk is the builder for creating many BusinessConfig entities in bulk.
|
||
|
type BusinessConfigCreateBulk struct {
|
||
|
config
|
||
|
err error
|
||
|
builders []*BusinessConfigCreate
|
||
|
}
|
||
|
|
||
|
// Save creates the BusinessConfig entities in the database.
|
||
|
func (bccb *BusinessConfigCreateBulk) Save(ctx context.Context) ([]*BusinessConfig, error) {
|
||
|
if bccb.err != nil {
|
||
|
return nil, bccb.err
|
||
|
}
|
||
|
specs := make([]*sqlgraph.CreateSpec, len(bccb.builders))
|
||
|
nodes := make([]*BusinessConfig, len(bccb.builders))
|
||
|
mutators := make([]Mutator, len(bccb.builders))
|
||
|
for i := range bccb.builders {
|
||
|
func(i int, root context.Context) {
|
||
|
builder := bccb.builders[i]
|
||
|
builder.defaults()
|
||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
mutation, ok := m.(*BusinessConfigMutation)
|
||
|
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, bccb.builders[i+1].mutation)
|
||
|
} else {
|
||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||
|
if err = sqlgraph.BatchCreate(ctx, bccb.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, bccb.builders[0].mutation); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
return nodes, nil
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (bccb *BusinessConfigCreateBulk) SaveX(ctx context.Context) []*BusinessConfig {
|
||
|
v, err := bccb.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (bccb *BusinessConfigCreateBulk) Exec(ctx context.Context) error {
|
||
|
_, err := bccb.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (bccb *BusinessConfigCreateBulk) ExecX(ctx context.Context) {
|
||
|
if err := bccb.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|