Skip to content

Commit 444b66e

Browse files
committed
Add deprecated option
1 parent ef09a6c commit 444b66e

File tree

6 files changed

+411
-19
lines changed

6 files changed

+411
-19
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Flags:
3838
-o, --output=OUTPUT output file path
3939
--no-interface output without Queryer interface
4040
--use-go-tool use 'go tool' for goimports
41+
--deprecated=DEPRECATED ...
42+
deprecated table names
4143
--version Show application version.
4244
4345
Args:

dgw.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"go/format"
1010
"os"
11+
"slices"
1112
"sort"
1213
"strings"
1314
"text/template"
@@ -160,10 +161,11 @@ type PgColumn struct {
160161

161162
// Struct go struct
162163
type Struct struct {
163-
Name string
164-
Table *PgTable
165-
Comment string
166-
Fields []*StructField
164+
Name string
165+
Table *PgTable
166+
Comment string
167+
Fields []*StructField
168+
Deprecated bool
167169
}
168170

169171
// StructTmpl go struct passed to template
@@ -285,11 +287,12 @@ func PgColToField(col *PgColumn, typeCfg *PgTypeMapConfig) (*StructField, error)
285287
}
286288

287289
// PgTableToStruct converts table def to go struct
288-
func PgTableToStruct(t *PgTable, typeCfg *PgTypeMapConfig, keyConfig *AutoKeyMap) (*Struct, error) {
290+
func PgTableToStruct(t *PgTable, typeCfg *PgTypeMapConfig, keyConfig *AutoKeyMap, deprecated []string) (*Struct, error) {
289291
t.setPrimaryKeyInfo(keyConfig)
290292
s := &Struct{
291-
Name: varfmt.PublicVarName(t.Name),
292-
Table: t,
293+
Name: varfmt.PublicVarName(t.Name),
294+
Table: t,
295+
Deprecated: slices.Contains(deprecated, t.Name),
293296
}
294297
var fs []*StructField
295298
for _, c := range t.Columns {
@@ -367,7 +370,7 @@ func PgExecuteCustomTmpl(st *StructTmpl, customTmpl string) ([]byte, error) {
367370

368371
// PgCreateStruct creates struct from given schema
369372
func PgCreateStruct(
370-
db Queryer, schema, typeMapPath, pkgName, customTmpl string, exTbls []string, autoGenKeyList []string) ([]byte, error) {
373+
db Queryer, schema, typeMapPath, pkgName, customTmpl string, exTbls []string, autoGenKeyList []string, deprecated []string) ([]byte, error) {
371374
src := []byte("// Code generated by dgw. DO NOT EDIT.\n\n")
372375
pkgDef := []byte(fmt.Sprintf("package %s\n\n", pkgName))
373376
src = append(src, pkgDef...)
@@ -396,7 +399,7 @@ func PgCreateStruct(
396399
if contains(tbl.Name, exTbls) {
397400
continue
398401
}
399-
st, err := PgTableToStruct(tbl, cfg, agkCfg)
402+
st, err := PgTableToStruct(tbl, cfg, agkCfg, deprecated)
400403
if err != nil {
401404
return src, errors.WithStack(err)
402405
}

0 commit comments

Comments
 (0)