// 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/support" ) // SupportCreate is the builder for creating a Support entity. type SupportCreate struct { config mutation *SupportMutation hooks []Hook } // SetRefid sets the "refid" field. func (sc *SupportCreate) SetRefid(s string) *SupportCreate { sc.mutation.SetRefid(s) return sc } // SetServerid sets the "serverid" field. func (sc *SupportCreate) SetServerid(s string) *SupportCreate { sc.mutation.SetServerid(s) return sc } // SetCreator sets the "creator" field. func (sc *SupportCreate) SetCreator(s string) *SupportCreate { sc.mutation.SetCreator(s) return sc } // SetStatus sets the "status" field. func (sc *SupportCreate) SetStatus(s string) *SupportCreate { sc.mutation.SetStatus(s) return sc } // SetTitle sets the "title" field. func (sc *SupportCreate) SetTitle(s string) *SupportCreate { sc.mutation.SetTitle(s) return sc } // SetDescription sets the "description" field. func (sc *SupportCreate) SetDescription(s string) *SupportCreate { sc.mutation.SetDescription(s) return sc } // SetID sets the "id" field. func (sc *SupportCreate) SetID(i int) *SupportCreate { sc.mutation.SetID(i) return sc } // Mutation returns the SupportMutation object of the builder. func (sc *SupportCreate) Mutation() *SupportMutation { return sc.mutation } // Save creates the Support in the database. func (sc *SupportCreate) Save(ctx context.Context) (*Support, error) { var ( err error node *Support ) 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.(*SupportMutation) 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.(*Support) if !ok { return nil, fmt.Errorf("unexpected node type %T returned from SupportMutation", v) } node = nv } return node, err } // SaveX calls Save and panics if Save returns an error. func (sc *SupportCreate) SaveX(ctx context.Context) *Support { v, err := sc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (sc *SupportCreate) Exec(ctx context.Context) error { _, err := sc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (sc *SupportCreate) 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 *SupportCreate) check() error { if _, ok := sc.mutation.Refid(); !ok { return &ValidationError{Name: "refid", err: errors.New(`ent: missing required field "Support.refid"`)} } if _, ok := sc.mutation.Serverid(); !ok { return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Support.serverid"`)} } if _, ok := sc.mutation.Creator(); !ok { return &ValidationError{Name: "creator", err: errors.New(`ent: missing required field "Support.creator"`)} } if _, ok := sc.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Support.status"`)} } if _, ok := sc.mutation.Title(); !ok { return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Support.title"`)} } if _, ok := sc.mutation.Description(); !ok { return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "Support.description"`)} } return nil } func (sc *SupportCreate) sqlSave(ctx context.Context) (*Support, 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 *SupportCreate) createSpec() (*Support, *sqlgraph.CreateSpec) { var ( _node = &Support{config: sc.config} _spec = &sqlgraph.CreateSpec{ Table: support.Table, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: support.FieldID, }, } ) if id, ok := sc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := sc.mutation.Refid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: support.FieldRefid, }) _node.Refid = value } if value, ok := sc.mutation.Serverid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: support.FieldServerid, }) _node.Serverid = value } if value, ok := sc.mutation.Creator(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: support.FieldCreator, }) _node.Creator = value } if value, ok := sc.mutation.Status(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: support.FieldStatus, }) _node.Status = value } if value, ok := sc.mutation.Title(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: support.FieldTitle, }) _node.Title = value } if value, ok := sc.mutation.Description(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: support.FieldDescription, }) _node.Description = value } return _node, _spec } // SupportCreateBulk is the builder for creating many Support entities in bulk. type SupportCreateBulk struct { config builders []*SupportCreate } // Save creates the Support entities in the database. func (scb *SupportCreateBulk) Save(ctx context.Context) ([]*Support, error) { specs := make([]*sqlgraph.CreateSpec, len(scb.builders)) nodes := make([]*Support, 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.(*SupportMutation) 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 *SupportCreateBulk) SaveX(ctx context.Context) []*Support { v, err := scb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (scb *SupportCreateBulk) Exec(ctx context.Context) error { _, err := scb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (scb *SupportCreateBulk) ExecX(ctx context.Context) { if err := scb.Exec(ctx); err != nil { panic(err) } }