authentication_create.go•34.6 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Southclaws/storyden/internal/ent/account"
"github.com/Southclaws/storyden/internal/ent/authentication"
"github.com/rs/xid"
)
// AuthenticationCreate is the builder for creating a Authentication entity.
type AuthenticationCreate struct {
config
mutation *AuthenticationMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *AuthenticationCreate) SetCreatedAt(v time.Time) *AuthenticationCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *AuthenticationCreate) SetNillableCreatedAt(v *time.Time) *AuthenticationCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetExpiresAt sets the "expires_at" field.
func (_c *AuthenticationCreate) SetExpiresAt(v time.Time) *AuthenticationCreate {
_c.mutation.SetExpiresAt(v)
return _c
}
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func (_c *AuthenticationCreate) SetNillableExpiresAt(v *time.Time) *AuthenticationCreate {
if v != nil {
_c.SetExpiresAt(*v)
}
return _c
}
// SetService sets the "service" field.
func (_c *AuthenticationCreate) SetService(v string) *AuthenticationCreate {
_c.mutation.SetService(v)
return _c
}
// SetTokenType sets the "token_type" field.
func (_c *AuthenticationCreate) SetTokenType(v string) *AuthenticationCreate {
_c.mutation.SetTokenType(v)
return _c
}
// SetIdentifier sets the "identifier" field.
func (_c *AuthenticationCreate) SetIdentifier(v string) *AuthenticationCreate {
_c.mutation.SetIdentifier(v)
return _c
}
// SetToken sets the "token" field.
func (_c *AuthenticationCreate) SetToken(v string) *AuthenticationCreate {
_c.mutation.SetToken(v)
return _c
}
// SetName sets the "name" field.
func (_c *AuthenticationCreate) SetName(v string) *AuthenticationCreate {
_c.mutation.SetName(v)
return _c
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_c *AuthenticationCreate) SetNillableName(v *string) *AuthenticationCreate {
if v != nil {
_c.SetName(*v)
}
return _c
}
// SetDisabled sets the "disabled" field.
func (_c *AuthenticationCreate) SetDisabled(v bool) *AuthenticationCreate {
_c.mutation.SetDisabled(v)
return _c
}
// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (_c *AuthenticationCreate) SetNillableDisabled(v *bool) *AuthenticationCreate {
if v != nil {
_c.SetDisabled(*v)
}
return _c
}
// SetMetadata sets the "metadata" field.
func (_c *AuthenticationCreate) SetMetadata(v map[string]interface{}) *AuthenticationCreate {
_c.mutation.SetMetadata(v)
return _c
}
// SetAccountAuthentication sets the "account_authentication" field.
func (_c *AuthenticationCreate) SetAccountAuthentication(v xid.ID) *AuthenticationCreate {
_c.mutation.SetAccountAuthentication(v)
return _c
}
// SetID sets the "id" field.
func (_c *AuthenticationCreate) SetID(v xid.ID) *AuthenticationCreate {
_c.mutation.SetID(v)
return _c
}
// SetNillableID sets the "id" field if the given value is not nil.
func (_c *AuthenticationCreate) SetNillableID(v *xid.ID) *AuthenticationCreate {
if v != nil {
_c.SetID(*v)
}
return _c
}
// SetAccountID sets the "account" edge to the Account entity by ID.
func (_c *AuthenticationCreate) SetAccountID(id xid.ID) *AuthenticationCreate {
_c.mutation.SetAccountID(id)
return _c
}
// SetAccount sets the "account" edge to the Account entity.
func (_c *AuthenticationCreate) SetAccount(v *Account) *AuthenticationCreate {
return _c.SetAccountID(v.ID)
}
// Mutation returns the AuthenticationMutation object of the builder.
func (_c *AuthenticationCreate) Mutation() *AuthenticationMutation {
return _c.mutation
}
// Save creates the Authentication in the database.
func (_c *AuthenticationCreate) Save(ctx context.Context) (*Authentication, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *AuthenticationCreate) SaveX(ctx context.Context) *Authentication {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AuthenticationCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AuthenticationCreate) 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 *AuthenticationCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := authentication.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.Disabled(); !ok {
v := authentication.DefaultDisabled
_c.mutation.SetDisabled(v)
}
if _, ok := _c.mutation.ID(); !ok {
v := authentication.DefaultID()
_c.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *AuthenticationCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Authentication.created_at"`)}
}
if _, ok := _c.mutation.Service(); !ok {
return &ValidationError{Name: "service", err: errors.New(`ent: missing required field "Authentication.service"`)}
}
if v, ok := _c.mutation.Service(); ok {
if err := authentication.ServiceValidator(v); err != nil {
return &ValidationError{Name: "service", err: fmt.Errorf(`ent: validator failed for field "Authentication.service": %w`, err)}
}
}
if _, ok := _c.mutation.TokenType(); !ok {
return &ValidationError{Name: "token_type", err: errors.New(`ent: missing required field "Authentication.token_type"`)}
}
if v, ok := _c.mutation.TokenType(); ok {
if err := authentication.TokenTypeValidator(v); err != nil {
return &ValidationError{Name: "token_type", err: fmt.Errorf(`ent: validator failed for field "Authentication.token_type": %w`, err)}
}
}
if _, ok := _c.mutation.Identifier(); !ok {
return &ValidationError{Name: "identifier", err: errors.New(`ent: missing required field "Authentication.identifier"`)}
}
if _, ok := _c.mutation.Token(); !ok {
return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "Authentication.token"`)}
}
if v, ok := _c.mutation.Token(); ok {
if err := authentication.TokenValidator(v); err != nil {
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "Authentication.token": %w`, err)}
}
}
if _, ok := _c.mutation.Disabled(); !ok {
return &ValidationError{Name: "disabled", err: errors.New(`ent: missing required field "Authentication.disabled"`)}
}
if _, ok := _c.mutation.AccountAuthentication(); !ok {
return &ValidationError{Name: "account_authentication", err: errors.New(`ent: missing required field "Authentication.account_authentication"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := authentication.IDValidator(v.String()); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Authentication.id": %w`, err)}
}
}
if len(_c.mutation.AccountIDs()) == 0 {
return &ValidationError{Name: "account", err: errors.New(`ent: missing required edge "Authentication.account"`)}
}
return nil
}
func (_c *AuthenticationCreate) sqlSave(ctx context.Context) (*Authentication, 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.(*xid.ID); ok {
_node.ID = *id
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
return nil, err
}
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *AuthenticationCreate) createSpec() (*Authentication, *sqlgraph.CreateSpec) {
var (
_node = &Authentication{config: _c.config}
_spec = sqlgraph.NewCreateSpec(authentication.Table, sqlgraph.NewFieldSpec(authentication.FieldID, field.TypeString))
)
_spec.OnConflict = _c.conflict
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(authentication.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.ExpiresAt(); ok {
_spec.SetField(authentication.FieldExpiresAt, field.TypeTime, value)
_node.ExpiresAt = &value
}
if value, ok := _c.mutation.Service(); ok {
_spec.SetField(authentication.FieldService, field.TypeString, value)
_node.Service = value
}
if value, ok := _c.mutation.TokenType(); ok {
_spec.SetField(authentication.FieldTokenType, field.TypeString, value)
_node.TokenType = value
}
if value, ok := _c.mutation.Identifier(); ok {
_spec.SetField(authentication.FieldIdentifier, field.TypeString, value)
_node.Identifier = value
}
if value, ok := _c.mutation.Token(); ok {
_spec.SetField(authentication.FieldToken, field.TypeString, value)
_node.Token = value
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(authentication.FieldName, field.TypeString, value)
_node.Name = &value
}
if value, ok := _c.mutation.Disabled(); ok {
_spec.SetField(authentication.FieldDisabled, field.TypeBool, value)
_node.Disabled = value
}
if value, ok := _c.mutation.Metadata(); ok {
_spec.SetField(authentication.FieldMetadata, field.TypeJSON, value)
_node.Metadata = value
}
if nodes := _c.mutation.AccountIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: authentication.AccountTable,
Columns: []string{authentication.AccountColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.AccountAuthentication = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Authentication.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.AuthenticationUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *AuthenticationCreate) OnConflict(opts ...sql.ConflictOption) *AuthenticationUpsertOne {
_c.conflict = opts
return &AuthenticationUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Authentication.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *AuthenticationCreate) OnConflictColumns(columns ...string) *AuthenticationUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &AuthenticationUpsertOne{
create: _c,
}
}
type (
// AuthenticationUpsertOne is the builder for "upsert"-ing
// one Authentication node.
AuthenticationUpsertOne struct {
create *AuthenticationCreate
}
// AuthenticationUpsert is the "OnConflict" setter.
AuthenticationUpsert struct {
*sql.UpdateSet
}
)
// SetExpiresAt sets the "expires_at" field.
func (u *AuthenticationUpsert) SetExpiresAt(v time.Time) *AuthenticationUpsert {
u.Set(authentication.FieldExpiresAt, v)
return u
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateExpiresAt() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldExpiresAt)
return u
}
// ClearExpiresAt clears the value of the "expires_at" field.
func (u *AuthenticationUpsert) ClearExpiresAt() *AuthenticationUpsert {
u.SetNull(authentication.FieldExpiresAt)
return u
}
// SetService sets the "service" field.
func (u *AuthenticationUpsert) SetService(v string) *AuthenticationUpsert {
u.Set(authentication.FieldService, v)
return u
}
// UpdateService sets the "service" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateService() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldService)
return u
}
// SetTokenType sets the "token_type" field.
func (u *AuthenticationUpsert) SetTokenType(v string) *AuthenticationUpsert {
u.Set(authentication.FieldTokenType, v)
return u
}
// UpdateTokenType sets the "token_type" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateTokenType() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldTokenType)
return u
}
// SetIdentifier sets the "identifier" field.
func (u *AuthenticationUpsert) SetIdentifier(v string) *AuthenticationUpsert {
u.Set(authentication.FieldIdentifier, v)
return u
}
// UpdateIdentifier sets the "identifier" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateIdentifier() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldIdentifier)
return u
}
// SetToken sets the "token" field.
func (u *AuthenticationUpsert) SetToken(v string) *AuthenticationUpsert {
u.Set(authentication.FieldToken, v)
return u
}
// UpdateToken sets the "token" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateToken() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldToken)
return u
}
// SetName sets the "name" field.
func (u *AuthenticationUpsert) SetName(v string) *AuthenticationUpsert {
u.Set(authentication.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateName() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldName)
return u
}
// ClearName clears the value of the "name" field.
func (u *AuthenticationUpsert) ClearName() *AuthenticationUpsert {
u.SetNull(authentication.FieldName)
return u
}
// SetDisabled sets the "disabled" field.
func (u *AuthenticationUpsert) SetDisabled(v bool) *AuthenticationUpsert {
u.Set(authentication.FieldDisabled, v)
return u
}
// UpdateDisabled sets the "disabled" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateDisabled() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldDisabled)
return u
}
// SetMetadata sets the "metadata" field.
func (u *AuthenticationUpsert) SetMetadata(v map[string]interface{}) *AuthenticationUpsert {
u.Set(authentication.FieldMetadata, v)
return u
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateMetadata() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldMetadata)
return u
}
// ClearMetadata clears the value of the "metadata" field.
func (u *AuthenticationUpsert) ClearMetadata() *AuthenticationUpsert {
u.SetNull(authentication.FieldMetadata)
return u
}
// SetAccountAuthentication sets the "account_authentication" field.
func (u *AuthenticationUpsert) SetAccountAuthentication(v xid.ID) *AuthenticationUpsert {
u.Set(authentication.FieldAccountAuthentication, v)
return u
}
// UpdateAccountAuthentication sets the "account_authentication" field to the value that was provided on create.
func (u *AuthenticationUpsert) UpdateAccountAuthentication() *AuthenticationUpsert {
u.SetExcluded(authentication.FieldAccountAuthentication)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.Authentication.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(authentication.FieldID)
// }),
// ).
// Exec(ctx)
func (u *AuthenticationUpsertOne) UpdateNewValues() *AuthenticationUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.ID(); exists {
s.SetIgnore(authentication.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(authentication.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Authentication.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *AuthenticationUpsertOne) Ignore() *AuthenticationUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *AuthenticationUpsertOne) DoNothing() *AuthenticationUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the AuthenticationCreate.OnConflict
// documentation for more info.
func (u *AuthenticationUpsertOne) Update(set func(*AuthenticationUpsert)) *AuthenticationUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&AuthenticationUpsert{UpdateSet: update})
}))
return u
}
// SetExpiresAt sets the "expires_at" field.
func (u *AuthenticationUpsertOne) SetExpiresAt(v time.Time) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetExpiresAt(v)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateExpiresAt() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateExpiresAt()
})
}
// ClearExpiresAt clears the value of the "expires_at" field.
func (u *AuthenticationUpsertOne) ClearExpiresAt() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.ClearExpiresAt()
})
}
// SetService sets the "service" field.
func (u *AuthenticationUpsertOne) SetService(v string) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetService(v)
})
}
// UpdateService sets the "service" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateService() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateService()
})
}
// SetTokenType sets the "token_type" field.
func (u *AuthenticationUpsertOne) SetTokenType(v string) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetTokenType(v)
})
}
// UpdateTokenType sets the "token_type" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateTokenType() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateTokenType()
})
}
// SetIdentifier sets the "identifier" field.
func (u *AuthenticationUpsertOne) SetIdentifier(v string) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetIdentifier(v)
})
}
// UpdateIdentifier sets the "identifier" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateIdentifier() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateIdentifier()
})
}
// SetToken sets the "token" field.
func (u *AuthenticationUpsertOne) SetToken(v string) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetToken(v)
})
}
// UpdateToken sets the "token" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateToken() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateToken()
})
}
// SetName sets the "name" field.
func (u *AuthenticationUpsertOne) SetName(v string) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateName() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateName()
})
}
// ClearName clears the value of the "name" field.
func (u *AuthenticationUpsertOne) ClearName() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.ClearName()
})
}
// SetDisabled sets the "disabled" field.
func (u *AuthenticationUpsertOne) SetDisabled(v bool) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetDisabled(v)
})
}
// UpdateDisabled sets the "disabled" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateDisabled() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateDisabled()
})
}
// SetMetadata sets the "metadata" field.
func (u *AuthenticationUpsertOne) SetMetadata(v map[string]interface{}) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetMetadata(v)
})
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateMetadata() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateMetadata()
})
}
// ClearMetadata clears the value of the "metadata" field.
func (u *AuthenticationUpsertOne) ClearMetadata() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.ClearMetadata()
})
}
// SetAccountAuthentication sets the "account_authentication" field.
func (u *AuthenticationUpsertOne) SetAccountAuthentication(v xid.ID) *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.SetAccountAuthentication(v)
})
}
// UpdateAccountAuthentication sets the "account_authentication" field to the value that was provided on create.
func (u *AuthenticationUpsertOne) UpdateAccountAuthentication() *AuthenticationUpsertOne {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateAccountAuthentication()
})
}
// Exec executes the query.
func (u *AuthenticationUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for AuthenticationCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *AuthenticationUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *AuthenticationUpsertOne) ID(ctx context.Context) (id xid.ID, err error) {
if u.create.driver.Dialect() == dialect.MySQL {
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
// fields from the database since MySQL does not support the RETURNING clause.
return id, errors.New("ent: AuthenticationUpsertOne.ID is not supported by MySQL driver. Use AuthenticationUpsertOne.Exec instead")
}
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *AuthenticationUpsertOne) IDX(ctx context.Context) xid.ID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// AuthenticationCreateBulk is the builder for creating many Authentication entities in bulk.
type AuthenticationCreateBulk struct {
config
err error
builders []*AuthenticationCreate
conflict []sql.ConflictOption
}
// Save creates the Authentication entities in the database.
func (_c *AuthenticationCreateBulk) Save(ctx context.Context) ([]*Authentication, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Authentication, 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.(*AuthenticationMutation)
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}
spec.OnConflict = _c.conflict
// 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 *AuthenticationCreateBulk) SaveX(ctx context.Context) []*Authentication {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AuthenticationCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AuthenticationCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Authentication.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.AuthenticationUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *AuthenticationCreateBulk) OnConflict(opts ...sql.ConflictOption) *AuthenticationUpsertBulk {
_c.conflict = opts
return &AuthenticationUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Authentication.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *AuthenticationCreateBulk) OnConflictColumns(columns ...string) *AuthenticationUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &AuthenticationUpsertBulk{
create: _c,
}
}
// AuthenticationUpsertBulk is the builder for "upsert"-ing
// a bulk of Authentication nodes.
type AuthenticationUpsertBulk struct {
create *AuthenticationCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Authentication.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(authentication.FieldID)
// }),
// ).
// Exec(ctx)
func (u *AuthenticationUpsertBulk) UpdateNewValues() *AuthenticationUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.ID(); exists {
s.SetIgnore(authentication.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(authentication.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Authentication.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *AuthenticationUpsertBulk) Ignore() *AuthenticationUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *AuthenticationUpsertBulk) DoNothing() *AuthenticationUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the AuthenticationCreateBulk.OnConflict
// documentation for more info.
func (u *AuthenticationUpsertBulk) Update(set func(*AuthenticationUpsert)) *AuthenticationUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&AuthenticationUpsert{UpdateSet: update})
}))
return u
}
// SetExpiresAt sets the "expires_at" field.
func (u *AuthenticationUpsertBulk) SetExpiresAt(v time.Time) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetExpiresAt(v)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateExpiresAt() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateExpiresAt()
})
}
// ClearExpiresAt clears the value of the "expires_at" field.
func (u *AuthenticationUpsertBulk) ClearExpiresAt() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.ClearExpiresAt()
})
}
// SetService sets the "service" field.
func (u *AuthenticationUpsertBulk) SetService(v string) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetService(v)
})
}
// UpdateService sets the "service" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateService() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateService()
})
}
// SetTokenType sets the "token_type" field.
func (u *AuthenticationUpsertBulk) SetTokenType(v string) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetTokenType(v)
})
}
// UpdateTokenType sets the "token_type" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateTokenType() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateTokenType()
})
}
// SetIdentifier sets the "identifier" field.
func (u *AuthenticationUpsertBulk) SetIdentifier(v string) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetIdentifier(v)
})
}
// UpdateIdentifier sets the "identifier" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateIdentifier() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateIdentifier()
})
}
// SetToken sets the "token" field.
func (u *AuthenticationUpsertBulk) SetToken(v string) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetToken(v)
})
}
// UpdateToken sets the "token" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateToken() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateToken()
})
}
// SetName sets the "name" field.
func (u *AuthenticationUpsertBulk) SetName(v string) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateName() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateName()
})
}
// ClearName clears the value of the "name" field.
func (u *AuthenticationUpsertBulk) ClearName() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.ClearName()
})
}
// SetDisabled sets the "disabled" field.
func (u *AuthenticationUpsertBulk) SetDisabled(v bool) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetDisabled(v)
})
}
// UpdateDisabled sets the "disabled" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateDisabled() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateDisabled()
})
}
// SetMetadata sets the "metadata" field.
func (u *AuthenticationUpsertBulk) SetMetadata(v map[string]interface{}) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetMetadata(v)
})
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateMetadata() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateMetadata()
})
}
// ClearMetadata clears the value of the "metadata" field.
func (u *AuthenticationUpsertBulk) ClearMetadata() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.ClearMetadata()
})
}
// SetAccountAuthentication sets the "account_authentication" field.
func (u *AuthenticationUpsertBulk) SetAccountAuthentication(v xid.ID) *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.SetAccountAuthentication(v)
})
}
// UpdateAccountAuthentication sets the "account_authentication" field to the value that was provided on create.
func (u *AuthenticationUpsertBulk) UpdateAccountAuthentication() *AuthenticationUpsertBulk {
return u.Update(func(s *AuthenticationUpsert) {
s.UpdateAccountAuthentication()
})
}
// Exec executes the query.
func (u *AuthenticationUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AuthenticationCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for AuthenticationCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *AuthenticationUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}