Skip to content

Commit 58211b6

Browse files
committed
refactor(python): move formatQueryForPython() function to cli.js
1 parent f408f12 commit 58211b6

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/cli.js

+14
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ const createEndpoints = async (destDir, { lang }, config) => {
273273
return `\n${indent}'${sql}'`
274274
},
275275

276+
// Differs from formatQuery() as it doesn't flatten query (preserve original formatting)
277+
// and also use """ for multiline strings
278+
// (used only with Python)
279+
"formatQueryForPython": (query, indentLevel) => {
280+
const sql = removePlaceholders(removeComments(query))
281+
const isMultilineSql = sql.indexOf('\n') >= 0
282+
if (isMultilineSql) {
283+
const indent = ' '.repeat(indentLevel)
284+
const indentedSql = sql.replace(/\n/g, '\n' + indent)
285+
return `\n${indent}"""\n${indent}${indentedSql}\n${indent}"""`
286+
}
287+
return `"${sql}"`
288+
},
289+
276290
// (used only with Golang)
277291
"convertPathPlaceholders": convertPathPlaceholders,
278292
"sqlParser": parser,

src/templates/routes.py.ejs

-13
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ function convertToFastApiPath(path) {
3131
return path.replace(/:([_a-zA-Z]+)/g, '{$1}')
3232
}
3333
34-
// Differs from formatQuery() as it doesn't flatten query (preserve original formatting)
35-
// and also use """ for multiline strings
36-
function formatQueryForPython(query, indentLevel) {
37-
const sql = removePlaceholders(removeComments(query))
38-
const isMultilineSql = sql.indexOf('\n') >= 0
39-
if (isMultilineSql) {
40-
const indent = ' '.repeat(indentLevel)
41-
const indentedSql = sql.replace(/\n/g, '\n' + indent)
42-
return `\n${indent}"""\n${indent}${indentedSql}\n${indent}"""`
43-
}
44-
return `"${sql}"`
45-
}
46-
4734
// LATER: reduce duplication with routes.go.ejs
4835
// {'values':
4936
// [

0 commit comments

Comments
 (0)