Skip to content

Commit

Permalink
Merge pull request #110 from alexj212/master
Browse files Browse the repository at this point in the history
Fixed naming in templates away from hard coded model package.
  • Loading branch information
alexj212 authored Jun 30, 2020
2 parents 1470bbb + ae90072 commit 677acfb
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ example/go.sum
custom/test/
example/*.proto
example/grpc
example/apis/
example/daos/
example/models/
tests/
.env
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ generate_example: clean_example ## generate example project code from sqlite db
--mapping=../template/mapping.json \
--json \
--db \
--api=apis \
--dao=daos \
--model=models \
--generate-dao \
--generate-proj \
--protobuf \
Expand Down Expand Up @@ -120,6 +123,7 @@ run_example: example ## run example project server


clean_example: ## remove generated example code
mkdir -p ./example
rm -rf ./example/Makefile \
./example/README.md \
./example/api \
Expand Down
10 changes: 6 additions & 4 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _test/dbmeta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
goopt.Description = func() string {
return "ORM and RESTful meta data viewer for SQl databases"
}
goopt.Version = "v0.9.17 (06/30/2020)"
goopt.Version = "v0.9.18 (06/30/2020)"
goopt.Summary = `dbmeta [-v] --sqltype=mysql --connstr "user:password@/dbname" --database <databaseName>
sqltype - sql database type such as [ mysql, mssql, postgres, sqlite, etc. ]
Expand Down
4 changes: 2 additions & 2 deletions code_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func GetInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// @Failure 400 {object} api.HTTPError
// @Failure 404 {object} api.HTTPError
// @Router /invoices [post]
// echo '{"billing_postal_code": "AOPIXOYmaQfoGUAAqpPwofbyG","billing_state": "FUKpRZMGWUtJXhtuIOArbtcfy","customer_id": 31,"invoice_date": "2262-12-14T19:22:36.159735656-05:00","billing_address": "gzChfHzuxRyunGDlUmjumNlGa","billing_city": "VASvBrPiKEMOURqwxxgWLwnIq","billing_country": "BjwznZcJbSXovdjoliHaDztId","total": 0.2454785678341827,"invoice_id": 86}' | http POST "http://127.0.0.1:8080/invoices" X-Api-User:user123
// echo '{"invoice_date": "2193-08-18T16:11:59.078188308-05:00","billing_address": "AqlNHbqeNoJOtnMJaPnzdILQa","billing_state": "tWuCMqsmCwdXbCINBdvKJRFLU","billing_postal_code": "SXZkYaGzotXoZOyOsikBMAFTZ","total": 0.5347164921866526,"invoice_id": 46,"customer_id": 8,"billing_city": "JdgoMLJqAcUmRgbXfqkCZaezO","billing_country": "bAWiKIZfJLnzNgUysoWJrhEkE"}' | http POST "http://127.0.0.1:8080/invoices" X-Api-User:user123
func AddInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
ctx := initializeContext(r)
invoices := &model.Invoices{}
Expand Down Expand Up @@ -192,7 +192,7 @@ func AddInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// @Failure 400 {object} api.HTTPError
// @Failure 404 {object} api.HTTPError
// @Router /invoices/{argInvoiceID} [patch]
// echo '{"billing_postal_code": "AOPIXOYmaQfoGUAAqpPwofbyG","billing_state": "FUKpRZMGWUtJXhtuIOArbtcfy","customer_id": 31,"invoice_date": "2262-12-14T19:22:36.159735656-05:00","billing_address": "gzChfHzuxRyunGDlUmjumNlGa","billing_city": "VASvBrPiKEMOURqwxxgWLwnIq","billing_country": "BjwznZcJbSXovdjoliHaDztId","total": 0.2454785678341827,"invoice_id": 86}' | http PUT "http://127.0.0.1:8080/invoices/1" X-Api-User:user123
// echo '{"invoice_date": "2193-08-18T16:11:59.078188308-05:00","billing_address": "AqlNHbqeNoJOtnMJaPnzdILQa","billing_state": "tWuCMqsmCwdXbCINBdvKJRFLU","billing_postal_code": "SXZkYaGzotXoZOyOsikBMAFTZ","total": 0.5347164921866526,"invoice_id": 46,"customer_id": 8,"billing_city": "JdgoMLJqAcUmRgbXfqkCZaezO","billing_country": "bAWiKIZfJLnzNgUysoWJrhEkE"}' | http PUT "http://127.0.0.1:8080/invoices/1" X-Api-User:user123
func UpdateInvoices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
ctx := initializeContext(r)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func init() {
goopt.Description = func() string {
return "ORM and RESTful API generator for SQl databases"
}
goopt.Version = "v0.9.17 (06/30/2020)"
goopt.Version = "v0.9.18 (06/30/2020)"
goopt.Summary = `gen [-v] --sqltype=mysql --connstr "user:password@/dbname" --database <databaseName> --module=example.com/example [--json] [--gorm] [--guregu] [--generate-dao] [--generate-proj]
git fetch up
sqltype - sql database type such as [ mysql, mssql, postgres, sqlite, etc. ]
Expand Down
8 changes: 4 additions & 4 deletions packrd/packed-packr.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion readme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
goopt.Description = func() string {
return "ORM and RESTful meta data viewer for SQl databases"
}
goopt.Version = "v0.9.17 (06/30/2020)"
goopt.Version = "v0.9.18 (06/30/2020)"
goopt.Summary = `dbmeta [-v] --sqltype=mysql --connstr "user:password@/dbname" --database <databaseName>
sqltype - sql database type such as [ mysql, mssql, postgres, sqlite, etc. ]
Expand Down
2 changes: 2 additions & 0 deletions template/GEN_README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ Table Name: registration_source
|ms sql |y | y | y | y | y | y| n

## Version History
- v0.9.18 (06/30/2020)
- Fixed naming in templates away from hard coded model package.
- v0.9.17 (06/30/2020)
- Refactored template loading, to better report error in template
- Added option to run gofmt on output directory
Expand Down
6 changes: 3 additions & 3 deletions template/protoserver.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Server) Get{{ $tableInfo.StructName }}(context context.Context, request

response := &{{$.modelPackageName}}.Get{{ $tableInfo.StructName }}Response{}
response.Data = result
response.Result=&models.Result{Result: models.Result_Success}
response.Result=&{{$.modelPackageName}}.Result{Result: {{$.modelPackageName}}.Result_Success}
return response, nil
}

Expand All @@ -62,7 +62,7 @@ func (s *Server) Add{{ $tableInfo.StructName }}(context context.Context, request

response := &{{$.modelPackageName}}.Add{{ $tableInfo.StructName }}Response{}
response.Data = result
response.Result = &models.Result{Result: models.Result_Success}
response.Result = &{{$.modelPackageName}}.Result{Result: {{$.modelPackageName}}.Result_Success}
response.RowsAffected = rowsAffected
return response, nil
}
Expand All @@ -80,7 +80,7 @@ func (s *Server) Update{{ $tableInfo.StructName }}(context context.Context, requ

response := &{{$.modelPackageName}}.Update{{ $tableInfo.StructName }}Response{}
response.Data = result
response.Result = &models.Result{Result: models.Result_Success}
response.Result = &{{$.modelPackageName}}.Result{Result: {{$.modelPackageName}}.Result_Success}
response.RowsAffected = rowsAffected
return response, nil
}
Expand Down
9 changes: 5 additions & 4 deletions template/router.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CrudAPI struct {
UpdateURL string `json:"update_url"`
DeleteURL string `json:"delete_url"`
FetchDDLURL string `json:"fetch_ddl_url"`
TableInfo *{{$.modelPackageName}}.TableInfo `json:"table_info"`
TableInfo *{{.modelPackageName}}.TableInfo `json:"table_info"`
}


Expand Down Expand Up @@ -294,7 +294,7 @@ func GetDdl(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

argID := ps.ByName("argID")

if err := ValidateRequest(ctx, r, "ddl", {{$.modelPackageName}}.FetchDDL); err != nil {
if err := ValidateRequest(ctx, r, "ddl", {{.modelPackageName}}.FetchDDL); err != nil {
returnError(ctx, w, r, err)
return
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func GetDdl(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
func GetDdlEndpoints(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
ctx := initializeContext(r)

if err := ValidateRequest(ctx, r, "ddl", {{$.modelPackageName}}.FetchDDL); err != nil {
if err := ValidateRequest(ctx, r, "ddl", {{.modelPackageName}}.FetchDDL); err != nil {
returnError(ctx, w, r, err)
return
}
Expand All @@ -344,7 +344,8 @@ func init() {
DeleteURL: "/{{$tableInfo.StructName | toLower}}",
FetchDDLURL: "/ddl/{{$tableName}}",
}
tmp.TableInfo, _ = {{$.modelPackageName}}.GetTableInfo("{{$tableName}}")

tmp.TableInfo, _ = {{.modelPackageName}}.GetTableInfo("{{$tableName}}")
crudEndpoints["{{$tableName}}"] = tmp

{{end}}
Expand Down

0 comments on commit 677acfb

Please sign in to comment.