234 lines
6.2 KiB
Go
234 lines
6.2 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"thesis/ent/key"
|
|
"thesis/ent/validators"
|
|
"thesis/ent/whitelist"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// WhiteListCreate is the builder for creating a WhiteList entity.
|
|
type WhiteListCreate struct {
|
|
config
|
|
mutation *WhiteListMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// AddSponsorIDs adds the "Sponsor" edge to the Validators entity by IDs.
|
|
func (wlc *WhiteListCreate) AddSponsorIDs(ids ...int) *WhiteListCreate {
|
|
wlc.mutation.AddSponsorIDs(ids...)
|
|
return wlc
|
|
}
|
|
|
|
// AddSponsor adds the "Sponsor" edges to the Validators entity.
|
|
func (wlc *WhiteListCreate) AddSponsor(v ...*Validators) *WhiteListCreate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return wlc.AddSponsorIDs(ids...)
|
|
}
|
|
|
|
// AddAccountIDs adds the "Account" edge to the Key entity by IDs.
|
|
func (wlc *WhiteListCreate) AddAccountIDs(ids ...int) *WhiteListCreate {
|
|
wlc.mutation.AddAccountIDs(ids...)
|
|
return wlc
|
|
}
|
|
|
|
// AddAccount adds the "Account" edges to the Key entity.
|
|
func (wlc *WhiteListCreate) AddAccount(k ...*Key) *WhiteListCreate {
|
|
ids := make([]int, len(k))
|
|
for i := range k {
|
|
ids[i] = k[i].ID
|
|
}
|
|
return wlc.AddAccountIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the WhiteListMutation object of the builder.
|
|
func (wlc *WhiteListCreate) Mutation() *WhiteListMutation {
|
|
return wlc.mutation
|
|
}
|
|
|
|
// Save creates the WhiteList in the database.
|
|
func (wlc *WhiteListCreate) Save(ctx context.Context) (*WhiteList, error) {
|
|
return withHooks(ctx, wlc.sqlSave, wlc.mutation, wlc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (wlc *WhiteListCreate) SaveX(ctx context.Context) *WhiteList {
|
|
v, err := wlc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wlc *WhiteListCreate) Exec(ctx context.Context) error {
|
|
_, err := wlc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wlc *WhiteListCreate) ExecX(ctx context.Context) {
|
|
if err := wlc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (wlc *WhiteListCreate) check() error {
|
|
return nil
|
|
}
|
|
|
|
func (wlc *WhiteListCreate) sqlSave(ctx context.Context) (*WhiteList, error) {
|
|
if err := wlc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := wlc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, wlc.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)
|
|
wlc.mutation.id = &_node.ID
|
|
wlc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (wlc *WhiteListCreate) createSpec() (*WhiteList, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &WhiteList{config: wlc.config}
|
|
_spec = sqlgraph.NewCreateSpec(whitelist.Table, sqlgraph.NewFieldSpec(whitelist.FieldID, field.TypeInt))
|
|
)
|
|
if nodes := wlc.mutation.SponsorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := wlc.mutation.AccountIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// WhiteListCreateBulk is the builder for creating many WhiteList entities in bulk.
|
|
type WhiteListCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*WhiteListCreate
|
|
}
|
|
|
|
// Save creates the WhiteList entities in the database.
|
|
func (wlcb *WhiteListCreateBulk) Save(ctx context.Context) ([]*WhiteList, error) {
|
|
if wlcb.err != nil {
|
|
return nil, wlcb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(wlcb.builders))
|
|
nodes := make([]*WhiteList, len(wlcb.builders))
|
|
mutators := make([]Mutator, len(wlcb.builders))
|
|
for i := range wlcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := wlcb.builders[i]
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*WhiteListMutation)
|
|
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, wlcb.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, wlcb.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, wlcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wlcb *WhiteListCreateBulk) SaveX(ctx context.Context) []*WhiteList {
|
|
v, err := wlcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wlcb *WhiteListCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := wlcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wlcb *WhiteListCreateBulk) ExecX(ctx context.Context) {
|
|
if err := wlcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|