Skip to content

Commit ecb3395

Browse files
committed
refactor: make possible to specify an object to bind to
1 parent 090d0d1 commit ecb3395

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const createEndpoints = async (destDir, fileName, config) => {
4848
},
4949

5050
// [ "page", "num" ] => '{ "page" : req.params.page, "num": req.params.num }'
51-
"formatParams": (params) => {
51+
"formatParams": (params, targetObject) => {
5252
return params.length > 0
53-
? '{ ' + Array.from(new Set(params), p => `"${p}": req.params.${p}`).join(', ') + ' }'
53+
? '{ ' + Array.from(new Set(params), p => `"${p}": ${targetObject}.${p}`).join(', ') + ' }'
5454
: params;
5555
},
5656

src/templates/app.js.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ endpoints.forEach(function(endpoint) {
3333
%>
3434
app.get('<%- endpoint.path %>', (req, res) => {
3535
pool.query(
36-
<%- formatQuery(endpoint.get) %>,<%- params.length > 0 ? '\n ' + formatParams(params) + ',' : '' %>
36+
<%- formatQuery(endpoint.get) %>,<%- params.length > 0 ? '\n ' + formatParams(params, 'req.params') + ',' : '' %>
3737
(err, rows, fields) => {
3838
if (err) {
3939
throw err

0 commit comments

Comments
 (0)