430 lines
11 KiB
Go
430 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"api/ent/sev"
|
|
"api/ent/user"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// SevCreate is the builder for creating a Sev entity.
|
|
type SevCreate struct {
|
|
config
|
|
mutation *SevMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (sc *SevCreate) SetPassword(s string) *SevCreate {
|
|
sc.mutation.SetPassword(s)
|
|
return sc
|
|
}
|
|
|
|
// SetToken sets the "token" field.
|
|
func (sc *SevCreate) SetToken(s string) *SevCreate {
|
|
sc.mutation.SetToken(s)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableToken sets the "token" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableToken(s *string) *SevCreate {
|
|
if s != nil {
|
|
sc.SetToken(*s)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetLimit sets the "limit" field.
|
|
func (sc *SevCreate) SetLimit(b bool) *SevCreate {
|
|
sc.mutation.SetLimit(b)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableLimit sets the "limit" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableLimit(b *bool) *SevCreate {
|
|
if b != nil {
|
|
sc.SetLimit(*b)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetCount sets the "count" field.
|
|
func (sc *SevCreate) SetCount(i int) *SevCreate {
|
|
sc.mutation.SetCount(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCount sets the "count" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableCount(i *int) *SevCreate {
|
|
if i != nil {
|
|
sc.SetCount(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetHandle sets the "handle" field.
|
|
func (sc *SevCreate) SetHandle(s string) *SevCreate {
|
|
sc.mutation.SetHandle(s)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableHandle sets the "handle" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableHandle(s *string) *SevCreate {
|
|
if s != nil {
|
|
sc.SetHandle(*s)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetDid sets the "did" field.
|
|
func (sc *SevCreate) SetDid(s string) *SevCreate {
|
|
sc.mutation.SetDid(s)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableDid sets the "did" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableDid(s *string) *SevCreate {
|
|
if s != nil {
|
|
sc.SetDid(*s)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUID sets the "uid" field.
|
|
func (sc *SevCreate) SetUID(i int) *SevCreate {
|
|
sc.mutation.SetUID(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUID sets the "uid" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableUID(i *int) *SevCreate {
|
|
if i != nil {
|
|
sc.SetUID(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetCid sets the "cid" field.
|
|
func (sc *SevCreate) SetCid(i int) *SevCreate {
|
|
sc.mutation.SetCid(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCid sets the "cid" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableCid(i *int) *SevCreate {
|
|
if i != nil {
|
|
sc.SetCid(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetCp sets the "cp" field.
|
|
func (sc *SevCreate) SetCp(i int) *SevCreate {
|
|
sc.mutation.SetCp(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCp sets the "cp" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableCp(i *int) *SevCreate {
|
|
if i != nil {
|
|
sc.SetCp(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetCard sets the "card" field.
|
|
func (sc *SevCreate) SetCard(i int) *SevCreate {
|
|
sc.mutation.SetCard(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCard sets the "card" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableCard(i *int) *SevCreate {
|
|
if i != nil {
|
|
sc.SetCard(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (sc *SevCreate) SetUpdatedAt(t time.Time) *SevCreate {
|
|
sc.mutation.SetUpdatedAt(t)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableUpdatedAt(t *time.Time) *SevCreate {
|
|
if t != nil {
|
|
sc.SetUpdatedAt(*t)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (sc *SevCreate) SetCreatedAt(t time.Time) *SevCreate {
|
|
sc.mutation.SetCreatedAt(t)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (sc *SevCreate) SetNillableCreatedAt(t *time.Time) *SevCreate {
|
|
if t != nil {
|
|
sc.SetCreatedAt(*t)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
|
func (sc *SevCreate) SetOwnerID(id int) *SevCreate {
|
|
sc.mutation.SetOwnerID(id)
|
|
return sc
|
|
}
|
|
|
|
// SetOwner sets the "owner" edge to the User entity.
|
|
func (sc *SevCreate) SetOwner(u *User) *SevCreate {
|
|
return sc.SetOwnerID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the SevMutation object of the builder.
|
|
func (sc *SevCreate) Mutation() *SevMutation {
|
|
return sc.mutation
|
|
}
|
|
|
|
// Save creates the Sev in the database.
|
|
func (sc *SevCreate) Save(ctx context.Context) (*Sev, error) {
|
|
sc.defaults()
|
|
return withHooks[*Sev, SevMutation](ctx, sc.sqlSave, sc.mutation, sc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sc *SevCreate) SaveX(ctx context.Context) *Sev {
|
|
v, err := sc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sc *SevCreate) Exec(ctx context.Context) error {
|
|
_, err := sc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sc *SevCreate) ExecX(ctx context.Context) {
|
|
if err := sc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (sc *SevCreate) defaults() {
|
|
if _, ok := sc.mutation.Limit(); !ok {
|
|
v := sev.DefaultLimit
|
|
sc.mutation.SetLimit(v)
|
|
}
|
|
if _, ok := sc.mutation.CreatedAt(); !ok {
|
|
v := sev.DefaultCreatedAt()
|
|
sc.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sc *SevCreate) check() error {
|
|
if _, ok := sc.mutation.Password(); !ok {
|
|
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Sev.password"`)}
|
|
}
|
|
if v, ok := sc.mutation.Password(); ok {
|
|
if err := sev.PasswordValidator(v); err != nil {
|
|
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Sev.password": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sc.mutation.OwnerID(); !ok {
|
|
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required edge "Sev.owner"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sc *SevCreate) sqlSave(ctx context.Context) (*Sev, error) {
|
|
if err := sc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_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
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
sc.mutation.id = &_node.ID
|
|
sc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (sc *SevCreate) createSpec() (*Sev, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Sev{config: sc.config}
|
|
_spec = sqlgraph.NewCreateSpec(sev.Table, sqlgraph.NewFieldSpec(sev.FieldID, field.TypeInt))
|
|
)
|
|
if value, ok := sc.mutation.Password(); ok {
|
|
_spec.SetField(sev.FieldPassword, field.TypeString, value)
|
|
_node.Password = value
|
|
}
|
|
if value, ok := sc.mutation.Token(); ok {
|
|
_spec.SetField(sev.FieldToken, field.TypeString, value)
|
|
_node.Token = value
|
|
}
|
|
if value, ok := sc.mutation.Limit(); ok {
|
|
_spec.SetField(sev.FieldLimit, field.TypeBool, value)
|
|
_node.Limit = value
|
|
}
|
|
if value, ok := sc.mutation.Count(); ok {
|
|
_spec.SetField(sev.FieldCount, field.TypeInt, value)
|
|
_node.Count = value
|
|
}
|
|
if value, ok := sc.mutation.Handle(); ok {
|
|
_spec.SetField(sev.FieldHandle, field.TypeString, value)
|
|
_node.Handle = value
|
|
}
|
|
if value, ok := sc.mutation.Did(); ok {
|
|
_spec.SetField(sev.FieldDid, field.TypeString, value)
|
|
_node.Did = value
|
|
}
|
|
if value, ok := sc.mutation.UID(); ok {
|
|
_spec.SetField(sev.FieldUID, field.TypeInt, value)
|
|
_node.UID = value
|
|
}
|
|
if value, ok := sc.mutation.Cid(); ok {
|
|
_spec.SetField(sev.FieldCid, field.TypeInt, value)
|
|
_node.Cid = value
|
|
}
|
|
if value, ok := sc.mutation.Cp(); ok {
|
|
_spec.SetField(sev.FieldCp, field.TypeInt, value)
|
|
_node.Cp = value
|
|
}
|
|
if value, ok := sc.mutation.Card(); ok {
|
|
_spec.SetField(sev.FieldCard, field.TypeInt, value)
|
|
_node.Card = value
|
|
}
|
|
if value, ok := sc.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(sev.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if value, ok := sc.mutation.CreatedAt(); ok {
|
|
_spec.SetField(sev.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if nodes := sc.mutation.OwnerIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: sev.OwnerTable,
|
|
Columns: []string{sev.OwnerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.user_sev = &nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// SevCreateBulk is the builder for creating many Sev entities in bulk.
|
|
type SevCreateBulk struct {
|
|
config
|
|
builders []*SevCreate
|
|
}
|
|
|
|
// Save creates the Sev entities in the database.
|
|
func (scb *SevCreateBulk) Save(ctx context.Context) ([]*Sev, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
|
nodes := make([]*Sev, len(scb.builders))
|
|
mutators := make([]Mutator, len(scb.builders))
|
|
for i := range scb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := scb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SevMutation)
|
|
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, 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 {
|
|
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 *SevCreateBulk) SaveX(ctx context.Context) []*Sev {
|
|
v, err := scb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (scb *SevCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := scb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (scb *SevCreateBulk) ExecX(ctx context.Context) {
|
|
if err := scb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|