[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
243
backend/ent/dailycategorycontent_create.go
Normal file
243
backend/ent/dailycategorycontent_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/dailycategory"
|
||||
"tss-rocks-be/ent/dailycategorycontent"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DailyCategoryContentCreate is the builder for creating a DailyCategoryContent entity.
|
||||
type DailyCategoryContentCreate struct {
|
||||
config
|
||||
mutation *DailyCategoryContentMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetLanguageCode sets the "language_code" field.
|
||||
func (dccc *DailyCategoryContentCreate) SetLanguageCode(dc dailycategorycontent.LanguageCode) *DailyCategoryContentCreate {
|
||||
dccc.mutation.SetLanguageCode(dc)
|
||||
return dccc
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (dccc *DailyCategoryContentCreate) SetName(s string) *DailyCategoryContentCreate {
|
||||
dccc.mutation.SetName(s)
|
||||
return dccc
|
||||
}
|
||||
|
||||
// SetCategoryID sets the "category" edge to the DailyCategory entity by ID.
|
||||
func (dccc *DailyCategoryContentCreate) SetCategoryID(id int) *DailyCategoryContentCreate {
|
||||
dccc.mutation.SetCategoryID(id)
|
||||
return dccc
|
||||
}
|
||||
|
||||
// SetNillableCategoryID sets the "category" edge to the DailyCategory entity by ID if the given value is not nil.
|
||||
func (dccc *DailyCategoryContentCreate) SetNillableCategoryID(id *int) *DailyCategoryContentCreate {
|
||||
if id != nil {
|
||||
dccc = dccc.SetCategoryID(*id)
|
||||
}
|
||||
return dccc
|
||||
}
|
||||
|
||||
// SetCategory sets the "category" edge to the DailyCategory entity.
|
||||
func (dccc *DailyCategoryContentCreate) SetCategory(d *DailyCategory) *DailyCategoryContentCreate {
|
||||
return dccc.SetCategoryID(d.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the DailyCategoryContentMutation object of the builder.
|
||||
func (dccc *DailyCategoryContentCreate) Mutation() *DailyCategoryContentMutation {
|
||||
return dccc.mutation
|
||||
}
|
||||
|
||||
// Save creates the DailyCategoryContent in the database.
|
||||
func (dccc *DailyCategoryContentCreate) Save(ctx context.Context) (*DailyCategoryContent, error) {
|
||||
return withHooks(ctx, dccc.sqlSave, dccc.mutation, dccc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (dccc *DailyCategoryContentCreate) SaveX(ctx context.Context) *DailyCategoryContent {
|
||||
v, err := dccc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (dccc *DailyCategoryContentCreate) Exec(ctx context.Context) error {
|
||||
_, err := dccc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (dccc *DailyCategoryContentCreate) ExecX(ctx context.Context) {
|
||||
if err := dccc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (dccc *DailyCategoryContentCreate) check() error {
|
||||
if _, ok := dccc.mutation.LanguageCode(); !ok {
|
||||
return &ValidationError{Name: "language_code", err: errors.New(`ent: missing required field "DailyCategoryContent.language_code"`)}
|
||||
}
|
||||
if v, ok := dccc.mutation.LanguageCode(); ok {
|
||||
if err := dailycategorycontent.LanguageCodeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "DailyCategoryContent.language_code": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := dccc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "DailyCategoryContent.name"`)}
|
||||
}
|
||||
if v, ok := dccc.mutation.Name(); ok {
|
||||
if err := dailycategorycontent.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "DailyCategoryContent.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dccc *DailyCategoryContentCreate) sqlSave(ctx context.Context) (*DailyCategoryContent, error) {
|
||||
if err := dccc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := dccc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, dccc.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)
|
||||
dccc.mutation.id = &_node.ID
|
||||
dccc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (dccc *DailyCategoryContentCreate) createSpec() (*DailyCategoryContent, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &DailyCategoryContent{config: dccc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(dailycategorycontent.Table, sqlgraph.NewFieldSpec(dailycategorycontent.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := dccc.mutation.LanguageCode(); ok {
|
||||
_spec.SetField(dailycategorycontent.FieldLanguageCode, field.TypeEnum, value)
|
||||
_node.LanguageCode = value
|
||||
}
|
||||
if value, ok := dccc.mutation.Name(); ok {
|
||||
_spec.SetField(dailycategorycontent.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := dccc.mutation.CategoryIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: dailycategorycontent.CategoryTable,
|
||||
Columns: []string{dailycategorycontent.CategoryColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(dailycategory.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.daily_category_contents = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// DailyCategoryContentCreateBulk is the builder for creating many DailyCategoryContent entities in bulk.
|
||||
type DailyCategoryContentCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*DailyCategoryContentCreate
|
||||
}
|
||||
|
||||
// Save creates the DailyCategoryContent entities in the database.
|
||||
func (dcccb *DailyCategoryContentCreateBulk) Save(ctx context.Context) ([]*DailyCategoryContent, error) {
|
||||
if dcccb.err != nil {
|
||||
return nil, dcccb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(dcccb.builders))
|
||||
nodes := make([]*DailyCategoryContent, len(dcccb.builders))
|
||||
mutators := make([]Mutator, len(dcccb.builders))
|
||||
for i := range dcccb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := dcccb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*DailyCategoryContentMutation)
|
||||
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, dcccb.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, dcccb.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, dcccb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (dcccb *DailyCategoryContentCreateBulk) SaveX(ctx context.Context) []*DailyCategoryContent {
|
||||
v, err := dcccb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (dcccb *DailyCategoryContentCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := dcccb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (dcccb *DailyCategoryContentCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := dcccb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue