-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyile
committed
Dec 11, 2024
1 parent
0cf19fa
commit 928e70f
Showing
8 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package example1 | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/yyle88/gormcnm" | ||
) | ||
|
||
func (T *Example) Columns() *ExampleColumns { | ||
return &ExampleColumns{ | ||
ID: gormcnm.Cnm(T.ID, "id"), | ||
V名称: gormcnm.Cnm(T.V名称, "v_0d54_f079"), | ||
V字段: gormcnm.Cnm(T.V字段, "v_575b_b56b"), | ||
V性别: gormcnm.Cnm(T.V性别, "v_2760_2b52"), | ||
V特殊: gormcnm.Cnm(T.V特殊, "v_7972_8a6b"), | ||
V年龄: gormcnm.Cnm(T.V年龄, "v_745e_849f"), | ||
Rank: gormcnm.Cnm(T.Rank, "rank"), | ||
V身高: gormcnm.Cnm(T.V身高, "v_ab8e_d89a"), | ||
V体重: gormcnm.Cnm(T.V体重, "v_534f_cd91"), | ||
CreatedAt: gormcnm.Cnm(T.CreatedAt, "created_at"), | ||
UpdatedAt: gormcnm.Cnm(T.UpdatedAt, "updated_at"), | ||
} | ||
} | ||
|
||
type ExampleColumns struct { | ||
// Embedding operation functions make it easy to use // 继承操作函数便于使用 | ||
gormcnm.ColumnOperationClass | ||
// The column names and types of the model's columns // 模型各列的列名和类型 | ||
ID gormcnm.ColumnName[int32] | ||
V名称 gormcnm.ColumnName[string] | ||
V字段 gormcnm.ColumnName[string] | ||
V性别 gormcnm.ColumnName[string] | ||
V特殊 gormcnm.ColumnName[string] | ||
V年龄 gormcnm.ColumnName[int] | ||
Rank gormcnm.ColumnName[int32] | ||
V身高 gormcnm.ColumnName[int32] | ||
V体重 gormcnm.ColumnName[int32] | ||
CreatedAt gormcnm.ColumnName[time.Time] | ||
UpdatedAt gormcnm.ColumnName[time.Time] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package example1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/gormcngen" | ||
"github.com/yyle88/osexistpath/osmustexist" | ||
"github.com/yyle88/runpath/runtestpath" | ||
) | ||
|
||
func TestGenerate(t *testing.T) { | ||
absPath := osmustexist.FILE(runtestpath.SrcPath(t)) | ||
t.Log(absPath) | ||
|
||
options := gormcngen.NewOptions(). | ||
WithColumnClassExportable(true). //中间类型名称的样式为非导出的 exampleColumns | ||
WithColumnsMethodRecvName("T"). | ||
WithColumnsCheckFieldType(true) | ||
|
||
cfg := gormcngen.NewConfigs([]interface{}{&Example{}}, options, absPath) | ||
cfg.Gen() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package example2 | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/yyle88/gormcnm" | ||
) | ||
|
||
func (T *Example) Columns() *exampleColumns { | ||
return &exampleColumns{ | ||
ID: gormcnm.Cnm(T.ID, "id"), | ||
V名称: gormcnm.Cnm(T.V名称, "V_0D54_F079"), | ||
V字段: gormcnm.Cnm(T.V字段, "v_575b_b56b"), | ||
V性别: gormcnm.Cnm(T.V性别, "v_2760_2b52"), | ||
V特殊: gormcnm.Cnm(T.V特殊, "V_7972_8A6B"), | ||
V年龄: gormcnm.Cnm(T.V年龄, "v_745e_849f"), | ||
Rank: gormcnm.Cnm(T.Rank, "rank"), | ||
V身高: gormcnm.Cnm(T.V身高, "V_AB8E_D89A"), | ||
V体重: gormcnm.Cnm(T.V体重, "v_534f_cd91"), | ||
CreatedAt: gormcnm.Cnm(T.CreatedAt, "created_at"), | ||
UpdatedAt: gormcnm.Cnm(T.UpdatedAt, "updated_at"), | ||
} | ||
} | ||
|
||
type exampleColumns struct { | ||
// Embedding operation functions make it easy to use // 继承操作函数便于使用 | ||
gormcnm.ColumnOperationClass | ||
// The column names and types of the model's columns // 模型各列的列名和类型 | ||
ID gormcnm.ColumnName[int32] | ||
V名称 gormcnm.ColumnName[string] | ||
V字段 gormcnm.ColumnName[string] | ||
V性别 gormcnm.ColumnName[string] | ||
V特殊 gormcnm.ColumnName[string] | ||
V年龄 gormcnm.ColumnName[int] | ||
Rank gormcnm.ColumnName[int32] | ||
V身高 gormcnm.ColumnName[int32] | ||
V体重 gormcnm.ColumnName[int32] | ||
CreatedAt gormcnm.ColumnName[time.Time] | ||
UpdatedAt gormcnm.ColumnName[time.Time] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package example2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/gormcngen" | ||
"github.com/yyle88/osexistpath/osmustexist" | ||
"github.com/yyle88/runpath/runtestpath" | ||
) | ||
|
||
func TestGenerate(t *testing.T) { | ||
absPath := osmustexist.FILE(runtestpath.SrcPath(t)) | ||
t.Log(absPath) | ||
|
||
options := gormcngen.NewOptions(). | ||
WithColumnClassExportable(false). //中间类型名称的样式为非导出的 exampleColumns | ||
WithColumnsMethodRecvName("T"). | ||
WithColumnsCheckFieldType(true) | ||
|
||
cfg := gormcngen.NewConfigs([]interface{}{&Example{}}, options, absPath) | ||
cfg.Gen() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package example3 | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/yyle88/gormcnm" | ||
) | ||
|
||
func (T *Example1) Columns() *Example1Columns { | ||
return &Example1Columns{ | ||
ID: gormcnm.Cnm(T.ID, "id"), | ||
V名称: gormcnm.Cnm(T.V名称, "v_0d54_f079"), | ||
V字段: gormcnm.Cnm(T.V字段, "v_575b_b56b"), | ||
V性别: gormcnm.Cnm(T.V性别, "v_2760_2b52"), | ||
V特殊: gormcnm.Cnm(T.V特殊, "v_7972_8a6b"), | ||
V年龄: gormcnm.Cnm(T.V年龄, "v_745e_849f"), | ||
Rank: gormcnm.Cnm(T.Rank, "rank"), | ||
V身高: gormcnm.Cnm(T.V身高, "v_ab8e_d89a"), | ||
V体重: gormcnm.Cnm(T.V体重, "v_534f_cd91"), | ||
CreatedAt: gormcnm.Cnm(T.CreatedAt, "created_at"), | ||
UpdatedAt: gormcnm.Cnm(T.UpdatedAt, "updated_at"), | ||
} | ||
} | ||
|
||
type Example1Columns struct { | ||
// Embedding operation functions make it easy to use // 继承操作函数便于使用 | ||
gormcnm.ColumnOperationClass | ||
// The column names and types of the model's columns // 模型各列的列名和类型 | ||
ID gormcnm.ColumnName[int32] | ||
V名称 gormcnm.ColumnName[string] | ||
V字段 gormcnm.ColumnName[string] | ||
V性别 gormcnm.ColumnName[string] | ||
V特殊 gormcnm.ColumnName[string] | ||
V年龄 gormcnm.ColumnName[int] | ||
Rank gormcnm.ColumnName[int32] | ||
V身高 gormcnm.ColumnName[int32] | ||
V体重 gormcnm.ColumnName[int32] | ||
CreatedAt gormcnm.ColumnName[time.Time] | ||
UpdatedAt gormcnm.ColumnName[time.Time] | ||
} | ||
|
||
func (T *Example2) Columns() *Example2Columns { | ||
return &Example2Columns{ | ||
ID: gormcnm.Cnm(T.ID, "id"), | ||
V名称: gormcnm.Cnm(T.V名称, "V_0D54_F079"), | ||
V字段: gormcnm.Cnm(T.V字段, "v_575b_b56b"), | ||
V性别: gormcnm.Cnm(T.V性别, "v_2760_2b52"), | ||
V特殊: gormcnm.Cnm(T.V特殊, "V_7972_8A6B"), | ||
V年龄: gormcnm.Cnm(T.V年龄, "v_745e_849f"), | ||
Rank: gormcnm.Cnm(T.Rank, "rank"), | ||
V身高: gormcnm.Cnm(T.V身高, "V_AB8E_D89A"), | ||
V体重: gormcnm.Cnm(T.V体重, "v_534f_cd91"), | ||
CreatedAt: gormcnm.Cnm(T.CreatedAt, "created_at"), | ||
UpdatedAt: gormcnm.Cnm(T.UpdatedAt, "updated_at"), | ||
} | ||
} | ||
|
||
type Example2Columns struct { | ||
// Embedding operation functions make it easy to use // 继承操作函数便于使用 | ||
gormcnm.ColumnOperationClass | ||
// The column names and types of the model's columns // 模型各列的列名和类型 | ||
ID gormcnm.ColumnName[int32] | ||
V名称 gormcnm.ColumnName[string] | ||
V字段 gormcnm.ColumnName[string] | ||
V性别 gormcnm.ColumnName[string] | ||
V特殊 gormcnm.ColumnName[string] | ||
V年龄 gormcnm.ColumnName[int] | ||
Rank gormcnm.ColumnName[int32] | ||
V身高 gormcnm.ColumnName[int32] | ||
V体重 gormcnm.ColumnName[int32] | ||
CreatedAt gormcnm.ColumnName[time.Time] | ||
UpdatedAt gormcnm.ColumnName[time.Time] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package example3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/gormcngen" | ||
"github.com/yyle88/osexistpath/osmustexist" | ||
"github.com/yyle88/runpath/runtestpath" | ||
) | ||
|
||
func TestGenerate(t *testing.T) { | ||
absPath := osmustexist.FILE(runtestpath.SrcPath(t)) | ||
t.Log(absPath) | ||
|
||
options := gormcngen.NewOptions(). | ||
WithColumnClassExportable(true). //中间类型名称的样式为非导出的 exampleColumns | ||
WithColumnsMethodRecvName("T"). | ||
WithColumnsCheckFieldType(true) | ||
|
||
cfg := gormcngen.NewConfigs([]interface{}{&Example1{}, &Example2{}}, options, absPath) | ||
cfg.Gen() | ||
} |