Skip to content

Commit 131bca1

Browse files
kirsaniumphp-coder
kirsanium
authored andcommitted
feat: allow comments by removing them
1 parent f524f15 commit 131bca1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

examples/js/endpoints.yaml

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
- path: /v1/collections/:collectionId/categories/count
1919
get:
20-
query: >-
20+
query: |-
21+
-- comment
2122
SELECT COUNT(DISTINCT s.category_id) AS counter
23+
-- comment2
2224
FROM collections_series cs
25+
-- comment3
2326
JOIN series s
2427
ON s.id = cs.series_id
2528
WHERE cs.collection_id = :p.collectionId
@@ -30,7 +33,7 @@
3033

3134
- path: /v1/categories
3235
get_list:
33-
query: >-
36+
query: |-
3437
SELECT id
3538
, name
3639
, name_ru
@@ -43,7 +46,7 @@
4346
id:
4447
type: integer
4548
post:
46-
query: >-
49+
query: |-
4750
INSERT
4851
INTO categories
4952
( name
@@ -68,7 +71,7 @@
6871

6972
- path: /v1/categories/:categoryId
7073
get:
71-
query: >-
74+
query: |-
7275
SELECT id
7376
, name
7477
, name_ru
@@ -81,7 +84,7 @@
8184
id:
8285
type: integer
8386
put:
84-
query: >-
87+
query: |-
8588
UPDATE categories
8689
SET name = :b.name
8790
, name_ru = :b.name_ru
@@ -90,7 +93,7 @@
9093
, updated_by = :b.user_id
9194
WHERE id = :p.categoryId
9295
delete:
93-
query: >-
96+
query: |-
9497
DELETE
9598
FROM categories
9699
WHERE id = :p.categoryId

src/cli.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const createApp = async (destDir, lang) => {
8989
fs.copyFileSync(`${__dirname}/templates/app.${ext}`, resultFile)
9090
};
9191

92+
const removeComments = (query) => query.replace(/--.*\n/g, '');
93+
9294
// "SELECT *\n FROM foo" => "SELECT * FROM foo"
9395
const flattenQuery = (query) => query.replace(/\n[ ]*/g, ' ');
9496

@@ -142,7 +144,7 @@ const createEndpoints = async (destDir, lang, config) => {
142144
queries = Object.values(method.aggregated_queries)
143145
}
144146
queries.forEach(query => {
145-
const sql = removePlaceholders(flattenQuery(query));
147+
const sql = removePlaceholders(flattenQuery(removeComments(query)));
146148
console.log(`\t${sql}`);
147149
})
148150
});
@@ -204,7 +206,7 @@ const createEndpoints = async (destDir, lang, config) => {
204206

205207
// "SELECT *\n FROM foo WHERE id = :p.id" => "SELECT * FROM foo WHERE id = :id"
206208
"formatQuery": (query) => {
207-
return removePlaceholders(flattenQuery(query));
209+
return removePlaceholders(flattenQuery(removeComments(query)));
208210
},
209211

210212
// (used only with Golang)

0 commit comments

Comments
 (0)