// 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/authorizables" ) // AuthorizablesCreate is the builder for creating a Authorizables entity. type AuthorizablesCreate struct { config mutation *AuthorizablesMutation hooks []Hook } // SetUsername sets the "username" field. func (ac *AuthorizablesCreate) SetUsername(s string) *AuthorizablesCreate { ac.mutation.SetUsername(s) return ac } // SetPassword sets the "password" field. func (ac *AuthorizablesCreate) SetPassword(s string) *AuthorizablesCreate { ac.mutation.SetPassword(s) return ac } // SetServerid sets the "serverid" field. func (ac *AuthorizablesCreate) SetServerid(s string) *AuthorizablesCreate { ac.mutation.SetServerid(s) return ac } // SetUserid sets the "userid" field. func (ac *AuthorizablesCreate) SetUserid(s string) *AuthorizablesCreate { ac.mutation.SetUserid(s) return ac } // Mutation returns the AuthorizablesMutation object of the builder. func (ac *AuthorizablesCreate) Mutation() *AuthorizablesMutation { return ac.mutation } // Save creates the Authorizables in the database. func (ac *AuthorizablesCreate) Save(ctx context.Context) (*Authorizables, error) { var ( err error node *Authorizables ) 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.(*AuthorizablesMutation) 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.(*Authorizables) if !ok { return nil, fmt.Errorf("unexpected node type %T returned from AuthorizablesMutation", v) } node = nv } return node, err } // SaveX calls Save and panics if Save returns an error. func (ac *AuthorizablesCreate) SaveX(ctx context.Context) *Authorizables { v, err := ac.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (ac *AuthorizablesCreate) Exec(ctx context.Context) error { _, err := ac.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (ac *AuthorizablesCreate) ExecX(ctx context.Context) { if err := ac.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (ac *AuthorizablesCreate) check() error { if _, ok := ac.mutation.Username(); !ok { return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "Authorizables.username"`)} } if _, ok := ac.mutation.Password(); !ok { return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Authorizables.password"`)} } if _, ok := ac.mutation.Serverid(); !ok { return &ValidationError{Name: "serverid", err: errors.New(`ent: missing required field "Authorizables.serverid"`)} } if _, ok := ac.mutation.Userid(); !ok { return &ValidationError{Name: "userid", err: errors.New(`ent: missing required field "Authorizables.userid"`)} } return nil } func (ac *AuthorizablesCreate) sqlSave(ctx context.Context) (*Authorizables, 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 } id := _spec.ID.Value.(int64) _node.ID = int(id) return _node, nil } func (ac *AuthorizablesCreate) createSpec() (*Authorizables, *sqlgraph.CreateSpec) { var ( _node = &Authorizables{config: ac.config} _spec = &sqlgraph.CreateSpec{ Table: authorizables.Table, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: authorizables.FieldID, }, } ) if value, ok := ac.mutation.Username(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldUsername, }) _node.Username = value } if value, ok := ac.mutation.Password(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldPassword, }) _node.Password = value } if value, ok := ac.mutation.Serverid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldServerid, }) _node.Serverid = value } if value, ok := ac.mutation.Userid(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldUserid, }) _node.Userid = value } return _node, _spec } // AuthorizablesCreateBulk is the builder for creating many Authorizables entities in bulk. type AuthorizablesCreateBulk struct { config builders []*AuthorizablesCreate } // Save creates the Authorizables entities in the database. func (acb *AuthorizablesCreateBulk) Save(ctx context.Context) ([]*Authorizables, error) { specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) nodes := make([]*Authorizables, len(acb.builders)) mutators := make([]Mutator, len(acb.builders)) for i := range acb.builders { func(i int, root context.Context) { builder := acb.builders[i] var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*AuthorizablesMutation) 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 { 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 *AuthorizablesCreateBulk) SaveX(ctx context.Context) []*Authorizables { v, err := acb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (acb *AuthorizablesCreateBulk) Exec(ctx context.Context) error { _, err := acb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (acb *AuthorizablesCreateBulk) ExecX(ctx context.Context) { if err := acb.Exec(ctx); err != nil { panic(err) } }