Skip to content

Commit

Permalink
更新 DAO 生成模板以使用 JSON 字段名,并重构 NewTable 函数以接受 TplObj 作为参数
Browse files Browse the repository at this point in the history
  • Loading branch information
hailaz committed Feb 20, 2025
1 parent 3a2a73c commit af20fbb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type {{.table.NameCaseCamel}}Columns struct { {{range $i,$v := .table.Fields}}

// {{.table.NameCaseCamelLower}}Columns holds the columns for table {{.table.Name}}.
var {{.table.NameCaseCamelLower}}Columns = {{.table.NameCaseCamel}}Columns{ {{range $i,$v := .table.Fields}}
{{$v.NameCaseCamel}}: "{{$v.NameCaseCamelLower}}",{{end}}
{{$v.NameCaseCamel}}: "{{$v.NameJsonCase}}",{{end}}
}

// New{{.table.NameCaseCamel}}Dao creates and returns a new DAO object for table data access.
Expand Down
10 changes: 5 additions & 5 deletions cmd/gf/internal/cmd/gen/tpl/tpl_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ type Tables []*Table
// createTime: 2023-12-11 16:17:33
//
// author: hailaz
func NewTable(ctx context.Context, db gdb.DB, tableName string, tableOutputName string) (*Table, error) {
fields, err := db.TableFields(ctx, tableName)
func NewTable(t *TplObj, tableName string) (*Table, error) {
fields, err := t.db.TableFields(t.ctx, tableName)
if err != nil {
return nil, err
}
table := Table{
Name: tableName,
OutputName: tableOutputName,
OutputName: t.TableOutputName(tableName),
FieldsSource: fields,
db: db,
db: t.db,
Imports: make(map[string]struct{}),
}
table.toTableFields()
Expand Down Expand Up @@ -159,7 +159,7 @@ func (t *TplObj) GetTables() (Tables, error) {

tables := make(Tables, 0, len(nameList))
for _, v := range nameList {
t, err := NewTable(t.ctx, t.db, v, t.TableOutputName(v))
t, err := NewTable(t, v)
if err != nil {
continue
}
Expand Down

0 comments on commit af20fbb

Please sign in to comment.