2024-08-19 13:55:36 +02:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.icod.de/auth/accountserver/ent/account"
|
|
|
|
"code.icod.de/auth/accountserver/ent/email"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EmailCreate is the builder for creating a Email entity.
|
|
|
|
type EmailCreate struct {
|
|
|
|
config
|
|
|
|
mutation *EmailMutation
|
|
|
|
hooks []Hook
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEmail sets the "email" field.
|
|
|
|
func (ec *EmailCreate) SetEmail(s string) *EmailCreate {
|
|
|
|
ec.mutation.SetEmail(s)
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPrimary sets the "primary" field.
|
|
|
|
func (ec *EmailCreate) SetPrimary(b bool) *EmailCreate {
|
|
|
|
ec.mutation.SetPrimary(b)
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillablePrimary sets the "primary" field if the given value is not nil.
|
|
|
|
func (ec *EmailCreate) SetNillablePrimary(b *bool) *EmailCreate {
|
|
|
|
if b != nil {
|
|
|
|
ec.SetPrimary(*b)
|
|
|
|
}
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVerified sets the "verified" field.
|
|
|
|
func (ec *EmailCreate) SetVerified(b bool) *EmailCreate {
|
|
|
|
ec.mutation.SetVerified(b)
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableVerified sets the "verified" field if the given value is not nil.
|
|
|
|
func (ec *EmailCreate) SetNillableVerified(b *bool) *EmailCreate {
|
|
|
|
if b != nil {
|
|
|
|
ec.SetVerified(*b)
|
|
|
|
}
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVerificationCode sets the "verification_code" field.
|
|
|
|
func (ec *EmailCreate) SetVerificationCode(s string) *EmailCreate {
|
|
|
|
ec.mutation.SetVerificationCode(s)
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableVerificationCode sets the "verification_code" field if the given value is not nil.
|
|
|
|
func (ec *EmailCreate) SetNillableVerificationCode(s *string) *EmailCreate {
|
|
|
|
if s != nil {
|
|
|
|
ec.SetVerificationCode(*s)
|
|
|
|
}
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetResetCode sets the "reset_code" field.
|
|
|
|
func (ec *EmailCreate) SetResetCode(s string) *EmailCreate {
|
|
|
|
ec.mutation.SetResetCode(s)
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableResetCode sets the "reset_code" field if the given value is not nil.
|
|
|
|
func (ec *EmailCreate) SetNillableResetCode(s *string) *EmailCreate {
|
|
|
|
if s != nil {
|
|
|
|
ec.SetResetCode(*s)
|
|
|
|
}
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetID sets the "id" field.
|
|
|
|
func (ec *EmailCreate) SetID(u uuid.UUID) *EmailCreate {
|
|
|
|
ec.mutation.SetID(u)
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
2024-09-03 15:56:34 +02:00
|
|
|
// SetAccountID sets the "account" edge to the Account entity by ID.
|
|
|
|
func (ec *EmailCreate) SetAccountID(id uuid.UUID) *EmailCreate {
|
|
|
|
ec.mutation.SetAccountID(id)
|
2024-08-19 13:55:36 +02:00
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
2024-09-03 15:56:34 +02:00
|
|
|
// SetNillableAccountID sets the "account" edge to the Account entity by ID if the given value is not nil.
|
|
|
|
func (ec *EmailCreate) SetNillableAccountID(id *uuid.UUID) *EmailCreate {
|
2024-08-19 13:55:36 +02:00
|
|
|
if id != nil {
|
2024-09-03 15:56:34 +02:00
|
|
|
ec = ec.SetAccountID(*id)
|
2024-08-19 13:55:36 +02:00
|
|
|
}
|
|
|
|
return ec
|
|
|
|
}
|
|
|
|
|
2024-09-03 15:56:34 +02:00
|
|
|
// SetAccount sets the "account" edge to the Account entity.
|
|
|
|
func (ec *EmailCreate) SetAccount(a *Account) *EmailCreate {
|
|
|
|
return ec.SetAccountID(a.ID)
|
2024-08-19 13:55:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the EmailMutation object of the builder.
|
|
|
|
func (ec *EmailCreate) Mutation() *EmailMutation {
|
|
|
|
return ec.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save creates the Email in the database.
|
|
|
|
func (ec *EmailCreate) Save(ctx context.Context) (*Email, error) {
|
|
|
|
ec.defaults()
|
|
|
|
return withHooks(ctx, ec.sqlSave, ec.mutation, ec.hooks)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
|
|
func (ec *EmailCreate) SaveX(ctx context.Context) *Email {
|
|
|
|
v, err := ec.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (ec *EmailCreate) Exec(ctx context.Context) error {
|
|
|
|
_, err := ec.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (ec *EmailCreate) ExecX(ctx context.Context) {
|
|
|
|
if err := ec.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
|
|
func (ec *EmailCreate) defaults() {
|
|
|
|
if _, ok := ec.mutation.Primary(); !ok {
|
|
|
|
v := email.DefaultPrimary
|
|
|
|
ec.mutation.SetPrimary(v)
|
|
|
|
}
|
|
|
|
if _, ok := ec.mutation.Verified(); !ok {
|
|
|
|
v := email.DefaultVerified
|
|
|
|
ec.mutation.SetVerified(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (ec *EmailCreate) check() error {
|
|
|
|
if _, ok := ec.mutation.Email(); !ok {
|
|
|
|
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "Email.email"`)}
|
|
|
|
}
|
|
|
|
if _, ok := ec.mutation.Primary(); !ok {
|
|
|
|
return &ValidationError{Name: "primary", err: errors.New(`ent: missing required field "Email.primary"`)}
|
|
|
|
}
|
|
|
|
if _, ok := ec.mutation.Verified(); !ok {
|
|
|
|
return &ValidationError{Name: "verified", err: errors.New(`ent: missing required field "Email.verified"`)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ec *EmailCreate) sqlSave(ctx context.Context) (*Email, error) {
|
|
|
|
if err := ec.check(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_node, _spec := ec.createSpec()
|
|
|
|
if err := sqlgraph.CreateNode(ctx, ec.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.(*uuid.UUID); ok {
|
|
|
|
_node.ID = *id
|
|
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ec.mutation.id = &_node.ID
|
|
|
|
ec.mutation.done = true
|
|
|
|
return _node, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ec *EmailCreate) createSpec() (*Email, *sqlgraph.CreateSpec) {
|
|
|
|
var (
|
|
|
|
_node = &Email{config: ec.config}
|
|
|
|
_spec = sqlgraph.NewCreateSpec(email.Table, sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID))
|
|
|
|
)
|
|
|
|
if id, ok := ec.mutation.ID(); ok {
|
|
|
|
_node.ID = id
|
|
|
|
_spec.ID.Value = &id
|
|
|
|
}
|
|
|
|
if value, ok := ec.mutation.Email(); ok {
|
|
|
|
_spec.SetField(email.FieldEmail, field.TypeString, value)
|
|
|
|
_node.Email = value
|
|
|
|
}
|
|
|
|
if value, ok := ec.mutation.Primary(); ok {
|
|
|
|
_spec.SetField(email.FieldPrimary, field.TypeBool, value)
|
|
|
|
_node.Primary = value
|
|
|
|
}
|
|
|
|
if value, ok := ec.mutation.Verified(); ok {
|
|
|
|
_spec.SetField(email.FieldVerified, field.TypeBool, value)
|
|
|
|
_node.Verified = value
|
|
|
|
}
|
|
|
|
if value, ok := ec.mutation.VerificationCode(); ok {
|
|
|
|
_spec.SetField(email.FieldVerificationCode, field.TypeString, value)
|
|
|
|
_node.VerificationCode = value
|
|
|
|
}
|
|
|
|
if value, ok := ec.mutation.ResetCode(); ok {
|
|
|
|
_spec.SetField(email.FieldResetCode, field.TypeString, value)
|
|
|
|
_node.ResetCode = value
|
|
|
|
}
|
2024-09-03 15:56:34 +02:00
|
|
|
if nodes := ec.mutation.AccountIDs(); len(nodes) > 0 {
|
2024-08-19 13:55:36 +02:00
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.M2O,
|
|
|
|
Inverse: true,
|
2024-09-03 15:56:34 +02:00
|
|
|
Table: email.AccountTable,
|
|
|
|
Columns: []string{email.AccountColumn},
|
2024-08-19 13:55:36 +02:00
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_node.account_emails = &nodes[0]
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
return _node, _spec
|
|
|
|
}
|
|
|
|
|
|
|
|
// EmailCreateBulk is the builder for creating many Email entities in bulk.
|
|
|
|
type EmailCreateBulk struct {
|
|
|
|
config
|
|
|
|
err error
|
|
|
|
builders []*EmailCreate
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save creates the Email entities in the database.
|
|
|
|
func (ecb *EmailCreateBulk) Save(ctx context.Context) ([]*Email, error) {
|
|
|
|
if ecb.err != nil {
|
|
|
|
return nil, ecb.err
|
|
|
|
}
|
|
|
|
specs := make([]*sqlgraph.CreateSpec, len(ecb.builders))
|
|
|
|
nodes := make([]*Email, len(ecb.builders))
|
|
|
|
mutators := make([]Mutator, len(ecb.builders))
|
|
|
|
for i := range ecb.builders {
|
|
|
|
func(i int, root context.Context) {
|
|
|
|
builder := ecb.builders[i]
|
|
|
|
builder.defaults()
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*EmailMutation)
|
|
|
|
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, ecb.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, ecb.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, ecb.builders[0].mutation); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
func (ecb *EmailCreateBulk) SaveX(ctx context.Context) []*Email {
|
|
|
|
v, err := ecb.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (ecb *EmailCreateBulk) Exec(ctx context.Context) error {
|
|
|
|
_, err := ecb.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (ecb *EmailCreateBulk) ExecX(ctx context.Context) {
|
|
|
|
if err := ecb.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|