Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Dec 9, 2024
1 parent 2f90f9a commit e5546ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/goctl/model/sql/gen/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func genNew(table Table, withCache, postgreSql bool) (string, error) {

t := fmt.Sprintf(`"%s"`, wrapWithRawString(table.Name.Source(), postgreSql))
primaryKey := fmt.Sprintf(`"%s"`, table.PrimaryKey.Field.Name.Source())
keyType := fmt.Sprintf(`"%s"`, table.PrimaryKey.DataType)
if postgreSql {
t = "`" + fmt.Sprintf(`"%s"."%s"`, table.Db.Source(), table.Name.Source()) + "`"
}
Expand All @@ -25,6 +26,8 @@ func genNew(table Table, withCache, postgreSql bool) (string, error) {
Execute(map[string]any{
"table": t,
"primaryKey": primaryKey,
"incrementing": table.PrimaryKey.AutoIncrement,
"keyType": keyType,
"withCache": withCache,
"upperStartCamelObject": table.Name.ToCamel(),
"data": table,
Expand Down
2 changes: 2 additions & 0 deletions tools/goctl/model/sql/template/tpl/model-new.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c ca
{{if .withCache}}CachedConn: sqlc.NewConn(conn, c, opts...){{else}}conn:conn{{end}},
table: {{.table}},
primaryKey: {{.primaryKey}},
incrementing: {{.incrementing}},
keyType: {{.keyType}},
}
}

2 changes: 2 additions & 0 deletions tools/goctl/model/sql/template/tpl/types.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type (
{{if .withCache}}sqlc.CachedConn{{else}}conn sqlx.SqlConn{{end}}
table string
primaryKey string
incrementing bool
keyType string
}

{{.upperStartCamelObject}} struct {
Expand Down

0 comments on commit e5546ed

Please sign in to comment.