[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
243
backend/ent/dailycontent_create.go
Normal file
243
backend/ent/dailycontent_create.go
Normal file
|
@ -0,0 +1,243 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"tss-rocks-be/ent/daily"
|
||||
"tss-rocks-be/ent/dailycontent"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DailyContentCreate is the builder for creating a DailyContent entity.
|
||||
type DailyContentCreate struct {
|
||||
config
|
||||
mutation *DailyContentMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetLanguageCode sets the "language_code" field.
|
||||
func (dcc *DailyContentCreate) SetLanguageCode(dc dailycontent.LanguageCode) *DailyContentCreate {
|
||||
dcc.mutation.SetLanguageCode(dc)
|
||||
return dcc
|
||||
}
|
||||
|
||||
// SetQuote sets the "quote" field.
|
||||
func (dcc *DailyContentCreate) SetQuote(s string) *DailyContentCreate {
|
||||
dcc.mutation.SetQuote(s)
|
||||
return dcc
|
||||
}
|
||||
|
||||
// SetDailyID sets the "daily" edge to the Daily entity by ID.
|
||||
func (dcc *DailyContentCreate) SetDailyID(id string) *DailyContentCreate {
|
||||
dcc.mutation.SetDailyID(id)
|
||||
return dcc
|
||||
}
|
||||
|
||||
// SetNillableDailyID sets the "daily" edge to the Daily entity by ID if the given value is not nil.
|
||||
func (dcc *DailyContentCreate) SetNillableDailyID(id *string) *DailyContentCreate {
|
||||
if id != nil {
|
||||
dcc = dcc.SetDailyID(*id)
|
||||
}
|
||||
return dcc
|
||||
}
|
||||
|
||||
// SetDaily sets the "daily" edge to the Daily entity.
|
||||
func (dcc *DailyContentCreate) SetDaily(d *Daily) *DailyContentCreate {
|
||||
return dcc.SetDailyID(d.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the DailyContentMutation object of the builder.
|
||||
func (dcc *DailyContentCreate) Mutation() *DailyContentMutation {
|
||||
return dcc.mutation
|
||||
}
|
||||
|
||||
// Save creates the DailyContent in the database.
|
||||
func (dcc *DailyContentCreate) Save(ctx context.Context) (*DailyContent, error) {
|
||||
return withHooks(ctx, dcc.sqlSave, dcc.mutation, dcc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (dcc *DailyContentCreate) SaveX(ctx context.Context) *DailyContent {
|
||||
v, err := dcc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (dcc *DailyContentCreate) Exec(ctx context.Context) error {
|
||||
_, err := dcc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (dcc *DailyContentCreate) ExecX(ctx context.Context) {
|
||||
if err := dcc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (dcc *DailyContentCreate) check() error {
|
||||
if _, ok := dcc.mutation.LanguageCode(); !ok {
|
||||
return &ValidationError{Name: "language_code", err: errors.New(`ent: missing required field "DailyContent.language_code"`)}
|
||||
}
|
||||
if v, ok := dcc.mutation.LanguageCode(); ok {
|
||||
if err := dailycontent.LanguageCodeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "DailyContent.language_code": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := dcc.mutation.Quote(); !ok {
|
||||
return &ValidationError{Name: "quote", err: errors.New(`ent: missing required field "DailyContent.quote"`)}
|
||||
}
|
||||
if v, ok := dcc.mutation.Quote(); ok {
|
||||
if err := dailycontent.QuoteValidator(v); err != nil {
|
||||
return &ValidationError{Name: "quote", err: fmt.Errorf(`ent: validator failed for field "DailyContent.quote": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dcc *DailyContentCreate) sqlSave(ctx context.Context) (*DailyContent, error) {
|
||||
if err := dcc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := dcc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, dcc.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)
|
||||
dcc.mutation.id = &_node.ID
|
||||
dcc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (dcc *DailyContentCreate) createSpec() (*DailyContent, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &DailyContent{config: dcc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(dailycontent.Table, sqlgraph.NewFieldSpec(dailycontent.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := dcc.mutation.LanguageCode(); ok {
|
||||
_spec.SetField(dailycontent.FieldLanguageCode, field.TypeEnum, value)
|
||||
_node.LanguageCode = value
|
||||
}
|
||||
if value, ok := dcc.mutation.Quote(); ok {
|
||||
_spec.SetField(dailycontent.FieldQuote, field.TypeString, value)
|
||||
_node.Quote = value
|
||||
}
|
||||
if nodes := dcc.mutation.DailyIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: dailycontent.DailyTable,
|
||||
Columns: []string{dailycontent.DailyColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(daily.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.daily_contents = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// DailyContentCreateBulk is the builder for creating many DailyContent entities in bulk.
|
||||
type DailyContentCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*DailyContentCreate
|
||||
}
|
||||
|
||||
// Save creates the DailyContent entities in the database.
|
||||
func (dccb *DailyContentCreateBulk) Save(ctx context.Context) ([]*DailyContent, error) {
|
||||
if dccb.err != nil {
|
||||
return nil, dccb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(dccb.builders))
|
||||
nodes := make([]*DailyContent, len(dccb.builders))
|
||||
mutators := make([]Mutator, len(dccb.builders))
|
||||
for i := range dccb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := dccb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*DailyContentMutation)
|
||||
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, dccb.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, dccb.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, dccb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (dccb *DailyContentCreateBulk) SaveX(ctx context.Context) []*DailyContent {
|
||||
v, err := dccb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (dccb *DailyContentCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := dccb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (dccb *DailyContentCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := dccb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue