mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 19:47:47 +08:00
first draft version
This commit is contained in:
235
ent/indexers_create.go
Normal file
235
ent/indexers_create.go
Normal file
@@ -0,0 +1,235 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/indexers"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// IndexersCreate is the builder for creating a Indexers entity.
|
||||
type IndexersCreate struct {
|
||||
config
|
||||
mutation *IndexersMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (ic *IndexersCreate) SetName(s string) *IndexersCreate {
|
||||
ic.mutation.SetName(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetImplementation sets the "implementation" field.
|
||||
func (ic *IndexersCreate) SetImplementation(s string) *IndexersCreate {
|
||||
ic.mutation.SetImplementation(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetSettings sets the "settings" field.
|
||||
func (ic *IndexersCreate) SetSettings(s string) *IndexersCreate {
|
||||
ic.mutation.SetSettings(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetEnableRss sets the "enable_rss" field.
|
||||
func (ic *IndexersCreate) SetEnableRss(b bool) *IndexersCreate {
|
||||
ic.mutation.SetEnableRss(b)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetPriority sets the "priority" field.
|
||||
func (ic *IndexersCreate) SetPriority(i int) *IndexersCreate {
|
||||
ic.mutation.SetPriority(i)
|
||||
return ic
|
||||
}
|
||||
|
||||
// Mutation returns the IndexersMutation object of the builder.
|
||||
func (ic *IndexersCreate) Mutation() *IndexersMutation {
|
||||
return ic.mutation
|
||||
}
|
||||
|
||||
// Save creates the Indexers in the database.
|
||||
func (ic *IndexersCreate) Save(ctx context.Context) (*Indexers, error) {
|
||||
return withHooks(ctx, ic.sqlSave, ic.mutation, ic.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (ic *IndexersCreate) SaveX(ctx context.Context) *Indexers {
|
||||
v, err := ic.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ic *IndexersCreate) Exec(ctx context.Context) error {
|
||||
_, err := ic.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ic *IndexersCreate) ExecX(ctx context.Context) {
|
||||
if err := ic.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ic *IndexersCreate) check() error {
|
||||
if _, ok := ic.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Indexers.name"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.Implementation(); !ok {
|
||||
return &ValidationError{Name: "implementation", err: errors.New(`ent: missing required field "Indexers.implementation"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.Settings(); !ok {
|
||||
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "Indexers.settings"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.EnableRss(); !ok {
|
||||
return &ValidationError{Name: "enable_rss", err: errors.New(`ent: missing required field "Indexers.enable_rss"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.Priority(); !ok {
|
||||
return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "Indexers.priority"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ic *IndexersCreate) sqlSave(ctx context.Context) (*Indexers, error) {
|
||||
if err := ic.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := ic.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, ic.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)
|
||||
ic.mutation.id = &_node.ID
|
||||
ic.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (ic *IndexersCreate) createSpec() (*Indexers, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Indexers{config: ic.config}
|
||||
_spec = sqlgraph.NewCreateSpec(indexers.Table, sqlgraph.NewFieldSpec(indexers.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := ic.mutation.Name(); ok {
|
||||
_spec.SetField(indexers.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := ic.mutation.Implementation(); ok {
|
||||
_spec.SetField(indexers.FieldImplementation, field.TypeString, value)
|
||||
_node.Implementation = value
|
||||
}
|
||||
if value, ok := ic.mutation.Settings(); ok {
|
||||
_spec.SetField(indexers.FieldSettings, field.TypeString, value)
|
||||
_node.Settings = value
|
||||
}
|
||||
if value, ok := ic.mutation.EnableRss(); ok {
|
||||
_spec.SetField(indexers.FieldEnableRss, field.TypeBool, value)
|
||||
_node.EnableRss = value
|
||||
}
|
||||
if value, ok := ic.mutation.Priority(); ok {
|
||||
_spec.SetField(indexers.FieldPriority, field.TypeInt, value)
|
||||
_node.Priority = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// IndexersCreateBulk is the builder for creating many Indexers entities in bulk.
|
||||
type IndexersCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*IndexersCreate
|
||||
}
|
||||
|
||||
// Save creates the Indexers entities in the database.
|
||||
func (icb *IndexersCreateBulk) Save(ctx context.Context) ([]*Indexers, error) {
|
||||
if icb.err != nil {
|
||||
return nil, icb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(icb.builders))
|
||||
nodes := make([]*Indexers, len(icb.builders))
|
||||
mutators := make([]Mutator, len(icb.builders))
|
||||
for i := range icb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := icb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*IndexersMutation)
|
||||
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, icb.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, icb.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, icb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (icb *IndexersCreateBulk) SaveX(ctx context.Context) []*Indexers {
|
||||
v, err := icb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (icb *IndexersCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := icb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (icb *IndexersCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := icb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user