@@ -207,6 +207,15 @@ endpoints.forEach(function(endpoint) {
207
207
// LATER: add support for aggregated_queries (#17)
208
208
const argsFromQuery = method .query ? extractParamsFromQuery (method .query ).map (stipOurPrefixes) : []
209
209
210
+ // define before "if", to make them available later
211
+ let sql
212
+ let formattedParams
213
+ if (method .name === ' post' || method .name === ' put' || method .name === ' delete' ) {
214
+ sql = convertToPsycopgNamedArguments (formatQueryForPython (method .query , 20 ))
215
+ const params = extractParamsFromQuery (method .query )
216
+ formattedParams = formatParamsAsPythonDict (params)
217
+ }
218
+
210
219
if (hasGetOne || hasGetMany) {
211
220
const methodArgs = Array .from (new Set ([... argsFromPath, ... argsFromQuery, ' conn=Depends(db_connection)' ]))
212
221
@@ -276,11 +285,6 @@ def <%- pythonMethodName %>(<%- methodArgs.join(', ') %>):
276
285
const dto = query2dto (sqlParser, method)
277
286
// LATER: do we really need signature and cache?
278
287
const model = obtainDtoName (dto)
279
-
280
- const sql = convertToPsycopgNamedArguments (formatQueryForPython (method .query , 20 ))
281
- const params = extractParamsFromQuery (method .query )
282
- const formattedParams = formatParamsAsPythonDict (params)
283
-
284
288
% >
285
289
286
290
@router .post (' <%- path %>' , status_code= status .HTTP_204_NO_CONTENT )
@@ -302,10 +306,6 @@ def <%- pythonMethodName %>(body: <%- model %>, conn=Depends(db_connection)):
302
306
const model = obtainDtoName (dto)
303
307
304
308
const methodArgs = [ ` body: ${ model} ` , ... argsFromPath, ' conn=Depends(db_connection)' ]
305
-
306
- const sql = convertToPsycopgNamedArguments (formatQueryForPython (method .query , 20 ))
307
- const params = extractParamsFromQuery (method .query )
308
- const formattedParams = formatParamsAsPythonDict (params)
309
309
% >
310
310
311
311
@router .put (' <%- path %>' , status_code= status .HTTP_204_NO_CONTENT )
@@ -321,10 +321,6 @@ def <%- pythonMethodName %>(<%- methodArgs.join(', ') %>):
321
321
}
322
322
if (method .name === ' delete' ) {
323
323
const methodArgs = [ ... argsFromPath, ' conn=Depends(db_connection)' ]
324
-
325
- const sql = convertToPsycopgNamedArguments (formatQueryForPython (method .query , 20 ))
326
- const params = extractParamsFromQuery (method .query )
327
- const formattedParams = formatParamsAsPythonDict (params)
328
324
% >
329
325
330
326
@router .delete (' <%- path %>' , status_code= status .HTTP_204_NO_CONTENT )
0 commit comments