[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
323
backend/ent/category_create.go
Normal file
323
backend/ent/category_create.go
Normal file
|
@ -0,0 +1,323 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
"tss-rocks-be/ent/category"
|
||||
"tss-rocks-be/ent/categorycontent"
|
||||
"tss-rocks-be/ent/daily"
|
||||
"tss-rocks-be/ent/post"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CategoryCreate is the builder for creating a Category entity.
|
||||
type CategoryCreate struct {
|
||||
config
|
||||
mutation *CategoryMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (cc *CategoryCreate) SetCreatedAt(t time.Time) *CategoryCreate {
|
||||
cc.mutation.SetCreatedAt(t)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (cc *CategoryCreate) SetNillableCreatedAt(t *time.Time) *CategoryCreate {
|
||||
if t != nil {
|
||||
cc.SetCreatedAt(*t)
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cc *CategoryCreate) SetUpdatedAt(t time.Time) *CategoryCreate {
|
||||
cc.mutation.SetUpdatedAt(t)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (cc *CategoryCreate) SetNillableUpdatedAt(t *time.Time) *CategoryCreate {
|
||||
if t != nil {
|
||||
cc.SetUpdatedAt(*t)
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
// AddContentIDs adds the "contents" edge to the CategoryContent entity by IDs.
|
||||
func (cc *CategoryCreate) AddContentIDs(ids ...int) *CategoryCreate {
|
||||
cc.mutation.AddContentIDs(ids...)
|
||||
return cc
|
||||
}
|
||||
|
||||
// AddContents adds the "contents" edges to the CategoryContent entity.
|
||||
func (cc *CategoryCreate) AddContents(c ...*CategoryContent) *CategoryCreate {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return cc.AddContentIDs(ids...)
|
||||
}
|
||||
|
||||
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||
func (cc *CategoryCreate) AddPostIDs(ids ...int) *CategoryCreate {
|
||||
cc.mutation.AddPostIDs(ids...)
|
||||
return cc
|
||||
}
|
||||
|
||||
// AddPosts adds the "posts" edges to the Post entity.
|
||||
func (cc *CategoryCreate) AddPosts(p ...*Post) *CategoryCreate {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return cc.AddPostIDs(ids...)
|
||||
}
|
||||
|
||||
// AddDailyItemIDs adds the "daily_items" edge to the Daily entity by IDs.
|
||||
func (cc *CategoryCreate) AddDailyItemIDs(ids ...string) *CategoryCreate {
|
||||
cc.mutation.AddDailyItemIDs(ids...)
|
||||
return cc
|
||||
}
|
||||
|
||||
// AddDailyItems adds the "daily_items" edges to the Daily entity.
|
||||
func (cc *CategoryCreate) AddDailyItems(d ...*Daily) *CategoryCreate {
|
||||
ids := make([]string, len(d))
|
||||
for i := range d {
|
||||
ids[i] = d[i].ID
|
||||
}
|
||||
return cc.AddDailyItemIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CategoryMutation object of the builder.
|
||||
func (cc *CategoryCreate) Mutation() *CategoryMutation {
|
||||
return cc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Category in the database.
|
||||
func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) {
|
||||
cc.defaults()
|
||||
return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (cc *CategoryCreate) SaveX(ctx context.Context) *Category {
|
||||
v, err := cc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cc *CategoryCreate) Exec(ctx context.Context) error {
|
||||
_, err := cc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cc *CategoryCreate) ExecX(ctx context.Context) {
|
||||
if err := cc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (cc *CategoryCreate) defaults() {
|
||||
if _, ok := cc.mutation.CreatedAt(); !ok {
|
||||
v := category.DefaultCreatedAt()
|
||||
cc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := cc.mutation.UpdatedAt(); !ok {
|
||||
v := category.DefaultUpdatedAt()
|
||||
cc.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cc *CategoryCreate) check() error {
|
||||
if _, ok := cc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Category.created_at"`)}
|
||||
}
|
||||
if _, ok := cc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Category.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cc *CategoryCreate) sqlSave(ctx context.Context) (*Category, error) {
|
||||
if err := cc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := cc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, cc.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)
|
||||
cc.mutation.id = &_node.ID
|
||||
cc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Category{config: cc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(category.Table, sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := cc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(category.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := cc.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(category.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if nodes := cc.mutation.ContentsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: category.ContentsTable,
|
||||
Columns: []string{category.ContentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(categorycontent.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := cc.mutation.PostsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: category.PostsTable,
|
||||
Columns: []string{category.PostsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := cc.mutation.DailyItemsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: category.DailyItemsTable,
|
||||
Columns: []string{category.DailyItemsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(daily.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// CategoryCreateBulk is the builder for creating many Category entities in bulk.
|
||||
type CategoryCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CategoryCreate
|
||||
}
|
||||
|
||||
// Save creates the Category entities in the database.
|
||||
func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) {
|
||||
if ccb.err != nil {
|
||||
return nil, ccb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
|
||||
nodes := make([]*Category, len(ccb.builders))
|
||||
mutators := make([]Mutator, len(ccb.builders))
|
||||
for i := range ccb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := ccb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CategoryMutation)
|
||||
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, ccb.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, ccb.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, ccb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ccb *CategoryCreateBulk) SaveX(ctx context.Context) []*Category {
|
||||
v, err := ccb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ccb *CategoryCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := ccb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ccb *CategoryCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := ccb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue