294 lines
7.6 KiB
Go
294 lines
7.6 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"home-vue-go/internal/ent/contact"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ContactCreate is the builder for creating a Contact entity.
|
|
type ContactCreate struct {
|
|
config
|
|
mutation *ContactMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_c *ContactCreate) SetType(v string) *ContactCreate {
|
|
_c.mutation.SetType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetIcon sets the "icon" field.
|
|
func (_c *ContactCreate) SetIcon(v string) *ContactCreate {
|
|
_c.mutation.SetIcon(v)
|
|
return _c
|
|
}
|
|
|
|
// SetURL sets the "url" field.
|
|
func (_c *ContactCreate) SetURL(v string) *ContactCreate {
|
|
_c.mutation.SetURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableURL sets the "url" field if the given value is not nil.
|
|
func (_c *ContactCreate) SetNillableURL(v *string) *ContactCreate {
|
|
if v != nil {
|
|
_c.SetURL(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetQrCode sets the "qr_code" field.
|
|
func (_c *ContactCreate) SetQrCode(v string) *ContactCreate {
|
|
_c.mutation.SetQrCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableQrCode sets the "qr_code" field if the given value is not nil.
|
|
func (_c *ContactCreate) SetNillableQrCode(v *string) *ContactCreate {
|
|
if v != nil {
|
|
_c.SetQrCode(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetHoverColor sets the "hover_color" field.
|
|
func (_c *ContactCreate) SetHoverColor(v string) *ContactCreate {
|
|
_c.mutation.SetHoverColor(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableHoverColor sets the "hover_color" field if the given value is not nil.
|
|
func (_c *ContactCreate) SetNillableHoverColor(v *string) *ContactCreate {
|
|
if v != nil {
|
|
_c.SetHoverColor(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetSortOrder sets the "sort_order" field.
|
|
func (_c *ContactCreate) SetSortOrder(v int) *ContactCreate {
|
|
_c.mutation.SetSortOrder(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
|
|
func (_c *ContactCreate) SetNillableSortOrder(v *int) *ContactCreate {
|
|
if v != nil {
|
|
_c.SetSortOrder(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ContactCreate) SetID(v int) *ContactCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the ContactMutation object of the builder.
|
|
func (_c *ContactCreate) Mutation() *ContactMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Contact in the database.
|
|
func (_c *ContactCreate) Save(ctx context.Context) (*Contact, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ContactCreate) SaveX(ctx context.Context) *Contact {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ContactCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ContactCreate) 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 *ContactCreate) defaults() {
|
|
if _, ok := _c.mutation.SortOrder(); !ok {
|
|
v := contact.DefaultSortOrder
|
|
_c.mutation.SetSortOrder(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ContactCreate) check() error {
|
|
if _, ok := _c.mutation.GetType(); !ok {
|
|
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Contact.type"`)}
|
|
}
|
|
if _, ok := _c.mutation.Icon(); !ok {
|
|
return &ValidationError{Name: "icon", err: errors.New(`ent: missing required field "Contact.icon"`)}
|
|
}
|
|
if _, ok := _c.mutation.SortOrder(); !ok {
|
|
return &ValidationError{Name: "sort_order", err: errors.New(`ent: missing required field "Contact.sort_order"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ContactCreate) sqlSave(ctx context.Context) (*Contact, 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
|
|
}
|
|
if _spec.ID.Value != _node.ID {
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *ContactCreate) createSpec() (*Contact, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Contact{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(contact.Table, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeInt))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.GetType(); ok {
|
|
_spec.SetField(contact.FieldType, field.TypeString, value)
|
|
_node.Type = value
|
|
}
|
|
if value, ok := _c.mutation.Icon(); ok {
|
|
_spec.SetField(contact.FieldIcon, field.TypeString, value)
|
|
_node.Icon = value
|
|
}
|
|
if value, ok := _c.mutation.URL(); ok {
|
|
_spec.SetField(contact.FieldURL, field.TypeString, value)
|
|
_node.URL = value
|
|
}
|
|
if value, ok := _c.mutation.QrCode(); ok {
|
|
_spec.SetField(contact.FieldQrCode, field.TypeString, value)
|
|
_node.QrCode = value
|
|
}
|
|
if value, ok := _c.mutation.HoverColor(); ok {
|
|
_spec.SetField(contact.FieldHoverColor, field.TypeString, value)
|
|
_node.HoverColor = value
|
|
}
|
|
if value, ok := _c.mutation.SortOrder(); ok {
|
|
_spec.SetField(contact.FieldSortOrder, field.TypeInt, value)
|
|
_node.SortOrder = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// ContactCreateBulk is the builder for creating many Contact entities in bulk.
|
|
type ContactCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ContactCreate
|
|
}
|
|
|
|
// Save creates the Contact entities in the database.
|
|
func (_c *ContactCreateBulk) Save(ctx context.Context) ([]*Contact, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Contact, 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.(*ContactMutation)
|
|
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}
|
|
// 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 && nodes[i].ID == 0 {
|
|
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 *ContactCreateBulk) SaveX(ctx context.Context) []*Contact {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ContactCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ContactCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|