|
8 | 8 | "fmt" |
9 | 9 | "go/format" |
10 | 10 | "os" |
| 11 | + "slices" |
11 | 12 | "sort" |
12 | 13 | "strings" |
13 | 14 | "text/template" |
@@ -160,10 +161,11 @@ type PgColumn struct { |
160 | 161 |
|
161 | 162 | // Struct go struct |
162 | 163 | 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 |
167 | 169 | } |
168 | 170 |
|
169 | 171 | // StructTmpl go struct passed to template |
@@ -285,11 +287,12 @@ func PgColToField(col *PgColumn, typeCfg *PgTypeMapConfig) (*StructField, error) |
285 | 287 | } |
286 | 288 |
|
287 | 289 | // 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) { |
289 | 291 | t.setPrimaryKeyInfo(keyConfig) |
290 | 292 | 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), |
293 | 296 | } |
294 | 297 | var fs []*StructField |
295 | 298 | for _, c := range t.Columns { |
@@ -367,7 +370,7 @@ func PgExecuteCustomTmpl(st *StructTmpl, customTmpl string) ([]byte, error) { |
367 | 370 |
|
368 | 371 | // PgCreateStruct creates struct from given schema |
369 | 372 | 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) { |
371 | 374 | src := []byte("// Code generated by dgw. DO NOT EDIT.\n\n") |
372 | 375 | pkgDef := []byte(fmt.Sprintf("package %s\n\n", pkgName)) |
373 | 376 | src = append(src, pkgDef...) |
@@ -396,7 +399,7 @@ func PgCreateStruct( |
396 | 399 | if contains(tbl.Name, exTbls) { |
397 | 400 | continue |
398 | 401 | } |
399 | | - st, err := PgTableToStruct(tbl, cfg, agkCfg) |
| 402 | + st, err := PgTableToStruct(tbl, cfg, agkCfg, deprecated) |
400 | 403 | if err != nil { |
401 | 404 | return src, errors.WithStack(err) |
402 | 405 | } |
|
0 commit comments