From 6625530f7dc79cb340d13a0a1280c13cea76efd1 Mon Sep 17 00:00:00 2001 From: Alexander Trost Date: Thu, 26 Dec 2024 15:03:42 +0100 Subject: [PATCH] feat: add generator skip option for table columns Signed-off-by: Alexander Trost --- generator/template/file_templates.go | 8 ++++++++ generator/template/sql_builder_template.go | 1 + 2 files changed, 9 insertions(+) diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go index 1538031d..8d9e848e 100644 --- a/generator/template/file_templates.go +++ b/generator/template/file_templates.go @@ -14,9 +14,11 @@ var tableSQLBuilderTemplate = ` {{define "column-list" -}} {{- range $i, $c := . }} {{- $field := columnField $c}} + {{- if not $field.Skip}} {{- if gt $i 0 }}, {{end}}{{$field.Name}}Column {{- end}} {{- end}} +{{- end}} package {{package}} @@ -33,7 +35,9 @@ type {{structImplName}} struct { // Columns {{- range $i, $c := .Columns}} {{- $field := columnField $c}} +{{- if not $field.Skip}} {{$field.Name}} {{dialect.PackageName}}.Column{{$field.Type}} {{golangComment .Comment}} +{{- end}} {{- end}} AllColumns {{dialect.PackageName}}.ColumnList @@ -77,7 +81,9 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st var ( {{- range $i, $c := .Columns}} {{- $field := columnField $c}} +{{- if not $field.Skip }} {{$field.Name}}Column = {{dialect.PackageName}}.{{$field.Type}}Column("{{$c.Name}}") +{{- end}} {{- end}} allColumns = {{dialect.PackageName}}.ColumnList{ {{template "column-list" .Columns}} } mutableColumns = {{dialect.PackageName}}.ColumnList{ {{template "column-list" .MutableColumns}} } @@ -89,7 +95,9 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st //Columns {{- range $i, $c := .Columns}} {{- $field := columnField $c}} +{{- if not $field.Skip }} {{$field.Name}}: {{$field.Name}}Column, +{{- end}} {{- end}} AllColumns: allColumns, diff --git a/generator/template/sql_builder_template.go b/generator/template/sql_builder_template.go index 3b158b85..a72e8e99 100644 --- a/generator/template/sql_builder_template.go +++ b/generator/template/sql_builder_template.go @@ -131,6 +131,7 @@ func (tb TableSQLBuilder) UseColumn(columnsFunc func(column metadata.Column) Tab // TableSQLBuilderColumn is template for table sql builder column type TableSQLBuilderColumn struct { + Skip bool Name string Type string }