feat: update
This commit is contained in:
@@ -1,225 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
|
||||
)
|
||||
|
||||
//go:embed table.go.tpl
|
||||
var tableTpl string
|
||||
|
||||
//go:embed table_funcs.go.tpl
|
||||
var tableFuncsTpl string
|
||||
|
||||
//go:embed table_test.go.tpl
|
||||
var tableTestTpl string
|
||||
|
||||
//go:embed provider.gen.go.tpl
|
||||
var providerTplStr string
|
||||
|
||||
type TableModelParam struct {
|
||||
PkgName string
|
||||
CamelTable string // user
|
||||
PascalTable string // User
|
||||
SoftDelete bool
|
||||
HasUpdatedAt bool
|
||||
HasCreatedAt bool
|
||||
}
|
||||
|
||||
func Generate(tables []string, transformer Transformer) error {
|
||||
baseDir := "app/model"
|
||||
modelDir := "database/schemas/public/model"
|
||||
tableDir := "database/schemas/public/table"
|
||||
defer func() {
|
||||
os.RemoveAll("database/schemas")
|
||||
}()
|
||||
|
||||
os.RemoveAll("database/table")
|
||||
// move tableDir to database/table
|
||||
if err := os.Rename(tableDir, "database/table"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove all files in app/model with ext .gen.go
|
||||
files, err := os.ReadDir(baseDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if strings.HasSuffix(file.Name(), ".gen.go") {
|
||||
if err := os.RemoveAll(filepath.Join(baseDir, file.Name())); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// move files remove ext .go to .gen.go
|
||||
files, err = os.ReadDir(modelDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
modelContent := make(map[string]string)
|
||||
for _, file := range files {
|
||||
// get filename without ext
|
||||
name := strings.TrimSuffix(file.Name(), filepath.Ext(file.Name()))
|
||||
|
||||
from := filepath.Join(modelDir, file.Name())
|
||||
to := filepath.Join(baseDir, name+".gen.go")
|
||||
log.Infof("Move %s to %s", from, to)
|
||||
if err := os.Rename(from, to); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// read file content
|
||||
content, err := os.ReadFile(to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
modelContent[name] = string(content)
|
||||
}
|
||||
|
||||
// remove database/schemas/public/model
|
||||
if err := os.RemoveAll(modelDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tableTpl := template.Must(template.New("model").Parse(string(tableTpl)))
|
||||
tableFuncsTpl := template.Must(template.New("model").Parse(string(tableFuncsTpl)))
|
||||
tableTestTpl := template.Must(template.New("model").Parse(string(tableTestTpl)))
|
||||
providerTpl := template.Must(template.New("modelGen").Parse(string(providerTplStr)))
|
||||
|
||||
items := []TableModelParam{}
|
||||
for _, table := range tables {
|
||||
if lo.Contains(transformer.Ignores.Model, table) {
|
||||
log.Printf("[WARN] skip model %s\n", table)
|
||||
continue
|
||||
}
|
||||
|
||||
tableInfo := TableModelParam{
|
||||
CamelTable: lo.CamelCase(table),
|
||||
PascalTable: lo.PascalCase(table),
|
||||
PkgName: gomod.GetModuleName(),
|
||||
SoftDelete: strings.Contains(modelContent[table], "DeletedAt"),
|
||||
HasUpdatedAt: strings.Contains(modelContent[table], "UpdatedAt"),
|
||||
HasCreatedAt: strings.Contains(modelContent[table], "CreatedAt"),
|
||||
}
|
||||
|
||||
items = append(items, tableInfo)
|
||||
|
||||
// tableFuncsFile
|
||||
tableFuncsFile := fmt.Sprintf("%s/%s.funcs.gen.go", baseDir, table)
|
||||
// 如果 modelFuncsFile 已存在,则跳过
|
||||
if _, err := os.Stat(tableFuncsFile); err == nil {
|
||||
fmt.Printf("Model funcs file %s already exists. Skipping...\n", tableFuncsFile)
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果 modelFuncsFile 不存在,则创建
|
||||
fd, err := os.Create(tableFuncsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create model funcs file %s: %w", tableFuncsFile, err)
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
if err := tableFuncsTpl.Execute(fd, tableInfo); err != nil {
|
||||
return fmt.Errorf("failed to render model funcs template: %w", err)
|
||||
}
|
||||
|
||||
modelFile := fmt.Sprintf("%s/%s.go", baseDir, table)
|
||||
// 如果 modelFile 已存在,则跳过
|
||||
if _, err := os.Stat(modelFile); err == nil {
|
||||
fmt.Printf("Model file %s already exists. Skipping...\n", modelFile)
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果 modelFile 不存在,则创建
|
||||
fd, err = os.Create(modelFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create model file %s: %w", modelFile, err)
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
if err := tableTpl.Execute(fd, tableInfo); err != nil {
|
||||
return fmt.Errorf("failed to render model template: %w", err)
|
||||
}
|
||||
|
||||
modelTestFile := fmt.Sprintf("%s/%s_test.go", baseDir, table)
|
||||
// 如果 modelTestFile 已存在,则跳过
|
||||
if _, err := os.Stat(modelTestFile); err == nil {
|
||||
fmt.Printf("Model test file %s already exists. Skipping...\n", modelTestFile)
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果 modelTestFile 不存在,则创建
|
||||
fd, err = os.Create(modelTestFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create model test file %s: %w", modelTestFile, err)
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
if err := tableTestTpl.Execute(fd, tableInfo); err != nil {
|
||||
return fmt.Errorf("failed to render model test template: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 渲染总的 provider 文件
|
||||
providerFile := fmt.Sprintf("%s/provider.gen.go", baseDir)
|
||||
os.Remove(providerFile)
|
||||
fd, err := os.Create(providerFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create provider file %s: %w", providerFile, err)
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
if err := providerTpl.Execute(fd, items); err != nil {
|
||||
return fmt.Errorf("failed to render model template: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addProviderComment(filePath string) error {
|
||||
file, err := os.OpenFile(filePath, os.O_RDWR, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
content, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(string(content), "// @provider") {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write this comment to the up line of the type xxx struct
|
||||
newLines := []string{}
|
||||
lines := strings.Split(string(content), "\n")
|
||||
for i, line := range lines {
|
||||
if strings.Contains(line, "type ") && strings.Contains(line, "struct") {
|
||||
newLines = append(newLines, "// @provider")
|
||||
// append rest lines
|
||||
newLines = append(newLines, lines[i:]...)
|
||||
break
|
||||
}
|
||||
newLines = append(newLines, line)
|
||||
}
|
||||
newContent := strings.Join(newLines, "\n")
|
||||
if _, err := file.WriteAt([]byte(newContent), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
package model
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
|
||||
{{ if gt (len .) 0 }}
|
||||
"{{ (index . 0).PkgName }}/database/table"
|
||||
{{ end }}
|
||||
|
||||
"go.ipao.vip/atom"
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.ipao.vip/atom/opt"
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
type Cond func(BoolExpression) BoolExpression
|
||||
|
||||
func ExprCond(expr BoolExpression) Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(expr)
|
||||
}
|
||||
}
|
||||
|
||||
func CondTrue(conds ...Cond) BoolExpression {
|
||||
cond:= BoolExp(Bool(true))
|
||||
for _, c := range conds {
|
||||
cond = c(cond)
|
||||
}
|
||||
return cond
|
||||
}
|
||||
|
||||
func CondJoin(cond Cond, conds ...Cond) []Cond {
|
||||
return append([]Cond{cond}, conds...)
|
||||
}
|
||||
|
||||
// converts
|
||||
func IntExprSlice[T constraints.Integer](slice []T) []Expression {
|
||||
if len(slice) == 0 { return nil }
|
||||
|
||||
return lo.Map(slice, func(item T, _ int) Expression {
|
||||
switch any(item).(type) {
|
||||
case int8:
|
||||
return Int8(int8(item))
|
||||
case int16:
|
||||
return Int16(int16(item))
|
||||
case int32:
|
||||
return Int32(int32(item))
|
||||
case int64:
|
||||
return Int64(int64(item))
|
||||
case uint8:
|
||||
return Uint8(uint8(item))
|
||||
case uint16:
|
||||
return Uint16(uint16(item))
|
||||
case uint32:
|
||||
return Uint32(uint32(item))
|
||||
case uint64:
|
||||
return Uint64(uint64(item))
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// tables
|
||||
{{- range . }}
|
||||
var tbl{{.PascalTable}} = table.{{.PascalTable}}
|
||||
{{- end }}
|
||||
|
||||
|
||||
// models
|
||||
var db *sql.DB
|
||||
{{- range . }}
|
||||
func {{.PascalTable}}Model() *{{.PascalTable}} { return &{{.PascalTable}}{} }
|
||||
{{- end }}
|
||||
|
||||
func Transaction(ctx context.Context) (*sql.Tx, error) { return db.Begin() }
|
||||
|
||||
func DB() *sql.DB { return db }
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func( _db *sql.DB,) (contracts.Initial, error) {
|
||||
db = _db
|
||||
return nil, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package model
|
||||
|
||||
var tbl{{.PascalTable}}UpdateMutableColumns = tbl{{.PascalTable}}.MutableColumns.Except(
|
||||
{{- if .HasCreatedAt}}
|
||||
tbl{{.PascalTable}}.CreatedAt,
|
||||
{{- end}}
|
||||
|
||||
{{- if .SoftDelete}}
|
||||
tbl{{.PascalTable}}.DeletedAt,
|
||||
{{- end}}
|
||||
)
|
||||
@@ -1,227 +0,0 @@
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"github.com/samber/lo"
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
// conds
|
||||
{{- if .SoftDelete }}
|
||||
func (m *{{.PascalTable}}) CondNotDeleted() Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(tbl{{.PascalTable}}.DeletedAt.IS_NULL())
|
||||
}
|
||||
}
|
||||
|
||||
func (m *{{.PascalTable}}) CondDeleted() Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(tbl{{.PascalTable}}.DeletedAt.IS_NOT_NULL())
|
||||
}
|
||||
}
|
||||
{{- end}}
|
||||
|
||||
func (m *{{.PascalTable}}) CondID(id int64) Cond {
|
||||
return func(cond BoolExpression) BoolExpression {
|
||||
return cond.AND(tbl{{.PascalTable}}.ID.EQ(Int(id)))
|
||||
}
|
||||
}
|
||||
|
||||
// funcs
|
||||
func (m *{{.PascalTable}}) log() *log.Entry {
|
||||
return log.WithField("model", "{{.PascalTable}}")
|
||||
}
|
||||
|
||||
func (m *{{.PascalTable}}) Create(ctx context.Context) error {
|
||||
{{- if .HasCreatedAt}}
|
||||
m.CreatedAt = time.Now()
|
||||
{{- end}}
|
||||
|
||||
{{- if .HasUpdatedAt}}
|
||||
m.UpdatedAt = time.Now()
|
||||
{{- end}}
|
||||
|
||||
|
||||
stmt := tbl{{.PascalTable}}.INSERT(tbl{{.PascalTable}}.MutableColumns).MODEL(m).RETURNING(tbl{{.PascalTable}}.AllColumns)
|
||||
m.log().WithField("func","Create").Info( stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","Create").Errorf("error creating {{.PascalTable}} item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func","Create").Infof("{{.PascalTable}} item created successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (m *{{.PascalTable}}) BatchCreate(ctx context.Context, models []*{{.PascalTable}}) error {
|
||||
stmt := tbl{{.PascalTable}}.INSERT(tbl{{.PascalTable}}.MutableColumns).MODELS(models)
|
||||
m.log().WithField("func", "BatchCreate").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log().WithField("func","Create").Errorf("error creating {{.PascalTable}} item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchCreate").Infof("{{.PascalTable}} items created successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
{{- if .SoftDelete }}
|
||||
func (m *{{.PascalTable}}) Delete(ctx context.Context) error {
|
||||
stmt := tbl{{.PascalTable}}.UPDATE().SET(tbl{{.PascalTable}}.DeletedAt.SET(TimestampT(time.Now()))).WHERE(tbl{{.PascalTable}}.ID.EQ(Int(m.ID)))
|
||||
m.log().WithField("func", "SoftDelete").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","SoftDelete").Errorf("error soft deleting {{.PascalTable}} item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "SoftDelete").Infof("{{.PascalTable}} item soft deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// BatchDelete
|
||||
func (m *{{.PascalTable}}) BatchDelete(ctx context.Context, ids []int64) error {
|
||||
condIds := lo.Map(ids, func(id int64, _ int) Expression {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
stmt := tbl{{.PascalTable}}.UPDATE().SET(tbl{{.PascalTable}}.DeletedAt.SET(TimestampT(time.Now()))).WHERE(tbl{{.PascalTable}}.ID.IN(condIds...))
|
||||
m.log().WithField("func", "BatchSoftDelete").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","BatchSoftDelete").Errorf("error soft deleting {{.PascalTable}} items: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchSoftDelete").WithField("ids", ids).Infof("{{.PascalTable}} items soft deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (m *{{.PascalTable}}) ForceDelete(ctx context.Context) error {
|
||||
stmt := tbl{{.PascalTable}}.DELETE().WHERE(tbl{{.PascalTable}}.ID.EQ(Int(m.ID)))
|
||||
m.log().WithField("func", "Delete").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log().WithField("func","Delete").Errorf("error deleting {{.PascalTable}} item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "Delete").Infof("{{.PascalTable}} item deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *{{.PascalTable}}) BatchForceDelete(ctx context.Context, ids []int64) error {
|
||||
condIds := lo.Map(ids, func(id int64, _ int) Expression {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
stmt := tbl{{.PascalTable}}.DELETE().WHERE(tbl{{.PascalTable}}.ID.IN(condIds...))
|
||||
m.log().WithField("func", "BatchDelete").Info(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log().WithField("func","BatchForceDelete").Errorf("error deleting {{.PascalTable}} items: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchForceDelete").WithField("ids", ids).Infof("{{.PascalTable}} items deleted successfully")
|
||||
return nil
|
||||
}
|
||||
{{- else}}
|
||||
func (m *{{.PascalTable}}) Delete(ctx context.Context) error {
|
||||
stmt := tbl{{.PascalTable}}.DELETE().WHERE(tbl{{.PascalTable}}.ID.EQ(Int(m.ID)))
|
||||
m.log().WithField("func", "Delete").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","Delete").Errorf("error deleting {{.PascalTable}} item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "Delete").Infof("{{.PascalTable}} item deleted successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// BatchDelete
|
||||
func (m *{{.PascalTable}}) BatchDelete(ctx context.Context, ids []int64) error {
|
||||
condIds := lo.Map(ids, func(id int64, _ int) Expression {
|
||||
return Int64(id)
|
||||
})
|
||||
|
||||
stmt := tbl{{.PascalTable}}.DELETE().WHERE(tbl{{.PascalTable}}.ID.IN(condIds...))
|
||||
m.log().WithField("func", "BatchDelete").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","BatchDelete").Errorf("error deleting {{.PascalTable}} items: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "BatchDelete").WithField("ids", ids).Infof("{{.PascalTable}} items deleted successfully")
|
||||
return nil
|
||||
}
|
||||
{{- end}}
|
||||
|
||||
func (m *{{.PascalTable}}) Update(ctx context.Context) error {
|
||||
{{- if .HasUpdatedAt}}
|
||||
m.UpdatedAt = time.Now()
|
||||
{{- end}}
|
||||
|
||||
stmt := tbl{{.PascalTable}}.UPDATE(tbl{{.PascalTable}}UpdateMutableColumns).MODEL(m).WHERE(tbl{{.PascalTable}}.ID.EQ(Int(m.ID))).RETURNING(tbl{{.PascalTable}}.AllColumns)
|
||||
m.log().WithField("func", "Update").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","Update").Errorf("error updating {{.PascalTable}} item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "Update").Infof("{{.PascalTable}} item updated successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByCond
|
||||
func (m *{{.PascalTable}}) GetByCond(ctx context.Context, conds ...Cond) (*{{.PascalTable}}, error) {
|
||||
cond := CondTrue(conds...)
|
||||
|
||||
stmt := tbl{{.PascalTable}}.SELECT(tbl{{.PascalTable}}.AllColumns).WHERE(cond)
|
||||
m.log().WithField("func", "GetByCond").Info(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().WithField("func","GetByCond").Errorf("error getting {{.PascalTable}} item by ID: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.log().WithField("func", "GetByCond").Infof("{{.PascalTable}} item retrieved successfully")
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetByID
|
||||
func (m *{{.PascalTable}}) GetByID(ctx context.Context, id int64, conds ...Cond) (*{{.PascalTable}}, error) {
|
||||
return m.GetByCond(ctx, CondJoin(m.CondID(id), conds...)...)
|
||||
}
|
||||
|
||||
|
||||
// Count
|
||||
func (m *{{.PascalTable}}) Count(ctx context.Context, conds ...Cond) (int64, error) {
|
||||
cond := CondTrue(conds...)
|
||||
|
||||
stmt := tbl{{.PascalTable}}.SELECT(COUNT(tbl{{.PascalTable}}.ID).AS("count")).WHERE(cond)
|
||||
m.log().Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var count struct {
|
||||
Count int64
|
||||
}
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, &count); err != nil {
|
||||
m.log().Errorf("error counting {{.PascalTable}} items: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count.Count, nil
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"{{ .PkgName }}/app/service/testx"
|
||||
"{{ .PkgName }}/database"
|
||||
"{{ .PkgName }}/database/table"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
// . "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
type {{ .PascalTable }}InjectParams struct {
|
||||
dig.In
|
||||
Initials []contracts.Initial `group:"initials"`
|
||||
}
|
||||
|
||||
type {{ .PascalTable }}TestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
{{ .PascalTable }}InjectParams
|
||||
}
|
||||
|
||||
func Test_{{ .PascalTable }}(t *testing.T) {
|
||||
providers := testx.Default().With(Provide)
|
||||
testx.Serve(providers, t, func(params {{ .PascalTable }}InjectParams) {
|
||||
suite.Run(t, &{{ .PascalTable }}TestSuite{
|
||||
{{ .PascalTable }}InjectParams: params,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *{{ .PascalTable }}TestSuite) Test_Demo() {
|
||||
Convey("Test_Demo", s.T(), func() {
|
||||
database.Truncate(context.Background(), db, tbl{{ .PascalTable }}.TableName())
|
||||
})
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package model
|
||||
|
||||
type Transformer struct {
|
||||
Ignores struct {
|
||||
Jet []string `mapstructure:"jet"`
|
||||
Model []string `mapstructure:"model"`
|
||||
} `mapstructure:"ignores"`
|
||||
Types map[string]map[string]string `mapstructure:"types"`
|
||||
}
|
||||
Reference in New Issue
Block a user