-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgorm_cls_gen_test.go
78 lines (67 loc) · 1.85 KB
/
gorm_cls_gen_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package gormcngen_test
import (
"testing"
"time"
"github.com/yyle88/gormcngen"
"github.com/yyle88/gormcnm"
"github.com/yyle88/runpath"
"gorm.io/gorm"
)
type Example struct {
Name string `gorm:"primary_key;type:varchar(100);"`
Type string `gorm:"column:type;"`
Rank int `gorm:"column:rank;"`
}
type Demo struct {
gorm.Model
Name string `gorm:"type:varchar(100);" cnm:"V名称"`
Type string `gorm:"type:varchar(100);" cnm:"V类型"`
}
func TestConfigs_Generate(t *testing.T) {
path := runpath.Path()
t.Log(path)
options := gormcngen.NewOptions().
WithColumnClassExportable(true).
WithUseTagName(true)
cfg := gormcngen.NewConfigs([]interface{}{
&Example{},
&Demo{},
}, options, path)
cfg.Generate()
}
func (*Example) Columns() *ExampleColumns {
return &ExampleColumns{
Name: "name",
Type: "type",
Rank: "rank",
}
}
type ExampleColumns struct {
// Embedding operation functions make it easy to use // 继承操作函数便于使用
gormcnm.ColumnOperationClass
// The column names and types of the model's columns // 模型各列的列名和类型
Name gormcnm.ColumnName[string]
Type gormcnm.ColumnName[string]
Rank gormcnm.ColumnName[int]
}
func (*Demo) Columns() *DemoColumns {
return &DemoColumns{
ID: "id",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
V名称: "name",
V类型: "type",
}
}
type DemoColumns struct {
// Embedding operation functions make it easy to use // 继承操作函数便于使用
gormcnm.ColumnOperationClass
// The column names and types of the model's columns // 模型各列的列名和类型
ID gormcnm.ColumnName[uint]
CreatedAt gormcnm.ColumnName[time.Time]
UpdatedAt gormcnm.ColumnName[time.Time]
DeletedAt gormcnm.ColumnName[gorm.DeletedAt]
V名称 gormcnm.ColumnName[string]
V类型 gormcnm.ColumnName[string]
}