// 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/blacklist" ) // BlacklistCreate is the builder for creating a Blacklist entity. type BlacklistCreate struct { config mutation *BlacklistMutation hooks []Hook } // SetServerid sets the "serverid" field. func (bc *BlacklistCreate) SetServerid(s string) *BlacklistCreate { bc.mutation.SetServerid(s) return bc } // SetWord sets the "word" field. func (bc *BlacklistCreate) SetWord(s string) *BlacklistCreate { bc.mutation.SetWord(s) return bc } // SetID sets the "id" field. func (bc *BlacklistCreate) SetID(i int) *BlacklistCreate { bc.mutation.SetID(i) return bc } // Mutation returns the BlacklistMutation object of the builder. func (bc *BlacklistCreate) Mutation() *BlacklistMutation { return bc.mutation } // Save creates the Blacklist in the database. func (bc *BlacklistCreate) Save(ctx context.Context) (*Blacklist, error) { var ( err error node *Blacklist ) if len(bc.hooks) == 0 { if err = bc.check(); err != nil { return nil, err } node, err = bc.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*BlacklistMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err = bc.check(); err != nil { return nil, err } bc.mutation = mutation if node, err = bc.sqlSave(ctx); err != nil { return nil, err } mutation.id = &node.ID mutation.done = true return node, err }) for i := len(bc.hooks) - 1; i >= 0; i-- { if bc.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = bc.hooks[i](mut) } v, err := mut.Mutate(ctx, bc.mutation) if err != nil { return nil, err } nv, ok := v.(*Blacklist) if !ok { return nil, fmt.Errorf("unexpected node type %T returned from BlacklistMutation", v) } node = nv } return node, err } // SaveX calls Save and panics if Save returns an error. func (bc *BlacklistCreate) SaveX(ctx context.Context) *Blacklist { v, err := bc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (bc *BlacklistCreate) Exec(ctx context.Context) error { _, err := bc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (bc *BlacklistCreate) ExecX(ctx context.Context) { if err := bc.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (bc *BlacklistCreate) check() error { if _, ok := bc.mutation.Serverid(); !ok { return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Blacklist.serverid"`)} } if _, ok := bc.mutation.Word(); !ok { return &ValidationError{Name: "word", err: errors.New(`ent: missing required field "Blacklist.word"`)} } return nil } func (bc *BlacklistCreate) sqlSave(ctx context.Context) (*Blacklist, error) { _node, _spec := bc.createSpec() if err := sqlgraph.CreateNode(ctx, bc.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 (bc *BlacklistCreate) createSpec() (*Blacklist, *sqlgraph.CreateSpec) { var ( _node = &Blacklist{config: bc.config} _spec = &sqlgraph.CreateSpec{ Table: blacklist.Table, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: blacklist.FieldID, }, } ) if id, ok := bc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := bc.mutation.Serverid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: blacklist.FieldServerid, }) _node.Serverid = value } if value, ok := bc.mutation.Word(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: blacklist.FieldWord, }) _node.Word = value } return _node, _spec } // BlacklistCreateBulk is the builder for creating many Blacklist entities in bulk. type BlacklistCreateBulk struct { config builders []*BlacklistCreate } // Save creates the Blacklist entities in the database. func (bcb *BlacklistCreateBulk) Save(ctx context.Context) ([]*Blacklist, error) { specs := make([]*sqlgraph.CreateSpec, len(bcb.builders)) nodes := make([]*Blacklist, len(bcb.builders)) mutators := make([]Mutator, len(bcb.builders)) for i := range bcb.builders { func(i int, root context.Context) { builder := bcb.builders[i] var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*BlacklistMutation) 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, bcb.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, bcb.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, bcb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (bcb *BlacklistCreateBulk) SaveX(ctx context.Context) []*Blacklist { v, err := bcb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (bcb *BlacklistCreateBulk) Exec(ctx context.Context) error { _, err := bcb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (bcb *BlacklistCreateBulk) ExecX(ctx context.Context) { if err := bcb.Exec(ctx); err != nil { panic(err) } }