// 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/actions" ) // ActionsCreate is the builder for creating a Actions entity. type ActionsCreate struct { config mutation *ActionsMutation hooks []Hook } // SetRefid sets the "refid" field. func (ac *ActionsCreate) SetRefid(s string) *ActionsCreate { ac.mutation.SetRefid(s) return ac } // SetCommiter sets the "commiter" field. func (ac *ActionsCreate) SetCommiter(s string) *ActionsCreate { ac.mutation.SetCommiter(s) return ac } // SetServerid sets the "serverid" field. func (ac *ActionsCreate) SetServerid(s string) *ActionsCreate { ac.mutation.SetServerid(s) return ac } // SetTarget sets the "target" field. func (ac *ActionsCreate) SetTarget(s string) *ActionsCreate { ac.mutation.SetTarget(s) return ac } // SetType sets the "type" field. func (ac *ActionsCreate) SetType(s string) *ActionsCreate { ac.mutation.SetType(s) return ac } // SetDuration sets the "duration" field. func (ac *ActionsCreate) SetDuration(s string) *ActionsCreate { ac.mutation.SetDuration(s) return ac } // SetReason sets the "reason" field. func (ac *ActionsCreate) SetReason(s string) *ActionsCreate { ac.mutation.SetReason(s) return ac } // SetTemp sets the "temp" field. func (ac *ActionsCreate) SetTemp(b bool) *ActionsCreate { ac.mutation.SetTemp(b) return ac } // SetNillableTemp sets the "temp" field if the given value is not nil. func (ac *ActionsCreate) SetNillableTemp(b *bool) *ActionsCreate { if b != nil { ac.SetTemp(*b) } return ac } // SetID sets the "id" field. func (ac *ActionsCreate) SetID(i int) *ActionsCreate { ac.mutation.SetID(i) return ac } // Mutation returns the ActionsMutation object of the builder. func (ac *ActionsCreate) Mutation() *ActionsMutation { return ac.mutation } // Save creates the Actions in the database. func (ac *ActionsCreate) Save(ctx context.Context) (*Actions, error) { var ( err error node *Actions ) ac.defaults() if len(ac.hooks) == 0 { if err = ac.check(); err != nil { return nil, err } node, err = ac.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*ActionsMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err = ac.check(); err != nil { return nil, err } ac.mutation = mutation if node, err = ac.sqlSave(ctx); err != nil { return nil, err } mutation.id = &node.ID mutation.done = true return node, err }) for i := len(ac.hooks) - 1; i >= 0; i-- { if ac.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = ac.hooks[i](mut) } v, err := mut.Mutate(ctx, ac.mutation) if err != nil { return nil, err } nv, ok := v.(*Actions) if !ok { return nil, fmt.Errorf("unexpected node type %T returned from ActionsMutation", v) } node = nv } return node, err } // SaveX calls Save and panics if Save returns an error. func (ac *ActionsCreate) SaveX(ctx context.Context) *Actions { v, err := ac.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (ac *ActionsCreate) Exec(ctx context.Context) error { _, err := ac.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (ac *ActionsCreate) ExecX(ctx context.Context) { if err := ac.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (ac *ActionsCreate) defaults() { if _, ok := ac.mutation.Temp(); !ok { v := actions.DefaultTemp ac.mutation.SetTemp(v) } } // check runs all checks and user-defined validators on the builder. func (ac *ActionsCreate) check() error { if _, ok := ac.mutation.Refid(); !ok { return &ValidationError{Name: "refid", err: errors.New(`ent: missing required field "Actions.refid"`)} } if _, ok := ac.mutation.Commiter(); !ok { return &ValidationError{Name: "commiter", err: errors.New(`ent: missing required field "Actions.commiter"`)} } if _, ok := ac.mutation.Serverid(); !ok { return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Actions.serverid"`)} } if _, ok := ac.mutation.Target(); !ok { return &ValidationError{Name: "target", err: errors.New(`ent: missing required field "Actions.target"`)} } if _, ok := ac.mutation.GetType(); !ok { return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Actions.type"`)} } if _, ok := ac.mutation.Duration(); !ok { return &ValidationError{Name: "duration", err: errors.New(`ent: missing required field "Actions.duration"`)} } if _, ok := ac.mutation.Reason(); !ok { return &ValidationError{Name: "reason", err: errors.New(`ent: missing required field "Actions.reason"`)} } if _, ok := ac.mutation.Temp(); !ok { return &ValidationError{Name: "temp", err: errors.New(`ent: missing required field "Actions.temp"`)} } return nil } func (ac *ActionsCreate) sqlSave(ctx context.Context) (*Actions, error) { _node, _spec := ac.createSpec() if err := sqlgraph.CreateNode(ctx, ac.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 (ac *ActionsCreate) createSpec() (*Actions, *sqlgraph.CreateSpec) { var ( _node = &Actions{config: ac.config} _spec = &sqlgraph.CreateSpec{ Table: actions.Table, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: actions.FieldID, }, } ) if id, ok := ac.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := ac.mutation.Refid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldRefid, }) _node.Refid = value } if value, ok := ac.mutation.Commiter(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldCommiter, }) _node.Commiter = value } if value, ok := ac.mutation.Serverid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldServerid, }) _node.Serverid = value } if value, ok := ac.mutation.Target(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldTarget, }) _node.Target = value } if value, ok := ac.mutation.GetType(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldType, }) _node.Type = value } if value, ok := ac.mutation.Duration(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldDuration, }) _node.Duration = value } if value, ok := ac.mutation.Reason(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldReason, }) _node.Reason = value } if value, ok := ac.mutation.Temp(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: actions.FieldTemp, }) _node.Temp = value } return _node, _spec } // ActionsCreateBulk is the builder for creating many Actions entities in bulk. type ActionsCreateBulk struct { config builders []*ActionsCreate } // Save creates the Actions entities in the database. func (acb *ActionsCreateBulk) Save(ctx context.Context) ([]*Actions, error) { specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) nodes := make([]*Actions, len(acb.builders)) mutators := make([]Mutator, len(acb.builders)) for i := range acb.builders { func(i int, root context.Context) { builder := acb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*ActionsMutation) 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, acb.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, acb.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, acb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (acb *ActionsCreateBulk) SaveX(ctx context.Context) []*Actions { v, err := acb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (acb *ActionsCreateBulk) Exec(ctx context.Context) error { _, err := acb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (acb *ActionsCreateBulk) ExecX(ctx context.Context) { if err := acb.Exec(ctx); err != nil { panic(err) } }