mirror of
https://github.com/kevin-DL/football_info_api.git
synced 2026-01-22 14:35:29 +00:00
Initial commit
This commit is contained in:
273
ent/profile_create.go
Normal file
273
ent/profile_create.go
Normal file
@@ -0,0 +1,273 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"football_api/ent/profile"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ProfileCreate is the builder for creating a Profile entity.
|
||||
type ProfileCreate struct {
|
||||
config
|
||||
mutation *ProfileMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetDisplayName sets the "display_name" field.
|
||||
func (pc *ProfileCreate) SetDisplayName(s string) *ProfileCreate {
|
||||
pc.mutation.SetDisplayName(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (pc *ProfileCreate) SetUserID(u uuid.UUID) *ProfileCreate {
|
||||
pc.mutation.SetUserID(u)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (pc *ProfileCreate) SetCreatedAt(t time.Time) *ProfileCreate {
|
||||
pc.mutation.SetCreatedAt(t)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (pc *ProfileCreate) SetNillableCreatedAt(t *time.Time) *ProfileCreate {
|
||||
if t != nil {
|
||||
pc.SetCreatedAt(*t)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (pc *ProfileCreate) SetUpdatedAt(t time.Time) *ProfileCreate {
|
||||
pc.mutation.SetUpdatedAt(t)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (pc *ProfileCreate) SetNillableUpdatedAt(t *time.Time) *ProfileCreate {
|
||||
if t != nil {
|
||||
pc.SetUpdatedAt(*t)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (pc *ProfileCreate) SetID(u uuid.UUID) *ProfileCreate {
|
||||
pc.mutation.SetID(u)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (pc *ProfileCreate) SetNillableID(u *uuid.UUID) *ProfileCreate {
|
||||
if u != nil {
|
||||
pc.SetID(*u)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// Mutation returns the ProfileMutation object of the builder.
|
||||
func (pc *ProfileCreate) Mutation() *ProfileMutation {
|
||||
return pc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Profile in the database.
|
||||
func (pc *ProfileCreate) Save(ctx context.Context) (*Profile, error) {
|
||||
pc.defaults()
|
||||
return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (pc *ProfileCreate) SaveX(ctx context.Context) *Profile {
|
||||
v, err := pc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pc *ProfileCreate) Exec(ctx context.Context) error {
|
||||
_, err := pc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pc *ProfileCreate) ExecX(ctx context.Context) {
|
||||
if err := pc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (pc *ProfileCreate) defaults() {
|
||||
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||
v := profile.DefaultCreatedAt()
|
||||
pc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := pc.mutation.UpdatedAt(); !ok {
|
||||
v := profile.DefaultUpdatedAt()
|
||||
pc.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := pc.mutation.ID(); !ok {
|
||||
v := profile.DefaultID()
|
||||
pc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (pc *ProfileCreate) check() error {
|
||||
if _, ok := pc.mutation.DisplayName(); !ok {
|
||||
return &ValidationError{Name: "display_name", err: errors.New(`ent: missing required field "Profile.display_name"`)}
|
||||
}
|
||||
if _, ok := pc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Profile.user_id"`)}
|
||||
}
|
||||
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Profile.created_at"`)}
|
||||
}
|
||||
if _, ok := pc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Profile.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pc *ProfileCreate) sqlSave(ctx context.Context) (*Profile, error) {
|
||||
if err := pc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := pc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, pc.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
|
||||
}
|
||||
}
|
||||
pc.mutation.id = &_node.ID
|
||||
pc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (pc *ProfileCreate) createSpec() (*Profile, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Profile{config: pc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(profile.Table, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID))
|
||||
)
|
||||
if id, ok := pc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := pc.mutation.DisplayName(); ok {
|
||||
_spec.SetField(profile.FieldDisplayName, field.TypeString, value)
|
||||
_node.DisplayName = value
|
||||
}
|
||||
if value, ok := pc.mutation.UserID(); ok {
|
||||
_spec.SetField(profile.FieldUserID, field.TypeUUID, value)
|
||||
_node.UserID = value
|
||||
}
|
||||
if value, ok := pc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(profile.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := pc.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ProfileCreateBulk is the builder for creating many Profile entities in bulk.
|
||||
type ProfileCreateBulk struct {
|
||||
config
|
||||
builders []*ProfileCreate
|
||||
}
|
||||
|
||||
// Save creates the Profile entities in the database.
|
||||
func (pcb *ProfileCreateBulk) Save(ctx context.Context) ([]*Profile, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(pcb.builders))
|
||||
nodes := make([]*Profile, len(pcb.builders))
|
||||
mutators := make([]Mutator, len(pcb.builders))
|
||||
for i := range pcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := pcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ProfileMutation)
|
||||
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, pcb.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, pcb.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, pcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (pcb *ProfileCreateBulk) SaveX(ctx context.Context) []*Profile {
|
||||
v, err := pcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pcb *ProfileCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := pcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pcb *ProfileCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := pcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user