From 69c42124f4337db132e3813d332c00839cb1060c Mon Sep 17 00:00:00 2001 From: thinkgos Date: Tue, 28 May 2024 15:14:58 +0800 Subject: [PATCH] fix --- cmd/dyngen/command/template/dal_gorm.tpl | 8 ++++---- cmd/dyngen/command/template/dal_query.tpl | 8 ++++---- cmd/dyngen/command/template/dal_rapier.tpl | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/dyngen/command/template/dal_gorm.tpl b/cmd/dyngen/command/template/dal_gorm.tpl index 41c1045..f7e7519 100644 --- a/cmd/dyngen/command/template/dal_gorm.tpl +++ b/cmd/dyngen/command/template/dal_gorm.tpl @@ -135,7 +135,7 @@ func (b {{$stName}}) ExistByFilter(ctx context.Context, q *{{$queryPrefix}}Exist {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where("{{$f.ColumnName}} = ?", q.{{$f.GoName}}) + db = db.Where("{{$f.ColumnName}} = ?", {{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}}) } {{- end}} {{- end}} @@ -198,7 +198,7 @@ func (b {{$stName}}) PluckIdByFilter(ctx context.Context, q *{{$queryPrefix}}Plu {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where("{{$f.ColumnName}} = ?", q.{{$f.GoName}}) + db = db.Where("{{$f.ColumnName}} = ?", {{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}}) } {{- end}} {{- end}} @@ -221,7 +221,7 @@ func get{{$stName}}Filter(q *{{$queryPrefix}}Get{{$stName}}ByFilter) func(db *go {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where("{{$f.ColumnName}} = ?", q.{{$f.GoName}}) + db = db.Where("{{$f.ColumnName}} = ?", {{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}}) } {{- end}} {{- end}} @@ -242,7 +242,7 @@ func list{{$stName}}Filter(q *{{$queryPrefix}}List{{$stName}}ByFilter) func(db * {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where("{{$f.ColumnName}} = ?", q.{{$f.GoName}}) + db = db.Where("{{$f.ColumnName}} = ?", {{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}}) } {{- end}} {{- end}} diff --git a/cmd/dyngen/command/template/dal_query.tpl b/cmd/dyngen/command/template/dal_query.tpl index 3cfcd13..ab3bd18 100644 --- a/cmd/dyngen/command/template/dal_query.tpl +++ b/cmd/dyngen/command/template/dal_query.tpl @@ -14,7 +14,7 @@ type Update{{$stName}}ByPartial struct { type Get{{$stName}}ByFilter struct { {{- range $f := $e.Fields}} {{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}} - {{$f.GoName}} {{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` + {{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` {{- end}} {{- end}} } @@ -22,7 +22,7 @@ type Get{{$stName}}ByFilter struct { type Exist{{$stName}}ByFilter struct { {{- range $f := $e.Fields}} {{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}} - {{$f.GoName}} {{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` + {{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` {{- end}} {{- end}} } @@ -30,7 +30,7 @@ type Exist{{$stName}}ByFilter struct { type List{{$stName}}ByFilter struct { {{- range $f := $e.Fields}} {{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}} - {{$f.GoName}} {{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` + {{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` {{- end}} {{- end}} Page int64 `json:"page"` @@ -40,7 +40,7 @@ type List{{$stName}}ByFilter struct { type PluckId{{$stName}}ByFilter struct { {{- range $f := $e.Fields}} {{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}} - {{$f.GoName}} {{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` + {{$f.GoName}} {{if eq $f.Type.Type 1 }}*{{- end}}{{$f.Type.Ident}} `json:"{{smallcamelcase $f.ColumnName}}"` {{- end}} {{- end}} } \ No newline at end of file diff --git a/cmd/dyngen/command/template/dal_rapier.tpl b/cmd/dyngen/command/template/dal_rapier.tpl index 87ceb7d..e2887a7 100644 --- a/cmd/dyngen/command/template/dal_rapier.tpl +++ b/cmd/dyngen/command/template/dal_rapier.tpl @@ -119,11 +119,11 @@ func (b {{$stName}}) ExistByFilter(ctx context.Context, q *{{$queryPrefix}}Exist {{- else if eq $f.Type.Type 18 }} if !q.{{$f.GoName}}.IsZero() { {{- else if eq $f.Type.Type 1 }} - { + if q.{{$f.GoName}} != nil { {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where(ref.{{$f.GoName}}.Eq(q.{{$f.GoName}})) + db = db.Where(ref.{{$f.GoName}}.Eq({{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}})) } {{- end}} {{- end}} @@ -167,11 +167,11 @@ func (b {{$stName}}) PluckIdByFilter(ctx context.Context, q *{{$queryPrefix}}Plu {{- else if eq $f.Type.Type 18 }} if !q.{{$f.GoName}}.IsZero() { {{- else if eq $f.Type.Type 1 }} - { + if q.{{$f.GoName}} != nil { {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where(ref.{{$f.GoName}}.Eq(q.{{$f.GoName}})) + db = db.Where(ref.{{$f.GoName}}.Eq({{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}})) } {{- end}} {{- end}} @@ -189,11 +189,11 @@ func get{{$stName}}Filter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPre {{- else if eq $f.Type.Type 18 }} if !q.{{$f.GoName}}.IsZero() { {{- else if eq $f.Type.Type 1 }} - { + if q.{{$f.GoName}} != nil { {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where(ref.{{$f.GoName}}.Eq(q.{{$f.GoName}})) + db = db.Where(ref.{{$f.GoName}}.Eq({{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}})) } {{- end}} {{- end}} @@ -210,11 +210,11 @@ func list{{$stName}}Filter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPr {{- else if eq $f.Type.Type 18 }} if !q.{{$f.GoName}}.IsZero() { {{- else if eq $f.Type.Type 1 }} - { + if q.{{$f.GoName}} != nil { {{- else }} if q.{{$f.GoName}} != 0 { {{- end}} - db = db.Where(ref.{{$f.GoName}}.Eq(q.{{$f.GoName}})) + db = db.Where(ref.{{$f.GoName}}.Eq({{if eq $f.Type.Type 1 }}*{{- end}}q.{{$f.GoName}})) } {{- end}} {{- end}}