Skip to content

Commit 60d3522

Browse files
committed
refactor(python): format dict on multiple lines
1 parent 2074fbe commit 60d3522

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

examples/python/fastapi/postgres/routes.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def get_v1_collections_collection_id_categories_count(collectionId, conn=Depends
6363
JOIN series s
6464
ON s.id = cs.series_id
6565
WHERE cs.collection_id = %(collectionId)s
66-
""", {"collectionId": collectionId})
66+
""", {
67+
"collectionId": collectionId
68+
})
6769
result = cur.fetchone()
6870
if result is None:
6971
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
@@ -116,7 +118,12 @@ def post_v1_categories(body: CreateCategoryDto, conn=Depends(db_connection)):
116118
, NOW()
117119
, %(user_id)s
118120
)
119-
""", {"name": body.name, "name_ru": body.name_ru, "slug": body.slug, "user_id": body.user_id})
121+
""", {
122+
"name": body.name,
123+
"name_ru": body.name_ru,
124+
"slug": body.slug,
125+
"user_id": body.user_id
126+
})
120127
finally:
121128
conn.close()
122129

@@ -134,7 +141,9 @@ def get_v1_categories_category_id(categoryId, conn=Depends(db_connection)):
134141
, slug
135142
FROM categories
136143
WHERE id = %(categoryId)s
137-
""", {"categoryId": categoryId})
144+
""", {
145+
"categoryId": categoryId
146+
})
138147
result = cur.fetchone()
139148
if result is None:
140149
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
@@ -157,7 +166,13 @@ def put_v1_categories_category_id(body: CreateCategoryDto, categoryId, conn=Depe
157166
, updated_at = NOW()
158167
, updated_by = %(user_id)s
159168
WHERE id = %(categoryId)s
160-
""", {"name": body.name, "name_ru": body.name_ru, "slug": body.slug, "user_id": body.user_id, "categoryId": categoryId})
169+
""", {
170+
"name": body.name,
171+
"name_ru": body.name_ru,
172+
"slug": body.slug,
173+
"user_id": body.user_id,
174+
"categoryId": categoryId
175+
})
161176
finally:
162177
conn.close()
163178

@@ -172,6 +187,8 @@ def delete_v1_categories_category_id(categoryId, conn=Depends(db_connection)):
172187
DELETE
173188
FROM categories
174189
WHERE id = %(categoryId)s
175-
""", {"categoryId": categoryId})
190+
""", {
191+
"categoryId": categoryId
192+
})
176193
finally:
177194
conn.close()

src/cli.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,18 @@ const createEndpoints = async (destDir, { lang }, config) => {
283283
if (params.length === 0) {
284284
return params
285285
}
286-
return ', {' + Array.from(
286+
const indentLevel = 24
287+
const indent = ' '.repeat(indentLevel)
288+
const closingIndent = ' '.repeat(indentLevel - 4)
289+
return ', {\n' + Array.from(
287290
new Set(params),
288291
p => {
289292
const bindTarget = p.substring(0, 1)
290293
const paramName = p.substring(2)
291294
const prefix = placeholdersMap['py'][bindTarget]
292-
return `"${paramName}": ${prefix}${paramName}`
295+
return `${indent}"${paramName}": ${prefix}${paramName}`
293296
}
294-
).join(', ') + '}'
297+
).join(',\n') + `\n${closingIndent}}`
295298
},
296299

297300
"placeholdersMap": placeholdersMap,

0 commit comments

Comments
 (0)