diff --git a/go.mod b/go.mod index aaafaf4..5a5d83d 100644 --- a/go.mod +++ b/go.mod @@ -7,11 +7,13 @@ require ( github.com/yyle88/done v1.0.18 github.com/yyle88/erero v1.0.14 github.com/yyle88/formatgo v1.0.19 - github.com/yyle88/gormcngen v1.0.34 + github.com/yyle88/gormcngen v1.0.35 + github.com/yyle88/gormcnm v1.0.45 github.com/yyle88/must v0.0.9 + github.com/yyle88/osexistpath v0.0.13 github.com/yyle88/rese v0.0.1 github.com/yyle88/runpath v1.0.22 - github.com/yyle88/syntaxgo v0.0.40 + github.com/yyle88/syntaxgo v0.0.41 github.com/yyle88/zaplog v0.0.16 go.uber.org/zap v1.27.0 gorm.io/driver/sqlite v1.5.7 @@ -25,7 +27,6 @@ require ( github.com/mattn/go-sqlite3 v1.14.24 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/yyle88/gormcnm v1.0.45 // indirect github.com/yyle88/mutexmap v1.0.8 // indirect github.com/yyle88/neatjson v0.0.10 // indirect github.com/yyle88/printgo v1.0.1 // indirect @@ -33,7 +34,7 @@ require ( github.com/yyle88/sure v0.0.33 // indirect github.com/yyle88/tern v0.0.3 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d // indirect + golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect golang.org/x/mod v0.22.0 // indirect golang.org/x/sync v0.10.0 // indirect golang.org/x/text v0.21.0 // indirect diff --git a/go.sum b/go.sum index e2239a9..5ac2742 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/yyle88/erero v1.0.14 h1:ozS3iPLIsnRPSs8AdfbA/3f3hGw5EFkJMkfA/dfI+do= github.com/yyle88/erero v1.0.14/go.mod h1:NhP5EcPoVlShkMk1cVCFP3im5Zm+JRG35qIInMw7aeo= github.com/yyle88/formatgo v1.0.19 h1:XgcSB8KsGLTnv7UOCVZDtrd3yJggFd2J82xG5qvmdFI= github.com/yyle88/formatgo v1.0.19/go.mod h1:Q+JpNGVgskW2Xl+BdHXZ7r6y6TQlQOyN7/23Gu/wzoM= -github.com/yyle88/gormcngen v1.0.34 h1:NGT2wAU66KsgUYR3EgsAMnvyhgW8Lozag4nMmItvwmQ= -github.com/yyle88/gormcngen v1.0.34/go.mod h1:+oXElXtJORoxxmKXwoASb1Ypyq/kUYukIFs+Z6yWLdY= +github.com/yyle88/gormcngen v1.0.35 h1:k+JemmWGnSUFAqG/N2/6iOF7RcotR77hPIHUSE+6VDo= +github.com/yyle88/gormcngen v1.0.35/go.mod h1:5upLI3RvylY2nuAV8N1vbbWGYOlrEmSqwLmpnDA93EA= github.com/yyle88/gormcnm v1.0.45 h1:iiq3il2AawmdQIK0up6+MhM25i+PPt+GsZmEradtD8g= github.com/yyle88/gormcnm v1.0.45/go.mod h1:zi0k7uNcsYIjv10pQdq4OsoYbzoJ6Rk2yepza5D9SWE= github.com/yyle88/must v0.0.9 h1:LA03i1O4/6Syopma8xqJMiWfAWeehoySeUaRmdQEvKY= @@ -36,6 +36,8 @@ github.com/yyle88/mutexmap v1.0.8 h1:VntAdXID5wbk211LZEPVK96jQBxIcfVIbQuk9cv3P/8 github.com/yyle88/mutexmap v1.0.8/go.mod h1:QUYDuARLPlGj414kHewQ5tt8jkDxQXoai8H3C4Gg+yc= github.com/yyle88/neatjson v0.0.10 h1:JrBsSWnEu6vqObFT8bUJE83HDb7xYScuEiz/RZp15pM= github.com/yyle88/neatjson v0.0.10/go.mod h1:4ENPBNVvTIB6iLv3mM02Jv/OEXANZNYDGXynSSt4kcc= +github.com/yyle88/osexistpath v0.0.13 h1:DGuLaKT5NSh2q/nIbG82gwKihzXWmsj80VcBmollJw8= +github.com/yyle88/osexistpath v0.0.13/go.mod h1:QgSZb/uRbF8//M7UPbg689zyQaXKWVmgopfTAWgKbLU= github.com/yyle88/printgo v1.0.1 h1:0lCpq28Tlf0jmYhSIlDQ7A3hAqVYswhBuURLR9xbmsw= github.com/yyle88/printgo v1.0.1/go.mod h1:yCvpShGBkKdWX5RO+yum2gLbru9ebc04sVmuzhPKSMw= github.com/yyle88/rese v0.0.1 h1:Eu2I+7BpbkX1n7SOu11AHVqecTuOVdg4becgt2ThGIo= @@ -46,8 +48,8 @@ github.com/yyle88/sortslice v1.0.6 h1:c9XoKbVzhjr0gbcOMwuE4xeBvREhreGN/62ZIGA5KA github.com/yyle88/sortslice v1.0.6/go.mod h1:/mlmWz1/w0CCeLSs/FaByXM5SKsVlZ7IJ+3O/PMS5Ws= github.com/yyle88/sure v0.0.33 h1:draMRRyZ3IWnXFyfKIWwH3ljWvA5Pq/X+z/fHyCbyFE= github.com/yyle88/sure v0.0.33/go.mod h1:ep6XBfw1D5bBNsihnaWlenO8Qc8lF+vfqwDqvnZBM9Y= -github.com/yyle88/syntaxgo v0.0.40 h1:b+Z7USsOPDS2B75oFZCupleLNn29FSuvgjcsWBAO5QE= -github.com/yyle88/syntaxgo v0.0.40/go.mod h1:vR/bU2RVwvkfkQyMy30OWpdmn5jc3wrm8vcMbHQGCbc= +github.com/yyle88/syntaxgo v0.0.41 h1:QkVlovdaekBWTKCEVvwmkLSHVT4Ak4N5PhESaChsiYs= +github.com/yyle88/syntaxgo v0.0.41/go.mod h1:/dFZNM1OsgpvQf8wPgp8ShqLixOZfdc/1dldCNdQrVE= github.com/yyle88/tern v0.0.3 h1:Ut5p1wPAVcreEkmzDp+IiteA3K2vnTeAYE1PyBLNgjU= github.com/yyle88/tern v0.0.3/go.mod h1:g9weyOMLtXYyt37EAshZPUTTHdH7WFauuxDi4oPr7/8= github.com/yyle88/zaplog v0.0.16 h1:ZCxQhq3+nWeWMAXIzeA1EA4exRq5Pn8pXTpEw1GjyD4= @@ -58,8 +60,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d h1:0olWaB5pg3+oychR51GUVCEsGkeCU/2JxjBgIo4f3M0= -golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= +golang.org/x/exp v0.0.0-20241210194714-1829a127f884 h1:Y/Mj/94zIQQGHVSv1tTtQBDaQaJe62U9bkDZKKyhPCU= +golang.org/x/exp v0.0.0-20241210194714-1829a127f884/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= diff --git a/internal/examples/example1/gormcnm.go b/internal/examples/example1/gormcnm.go new file mode 100644 index 0000000..b606347 --- /dev/null +++ b/internal/examples/example1/gormcnm.go @@ -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] +} diff --git a/internal/examples/example1/gormcnm_test.go b/internal/examples/example1/gormcnm_test.go new file mode 100644 index 0000000..89a281f --- /dev/null +++ b/internal/examples/example1/gormcnm_test.go @@ -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() +} diff --git a/internal/examples/example2/gormcnm.go b/internal/examples/example2/gormcnm.go new file mode 100644 index 0000000..48b1ba2 --- /dev/null +++ b/internal/examples/example2/gormcnm.go @@ -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] +} diff --git a/internal/examples/example2/gormcnm_test.go b/internal/examples/example2/gormcnm_test.go new file mode 100644 index 0000000..960a048 --- /dev/null +++ b/internal/examples/example2/gormcnm_test.go @@ -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() +} diff --git a/internal/examples/example3/gormcnm.go b/internal/examples/example3/gormcnm.go new file mode 100644 index 0000000..015c04f --- /dev/null +++ b/internal/examples/example3/gormcnm.go @@ -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] +} diff --git a/internal/examples/example3/gormcnm_test.go b/internal/examples/example3/gormcnm_test.go new file mode 100644 index 0000000..b14d6dd --- /dev/null +++ b/internal/examples/example3/gormcnm_test.go @@ -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() +}