mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
546e66cb5d
Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com> Signed-off-by: Maksim Nabokikh <max.nabokih@gmail.com> Co-authored-by: Alwx <alwxsin@gmail.com>
581 lines
18 KiB
Go
581 lines
18 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/dexidp/dex/storage/ent/db/authrequest"
|
|
)
|
|
|
|
// AuthRequestCreate is the builder for creating a AuthRequest entity.
|
|
type AuthRequestCreate struct {
|
|
config
|
|
mutation *AuthRequestMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetClientID sets the "client_id" field.
|
|
func (_c *AuthRequestCreate) SetClientID(v string) *AuthRequestCreate {
|
|
_c.mutation.SetClientID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetScopes sets the "scopes" field.
|
|
func (_c *AuthRequestCreate) SetScopes(v []string) *AuthRequestCreate {
|
|
_c.mutation.SetScopes(v)
|
|
return _c
|
|
}
|
|
|
|
// SetResponseTypes sets the "response_types" field.
|
|
func (_c *AuthRequestCreate) SetResponseTypes(v []string) *AuthRequestCreate {
|
|
_c.mutation.SetResponseTypes(v)
|
|
return _c
|
|
}
|
|
|
|
// SetRedirectURI sets the "redirect_uri" field.
|
|
func (_c *AuthRequestCreate) SetRedirectURI(v string) *AuthRequestCreate {
|
|
_c.mutation.SetRedirectURI(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNonce sets the "nonce" field.
|
|
func (_c *AuthRequestCreate) SetNonce(v string) *AuthRequestCreate {
|
|
_c.mutation.SetNonce(v)
|
|
return _c
|
|
}
|
|
|
|
// SetState sets the "state" field.
|
|
func (_c *AuthRequestCreate) SetState(v string) *AuthRequestCreate {
|
|
_c.mutation.SetState(v)
|
|
return _c
|
|
}
|
|
|
|
// SetForceApprovalPrompt sets the "force_approval_prompt" field.
|
|
func (_c *AuthRequestCreate) SetForceApprovalPrompt(v bool) *AuthRequestCreate {
|
|
_c.mutation.SetForceApprovalPrompt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetLoggedIn sets the "logged_in" field.
|
|
func (_c *AuthRequestCreate) SetLoggedIn(v bool) *AuthRequestCreate {
|
|
_c.mutation.SetLoggedIn(v)
|
|
return _c
|
|
}
|
|
|
|
// SetClaimsUserID sets the "claims_user_id" field.
|
|
func (_c *AuthRequestCreate) SetClaimsUserID(v string) *AuthRequestCreate {
|
|
_c.mutation.SetClaimsUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetClaimsUsername sets the "claims_username" field.
|
|
func (_c *AuthRequestCreate) SetClaimsUsername(v string) *AuthRequestCreate {
|
|
_c.mutation.SetClaimsUsername(v)
|
|
return _c
|
|
}
|
|
|
|
// SetClaimsEmail sets the "claims_email" field.
|
|
func (_c *AuthRequestCreate) SetClaimsEmail(v string) *AuthRequestCreate {
|
|
_c.mutation.SetClaimsEmail(v)
|
|
return _c
|
|
}
|
|
|
|
// SetClaimsEmailVerified sets the "claims_email_verified" field.
|
|
func (_c *AuthRequestCreate) SetClaimsEmailVerified(v bool) *AuthRequestCreate {
|
|
_c.mutation.SetClaimsEmailVerified(v)
|
|
return _c
|
|
}
|
|
|
|
// SetClaimsGroups sets the "claims_groups" field.
|
|
func (_c *AuthRequestCreate) SetClaimsGroups(v []string) *AuthRequestCreate {
|
|
_c.mutation.SetClaimsGroups(v)
|
|
return _c
|
|
}
|
|
|
|
// SetClaimsPreferredUsername sets the "claims_preferred_username" field.
|
|
func (_c *AuthRequestCreate) SetClaimsPreferredUsername(v string) *AuthRequestCreate {
|
|
_c.mutation.SetClaimsPreferredUsername(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableClaimsPreferredUsername sets the "claims_preferred_username" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillableClaimsPreferredUsername(v *string) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetClaimsPreferredUsername(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetConnectorID sets the "connector_id" field.
|
|
func (_c *AuthRequestCreate) SetConnectorID(v string) *AuthRequestCreate {
|
|
_c.mutation.SetConnectorID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetConnectorData sets the "connector_data" field.
|
|
func (_c *AuthRequestCreate) SetConnectorData(v []byte) *AuthRequestCreate {
|
|
_c.mutation.SetConnectorData(v)
|
|
return _c
|
|
}
|
|
|
|
// SetExpiry sets the "expiry" field.
|
|
func (_c *AuthRequestCreate) SetExpiry(v time.Time) *AuthRequestCreate {
|
|
_c.mutation.SetExpiry(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCodeChallenge sets the "code_challenge" field.
|
|
func (_c *AuthRequestCreate) SetCodeChallenge(v string) *AuthRequestCreate {
|
|
_c.mutation.SetCodeChallenge(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCodeChallenge sets the "code_challenge" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillableCodeChallenge(v *string) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetCodeChallenge(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCodeChallengeMethod sets the "code_challenge_method" field.
|
|
func (_c *AuthRequestCreate) SetCodeChallengeMethod(v string) *AuthRequestCreate {
|
|
_c.mutation.SetCodeChallengeMethod(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCodeChallengeMethod sets the "code_challenge_method" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillableCodeChallengeMethod(v *string) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetCodeChallengeMethod(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetHmacKey sets the "hmac_key" field.
|
|
func (_c *AuthRequestCreate) SetHmacKey(v []byte) *AuthRequestCreate {
|
|
_c.mutation.SetHmacKey(v)
|
|
return _c
|
|
}
|
|
|
|
// SetMfaValidated sets the "mfa_validated" field.
|
|
func (_c *AuthRequestCreate) SetMfaValidated(v bool) *AuthRequestCreate {
|
|
_c.mutation.SetMfaValidated(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMfaValidated sets the "mfa_validated" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillableMfaValidated(v *bool) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetMfaValidated(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetWebauthnSessionData sets the "webauthn_session_data" field.
|
|
func (_c *AuthRequestCreate) SetWebauthnSessionData(v []byte) *AuthRequestCreate {
|
|
_c.mutation.SetWebauthnSessionData(v)
|
|
return _c
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (_c *AuthRequestCreate) SetPrompt(v string) *AuthRequestCreate {
|
|
_c.mutation.SetPrompt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillablePrompt sets the "prompt" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillablePrompt(v *string) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetPrompt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetMaxAge sets the "max_age" field.
|
|
func (_c *AuthRequestCreate) SetMaxAge(v int) *AuthRequestCreate {
|
|
_c.mutation.SetMaxAge(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMaxAge sets the "max_age" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillableMaxAge(v *int) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetMaxAge(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAuthTime sets the "auth_time" field.
|
|
func (_c *AuthRequestCreate) SetAuthTime(v time.Time) *AuthRequestCreate {
|
|
_c.mutation.SetAuthTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableAuthTime sets the "auth_time" field if the given value is not nil.
|
|
func (_c *AuthRequestCreate) SetNillableAuthTime(v *time.Time) *AuthRequestCreate {
|
|
if v != nil {
|
|
_c.SetAuthTime(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *AuthRequestCreate) SetID(v string) *AuthRequestCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the AuthRequestMutation object of the builder.
|
|
func (_c *AuthRequestCreate) Mutation() *AuthRequestMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the AuthRequest in the database.
|
|
func (_c *AuthRequestCreate) Save(ctx context.Context) (*AuthRequest, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *AuthRequestCreate) SaveX(ctx context.Context) *AuthRequest {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AuthRequestCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AuthRequestCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *AuthRequestCreate) defaults() {
|
|
if _, ok := _c.mutation.ClaimsPreferredUsername(); !ok {
|
|
v := authrequest.DefaultClaimsPreferredUsername
|
|
_c.mutation.SetClaimsPreferredUsername(v)
|
|
}
|
|
if _, ok := _c.mutation.CodeChallenge(); !ok {
|
|
v := authrequest.DefaultCodeChallenge
|
|
_c.mutation.SetCodeChallenge(v)
|
|
}
|
|
if _, ok := _c.mutation.CodeChallengeMethod(); !ok {
|
|
v := authrequest.DefaultCodeChallengeMethod
|
|
_c.mutation.SetCodeChallengeMethod(v)
|
|
}
|
|
if _, ok := _c.mutation.MfaValidated(); !ok {
|
|
v := authrequest.DefaultMfaValidated
|
|
_c.mutation.SetMfaValidated(v)
|
|
}
|
|
if _, ok := _c.mutation.Prompt(); !ok {
|
|
v := authrequest.DefaultPrompt
|
|
_c.mutation.SetPrompt(v)
|
|
}
|
|
if _, ok := _c.mutation.MaxAge(); !ok {
|
|
v := authrequest.DefaultMaxAge
|
|
_c.mutation.SetMaxAge(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *AuthRequestCreate) check() error {
|
|
if _, ok := _c.mutation.ClientID(); !ok {
|
|
return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "AuthRequest.client_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.RedirectURI(); !ok {
|
|
return &ValidationError{Name: "redirect_uri", err: errors.New(`db: missing required field "AuthRequest.redirect_uri"`)}
|
|
}
|
|
if _, ok := _c.mutation.Nonce(); !ok {
|
|
return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "AuthRequest.nonce"`)}
|
|
}
|
|
if _, ok := _c.mutation.State(); !ok {
|
|
return &ValidationError{Name: "state", err: errors.New(`db: missing required field "AuthRequest.state"`)}
|
|
}
|
|
if _, ok := _c.mutation.ForceApprovalPrompt(); !ok {
|
|
return &ValidationError{Name: "force_approval_prompt", err: errors.New(`db: missing required field "AuthRequest.force_approval_prompt"`)}
|
|
}
|
|
if _, ok := _c.mutation.LoggedIn(); !ok {
|
|
return &ValidationError{Name: "logged_in", err: errors.New(`db: missing required field "AuthRequest.logged_in"`)}
|
|
}
|
|
if _, ok := _c.mutation.ClaimsUserID(); !ok {
|
|
return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "AuthRequest.claims_user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.ClaimsUsername(); !ok {
|
|
return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "AuthRequest.claims_username"`)}
|
|
}
|
|
if _, ok := _c.mutation.ClaimsEmail(); !ok {
|
|
return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "AuthRequest.claims_email"`)}
|
|
}
|
|
if _, ok := _c.mutation.ClaimsEmailVerified(); !ok {
|
|
return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "AuthRequest.claims_email_verified"`)}
|
|
}
|
|
if _, ok := _c.mutation.ClaimsPreferredUsername(); !ok {
|
|
return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "AuthRequest.claims_preferred_username"`)}
|
|
}
|
|
if _, ok := _c.mutation.ConnectorID(); !ok {
|
|
return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "AuthRequest.connector_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Expiry(); !ok {
|
|
return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "AuthRequest.expiry"`)}
|
|
}
|
|
if _, ok := _c.mutation.CodeChallenge(); !ok {
|
|
return &ValidationError{Name: "code_challenge", err: errors.New(`db: missing required field "AuthRequest.code_challenge"`)}
|
|
}
|
|
if _, ok := _c.mutation.CodeChallengeMethod(); !ok {
|
|
return &ValidationError{Name: "code_challenge_method", err: errors.New(`db: missing required field "AuthRequest.code_challenge_method"`)}
|
|
}
|
|
if _, ok := _c.mutation.HmacKey(); !ok {
|
|
return &ValidationError{Name: "hmac_key", err: errors.New(`db: missing required field "AuthRequest.hmac_key"`)}
|
|
}
|
|
if _, ok := _c.mutation.MfaValidated(); !ok {
|
|
return &ValidationError{Name: "mfa_validated", err: errors.New(`db: missing required field "AuthRequest.mfa_validated"`)}
|
|
}
|
|
if _, ok := _c.mutation.Prompt(); !ok {
|
|
return &ValidationError{Name: "prompt", err: errors.New(`db: missing required field "AuthRequest.prompt"`)}
|
|
}
|
|
if _, ok := _c.mutation.MaxAge(); !ok {
|
|
return &ValidationError{Name: "max_age", err: errors.New(`db: missing required field "AuthRequest.max_age"`)}
|
|
}
|
|
if v, ok := _c.mutation.ID(); ok {
|
|
if err := authrequest.IDValidator(v); err != nil {
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "AuthRequest.id": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *AuthRequestCreate) sqlSave(ctx context.Context) (*AuthRequest, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != nil {
|
|
if id, ok := _spec.ID.Value.(string); ok {
|
|
_node.ID = id
|
|
} else {
|
|
return nil, fmt.Errorf("unexpected AuthRequest.ID type: %T", _spec.ID.Value)
|
|
}
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *AuthRequestCreate) createSpec() (*AuthRequest, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &AuthRequest{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(authrequest.Table, sqlgraph.NewFieldSpec(authrequest.FieldID, field.TypeString))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.ClientID(); ok {
|
|
_spec.SetField(authrequest.FieldClientID, field.TypeString, value)
|
|
_node.ClientID = value
|
|
}
|
|
if value, ok := _c.mutation.Scopes(); ok {
|
|
_spec.SetField(authrequest.FieldScopes, field.TypeJSON, value)
|
|
_node.Scopes = value
|
|
}
|
|
if value, ok := _c.mutation.ResponseTypes(); ok {
|
|
_spec.SetField(authrequest.FieldResponseTypes, field.TypeJSON, value)
|
|
_node.ResponseTypes = value
|
|
}
|
|
if value, ok := _c.mutation.RedirectURI(); ok {
|
|
_spec.SetField(authrequest.FieldRedirectURI, field.TypeString, value)
|
|
_node.RedirectURI = value
|
|
}
|
|
if value, ok := _c.mutation.Nonce(); ok {
|
|
_spec.SetField(authrequest.FieldNonce, field.TypeString, value)
|
|
_node.Nonce = value
|
|
}
|
|
if value, ok := _c.mutation.State(); ok {
|
|
_spec.SetField(authrequest.FieldState, field.TypeString, value)
|
|
_node.State = value
|
|
}
|
|
if value, ok := _c.mutation.ForceApprovalPrompt(); ok {
|
|
_spec.SetField(authrequest.FieldForceApprovalPrompt, field.TypeBool, value)
|
|
_node.ForceApprovalPrompt = value
|
|
}
|
|
if value, ok := _c.mutation.LoggedIn(); ok {
|
|
_spec.SetField(authrequest.FieldLoggedIn, field.TypeBool, value)
|
|
_node.LoggedIn = value
|
|
}
|
|
if value, ok := _c.mutation.ClaimsUserID(); ok {
|
|
_spec.SetField(authrequest.FieldClaimsUserID, field.TypeString, value)
|
|
_node.ClaimsUserID = value
|
|
}
|
|
if value, ok := _c.mutation.ClaimsUsername(); ok {
|
|
_spec.SetField(authrequest.FieldClaimsUsername, field.TypeString, value)
|
|
_node.ClaimsUsername = value
|
|
}
|
|
if value, ok := _c.mutation.ClaimsEmail(); ok {
|
|
_spec.SetField(authrequest.FieldClaimsEmail, field.TypeString, value)
|
|
_node.ClaimsEmail = value
|
|
}
|
|
if value, ok := _c.mutation.ClaimsEmailVerified(); ok {
|
|
_spec.SetField(authrequest.FieldClaimsEmailVerified, field.TypeBool, value)
|
|
_node.ClaimsEmailVerified = value
|
|
}
|
|
if value, ok := _c.mutation.ClaimsGroups(); ok {
|
|
_spec.SetField(authrequest.FieldClaimsGroups, field.TypeJSON, value)
|
|
_node.ClaimsGroups = value
|
|
}
|
|
if value, ok := _c.mutation.ClaimsPreferredUsername(); ok {
|
|
_spec.SetField(authrequest.FieldClaimsPreferredUsername, field.TypeString, value)
|
|
_node.ClaimsPreferredUsername = value
|
|
}
|
|
if value, ok := _c.mutation.ConnectorID(); ok {
|
|
_spec.SetField(authrequest.FieldConnectorID, field.TypeString, value)
|
|
_node.ConnectorID = value
|
|
}
|
|
if value, ok := _c.mutation.ConnectorData(); ok {
|
|
_spec.SetField(authrequest.FieldConnectorData, field.TypeBytes, value)
|
|
_node.ConnectorData = &value
|
|
}
|
|
if value, ok := _c.mutation.Expiry(); ok {
|
|
_spec.SetField(authrequest.FieldExpiry, field.TypeTime, value)
|
|
_node.Expiry = value
|
|
}
|
|
if value, ok := _c.mutation.CodeChallenge(); ok {
|
|
_spec.SetField(authrequest.FieldCodeChallenge, field.TypeString, value)
|
|
_node.CodeChallenge = value
|
|
}
|
|
if value, ok := _c.mutation.CodeChallengeMethod(); ok {
|
|
_spec.SetField(authrequest.FieldCodeChallengeMethod, field.TypeString, value)
|
|
_node.CodeChallengeMethod = value
|
|
}
|
|
if value, ok := _c.mutation.HmacKey(); ok {
|
|
_spec.SetField(authrequest.FieldHmacKey, field.TypeBytes, value)
|
|
_node.HmacKey = value
|
|
}
|
|
if value, ok := _c.mutation.MfaValidated(); ok {
|
|
_spec.SetField(authrequest.FieldMfaValidated, field.TypeBool, value)
|
|
_node.MfaValidated = value
|
|
}
|
|
if value, ok := _c.mutation.WebauthnSessionData(); ok {
|
|
_spec.SetField(authrequest.FieldWebauthnSessionData, field.TypeBytes, value)
|
|
_node.WebauthnSessionData = &value
|
|
}
|
|
if value, ok := _c.mutation.Prompt(); ok {
|
|
_spec.SetField(authrequest.FieldPrompt, field.TypeString, value)
|
|
_node.Prompt = value
|
|
}
|
|
if value, ok := _c.mutation.MaxAge(); ok {
|
|
_spec.SetField(authrequest.FieldMaxAge, field.TypeInt, value)
|
|
_node.MaxAge = value
|
|
}
|
|
if value, ok := _c.mutation.AuthTime(); ok {
|
|
_spec.SetField(authrequest.FieldAuthTime, field.TypeTime, value)
|
|
_node.AuthTime = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// AuthRequestCreateBulk is the builder for creating many AuthRequest entities in bulk.
|
|
type AuthRequestCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*AuthRequestCreate
|
|
}
|
|
|
|
// Save creates the AuthRequest entities in the database.
|
|
func (_c *AuthRequestCreateBulk) Save(ctx context.Context) ([]*AuthRequest, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*AuthRequest, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*AuthRequestMutation)
|
|
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, _c.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, _c.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
|
|
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, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *AuthRequestCreateBulk) SaveX(ctx context.Context) []*AuthRequest {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AuthRequestCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AuthRequestCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|