Skip to content

Commit

Permalink
fix: fix template
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Sep 15, 2024
1 parent d00c12f commit 47c92db
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/dyngen/command/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newApiCmd() *apiCmd {
cmd.Flags().StringVarP(&root.OutputDir, "out", "o", "./proto", "out directory")
cmd.Flags().StringVar(&root.PackageName, "package", "", "proto package name")
cmd.Flags().StringToStringVar(&root.Options, "options", nil, "proto options")
cmd.Flags().StringVar(&root.Style, "style", "smallCamelCase", "字段代码风格, snakeCase, smallCamelCase, pascalCase")
cmd.Flags().StringVar(&root.Style, "style", "snakeCase", "字段代码风格, snakeCase, smallCamelCase, pascalCase")

cmd.Flags().BoolVar(&root.DisableBool, "disableBool", false, "禁用bool,使用int32")
cmd.Flags().BoolVar(&root.DisableTimestamp, "disableTimestamp", false, "禁用google.protobuf.Timestamp,使用int64")
Expand Down
2 changes: 1 addition & 1 deletion cmd/dyngen/command/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (g *CodeGen) Gen() *CodeGen {
g.Printf("message List%sReply {\n", structName)
g.Println(" int64 total = 1 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { type: [ INTEGER ] }];")
g.Println(" int64 page = 30 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { type: [ INTEGER ] }];")
g.Println(" int64 perPage = 31 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { type: [ INTEGER ] }];")
g.Println(" int64 per_page = 31 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { type: [ INTEGER ] }];")
g.Printf(" repeated mapper.%s list = 32;\n", structName)
g.Println("}")
//* get
Expand Down
4 changes: 4 additions & 0 deletions cmd/dyngen/command/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type dalOpt struct {
DalImportPath string // M, dal导入路径, 给query用
CustomTemplate string // O, 自定义模板
Override bool // O, 是否覆盖
Style string // O, style kind.
ens.Option
}

Expand Down Expand Up @@ -75,6 +76,7 @@ func newDalCmd() *dalCmd {
ModelPrefix: utils.PkgName(root.ModelImportPath) + ".",
QueryPrefix: "query.",
RepoPrefix: utils.PkgName(root.RepoImportPath) + ".",
Style: root.Style,
Entity: nil,
}

Expand All @@ -84,6 +86,7 @@ func newDalCmd() *dalCmd {
ModelPrefix: utils.PkgName(root.ModelImportPath) + ".",
QueryPrefix: "",
RepoPrefix: "",
Style: root.Style,
Entity: nil,
}

Expand Down Expand Up @@ -137,6 +140,7 @@ func newDalCmd() *dalCmd {
cmd.Flags().StringVar(&root.PackageName, "package", "", "package name")
cmd.Flags().StringVar(&root.CustomTemplate, "template", "builtin-rapier", "use custom template except [builtin-rapier, builtin-gorm]")
cmd.Flags().BoolVar(&root.Override, "override", false, "是否覆盖")
cmd.Flags().StringVar(&root.Style, "style", "snakeCase", "字段代码风格, snakeCase, smallCamelCase, pascalCase")

cmd.Flags().StringVar(&root.ModelImportPath, "modelImportPath", "", "model导入路径")
cmd.Flags().StringVar(&root.DalImportPath, "dalImportPath", "", "dal导入路径")
Expand Down
1 change: 1 addition & 0 deletions cmd/dyngen/command/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Dal struct {
ModelPrefix string
QueryPrefix string
RepoPrefix string
Style string
Entity *ens.EntityDescriptor
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/dyngen/command/template/dal_query.tpl
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
package {{.Package}}

{{- $style := .Style}}
{{- $e := .Entity}}
{{- $stName := pascalcase $e.Name}}

type Update{{$stName}}ByPartial struct {
{{- range $f := $e.Fields}}
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if ne $f.GoName "Id"}}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"`
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if ne $f.GoName "Id"}}*{{- end}}{{$f.Type.Ident}} `json:"{{stylename $style $f.ColumnName}}"`
{{- end}}
}

type Get{{$stName}}ByFilter struct {
{{- range $f := $e.Fields}}
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"`
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{stylename $style $f.ColumnName}}"`
{{- end}}
}

type Exist{{$stName}}ByFilter struct {
{{- range $f := $e.Fields}}
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"`
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{stylename $style $f.ColumnName}}"`
{{- end}}
}

type List{{$stName}}ByFilter struct {
{{- range $f := $e.Fields}}
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"`
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{stylename $style $f.ColumnName}}"`
{{- end}}
Page int64 `json:"page"`
PerPage int64 `json:"perPage"`
}

type PluckId{{$stName}}ByFilter struct {
{{- range $f := $e.Fields}}
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"`
{{if or (eq $f.GoName "CreatedAt") (eq $f.GoName "UpdatedAt") (eq $f.GoName "DeletedAt")}}// {{end}}{{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{stylename $style $f.ColumnName}}"`
{{- end}}
}

0 comments on commit 47c92db

Please sign in to comment.