273 lines
7.2 KiB
Go
273 lines
7.2 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/socialmedia"
|
|
)
|
|
|
|
// SocialmediaCreate is the builder for creating a Socialmedia entity.
|
|
type SocialmediaCreate struct {
|
|
config
|
|
mutation *SocialmediaMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (sc *SocialmediaCreate) SetServerid(s string) *SocialmediaCreate {
|
|
sc.mutation.SetServerid(s)
|
|
return sc
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (sc *SocialmediaCreate) SetType(s string) *SocialmediaCreate {
|
|
sc.mutation.SetType(s)
|
|
return sc
|
|
}
|
|
|
|
// SetIdentificator sets the "identificator" field.
|
|
func (sc *SocialmediaCreate) SetIdentificator(s string) *SocialmediaCreate {
|
|
sc.mutation.SetIdentificator(s)
|
|
return sc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (sc *SocialmediaCreate) SetID(i int) *SocialmediaCreate {
|
|
sc.mutation.SetID(i)
|
|
return sc
|
|
}
|
|
|
|
// Mutation returns the SocialmediaMutation object of the builder.
|
|
func (sc *SocialmediaCreate) Mutation() *SocialmediaMutation {
|
|
return sc.mutation
|
|
}
|
|
|
|
// Save creates the Socialmedia in the database.
|
|
func (sc *SocialmediaCreate) Save(ctx context.Context) (*Socialmedia, error) {
|
|
var (
|
|
err error
|
|
node *Socialmedia
|
|
)
|
|
if len(sc.hooks) == 0 {
|
|
if err = sc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
node, err = sc.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SocialmediaMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err = sc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
sc.mutation = mutation
|
|
if node, err = sc.sqlSave(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &node.ID
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(sc.hooks) - 1; i >= 0; i-- {
|
|
if sc.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = sc.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, sc.mutation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nv, ok := v.(*Socialmedia)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from SocialmediaMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sc *SocialmediaCreate) SaveX(ctx context.Context) *Socialmedia {
|
|
v, err := sc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sc *SocialmediaCreate) Exec(ctx context.Context) error {
|
|
_, err := sc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sc *SocialmediaCreate) ExecX(ctx context.Context) {
|
|
if err := sc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sc *SocialmediaCreate) check() error {
|
|
if _, ok := sc.mutation.Serverid(); !ok {
|
|
return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Socialmedia.serverid"`)}
|
|
}
|
|
if _, ok := sc.mutation.GetType(); !ok {
|
|
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Socialmedia.type"`)}
|
|
}
|
|
if _, ok := sc.mutation.Identificator(); !ok {
|
|
return &ValidationError{Name: "identificator", err: errors.New(`ent: missing required field "Socialmedia.identificator"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sc *SocialmediaCreate) sqlSave(ctx context.Context) (*Socialmedia, error) {
|
|
_node, _spec := sc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, sc.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)
|
|
}
|
|
return _node, nil
|
|
}
|
|
|
|
func (sc *SocialmediaCreate) createSpec() (*Socialmedia, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Socialmedia{config: sc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: socialmedia.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: socialmedia.FieldID,
|
|
},
|
|
}
|
|
)
|
|
if id, ok := sc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := sc.mutation.Serverid(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldServerid,
|
|
})
|
|
_node.Serverid = value
|
|
}
|
|
if value, ok := sc.mutation.GetType(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldType,
|
|
})
|
|
_node.Type = value
|
|
}
|
|
if value, ok := sc.mutation.Identificator(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldIdentificator,
|
|
})
|
|
_node.Identificator = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// SocialmediaCreateBulk is the builder for creating many Socialmedia entities in bulk.
|
|
type SocialmediaCreateBulk struct {
|
|
config
|
|
builders []*SocialmediaCreate
|
|
}
|
|
|
|
// Save creates the Socialmedia entities in the database.
|
|
func (scb *SocialmediaCreateBulk) Save(ctx context.Context) ([]*Socialmedia, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
|
nodes := make([]*Socialmedia, len(scb.builders))
|
|
mutators := make([]Mutator, len(scb.builders))
|
|
for i := range scb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := scb.builders[i]
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SocialmediaMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
var err error
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, scb.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, scb.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, scb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (scb *SocialmediaCreateBulk) SaveX(ctx context.Context) []*Socialmedia {
|
|
v, err := scb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (scb *SocialmediaCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := scb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (scb *SocialmediaCreateBulk) ExecX(ctx context.Context) {
|
|
if err := scb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|