Skip to content

Commit 9406305

Browse files
committed
feat: include query name in PreparedQuery
1 parent 4cfce1b commit 9406305

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

packages/cli/src/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export function generateDeclarations(typeDecs: TypedQuery[]): string {
416416
typeDeclarations +=
417417
`export const ${typeDec.query.name} = ` +
418418
`new PreparedQuery<${typeDec.query.paramTypeAlias},${typeDec.query.returnTypeAlias}>` +
419-
`(${typeDec.query.name}IR);\n\n\n`;
419+
`(${JSON.stringify(typeDec.query.name)},${typeDec.query.name}IR);\n\n\n`;
420420
}
421421
return typeDeclarations;
422422
}

packages/example/src/books/books.queries.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const findBookByIdIR: any = {"usedParamSet":{"id":true},"params":[{"name":"id","
4141
* SELECT * FROM books WHERE id = :id
4242
* ```
4343
*/
44-
export const findBookById = new PreparedQuery<IFindBookByIdParams,IFindBookByIdResult>(findBookByIdIR);
44+
export const findBookById = new PreparedQuery<IFindBookByIdParams,IFindBookByIdResult>("findBookById",findBookByIdIR);
4545

4646

4747
/** 'FindBookByCategory' parameters type */
@@ -72,7 +72,7 @@ const findBookByCategoryIR: any = {"usedParamSet":{"category":true},"params":[{"
7272
* SELECT * FROM books WHERE :category = ANY(categories)
7373
* ```
7474
*/
75-
export const findBookByCategory = new PreparedQuery<IFindBookByCategoryParams,IFindBookByCategoryResult>(findBookByCategoryIR);
75+
export const findBookByCategory = new PreparedQuery<IFindBookByCategoryParams,IFindBookByCategoryResult>("findBookByCategory",findBookByCategoryIR);
7676

7777

7878
/** 'FindBookNameOrRank' parameters type */
@@ -103,7 +103,7 @@ const findBookNameOrRankIR: any = {"usedParamSet":{"name":true,"rank":true},"par
103103
* WHERE (name = :name OR rank = :rank)
104104
* ```
105105
*/
106-
export const findBookNameOrRank = new PreparedQuery<IFindBookNameOrRankParams,IFindBookNameOrRankResult>(findBookNameOrRankIR);
106+
export const findBookNameOrRank = new PreparedQuery<IFindBookNameOrRankParams,IFindBookNameOrRankResult>("findBookNameOrRank",findBookNameOrRankIR);
107107

108108

109109
/** 'FindBookUnicode' parameters type */
@@ -132,7 +132,7 @@ const findBookUnicodeIR: any = {"usedParamSet":{},"params":[],"statement":"SELEC
132132
* SELECT * FROM books WHERE name = 'שקל'
133133
* ```
134134
*/
135-
export const findBookUnicode = new PreparedQuery<IFindBookUnicodeParams,IFindBookUnicodeResult>(findBookUnicodeIR);
135+
export const findBookUnicode = new PreparedQuery<IFindBookUnicodeParams,IFindBookUnicodeResult>("findBookUnicode",findBookUnicodeIR);
136136

137137

138138
/** 'InsertBooks' parameters type */
@@ -165,7 +165,7 @@ const insertBooksIR: any = {"usedParamSet":{"books":true},"params":[{"name":"boo
165165
* VALUES :books RETURNING id as book_id
166166
* ```
167167
*/
168-
export const insertBooks = new PreparedQuery<IInsertBooksParams,IInsertBooksResult>(insertBooksIR);
168+
export const insertBooks = new PreparedQuery<IInsertBooksParams,IInsertBooksResult>("insertBooks",insertBooksIR);
169169

170170

171171
/** 'UpdateBooksCustom' parameters type */
@@ -199,7 +199,7 @@ const updateBooksCustomIR: any = {"usedParamSet":{"rank":true,"id":true},"params
199199
* WHERE id = :id!
200200
* ```
201201
*/
202-
export const updateBooksCustom = new PreparedQuery<IUpdateBooksCustomParams,IUpdateBooksCustomResult>(updateBooksCustomIR);
202+
export const updateBooksCustom = new PreparedQuery<IUpdateBooksCustomParams,IUpdateBooksCustomResult>("updateBooksCustom",updateBooksCustomIR);
203203

204204

205205
/** 'UpdateBooks' parameters type */
@@ -231,7 +231,7 @@ const updateBooksIR: any = {"usedParamSet":{"name":true,"rank":true,"id":true},"
231231
* WHERE id = :id!
232232
* ```
233233
*/
234-
export const updateBooks = new PreparedQuery<IUpdateBooksParams,IUpdateBooksResult>(updateBooksIR);
234+
export const updateBooks = new PreparedQuery<IUpdateBooksParams,IUpdateBooksResult>("updateBooks",updateBooksIR);
235235

236236

237237
/** 'UpdateBooksRankNotNull' parameters type */
@@ -262,7 +262,7 @@ const updateBooksRankNotNullIR: any = {"usedParamSet":{"rank":true,"name":true,"
262262
* WHERE id = :id!
263263
* ```
264264
*/
265-
export const updateBooksRankNotNull = new PreparedQuery<IUpdateBooksRankNotNullParams,IUpdateBooksRankNotNullResult>(updateBooksRankNotNullIR);
265+
export const updateBooksRankNotNull = new PreparedQuery<IUpdateBooksRankNotNullParams,IUpdateBooksRankNotNullResult>("updateBooksRankNotNull",updateBooksRankNotNullIR);
266266

267267

268268
/** 'GetBooksByAuthorName' parameters type */
@@ -295,7 +295,7 @@ const getBooksByAuthorNameIR: any = {"usedParamSet":{"authorName":true},"params"
295295
* WHERE a.first_name || ' ' || a.last_name = :authorName!
296296
* ```
297297
*/
298-
export const getBooksByAuthorName = new PreparedQuery<IGetBooksByAuthorNameParams,IGetBooksByAuthorNameResult>(getBooksByAuthorNameIR);
298+
export const getBooksByAuthorName = new PreparedQuery<IGetBooksByAuthorNameParams,IGetBooksByAuthorNameResult>("getBooksByAuthorName",getBooksByAuthorNameIR);
299299

300300

301301
/** 'AggregateEmailsAndTest' parameters type */
@@ -323,7 +323,7 @@ const aggregateEmailsAndTestIR: any = {"usedParamSet":{"testAges":true},"params"
323323
* SELECT array_agg(email) as "emails!", array_agg(age) = :testAges as ageTest FROM users
324324
* ```
325325
*/
326-
export const aggregateEmailsAndTest = new PreparedQuery<IAggregateEmailsAndTestParams,IAggregateEmailsAndTestResult>(aggregateEmailsAndTestIR);
326+
export const aggregateEmailsAndTest = new PreparedQuery<IAggregateEmailsAndTestParams,IAggregateEmailsAndTestResult>("aggregateEmailsAndTest",aggregateEmailsAndTestIR);
327327

328328

329329
/** 'GetBooks' parameters type */
@@ -349,7 +349,7 @@ const getBooksIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT id, n
349349
* SELECT id, name as "name!" FROM books
350350
* ```
351351
*/
352-
export const getBooks = new PreparedQuery<IGetBooksParams,IGetBooksResult>(getBooksIR);
352+
export const getBooks = new PreparedQuery<IGetBooksParams,IGetBooksResult>("getBooks",getBooksIR);
353353

354354

355355
/** 'CountBooks' parameters type */
@@ -374,7 +374,7 @@ const countBooksIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT cou
374374
* SELECT count(*) as book_count FROM books
375375
* ```
376376
*/
377-
export const countBooks = new PreparedQuery<ICountBooksParams,ICountBooksResult>(countBooksIR);
377+
export const countBooks = new PreparedQuery<ICountBooksParams,ICountBooksResult>("countBooks",countBooksIR);
378378

379379

380380
/** 'GetBookCountries' parameters type */
@@ -400,6 +400,6 @@ const getBookCountriesIR: any = {"usedParamSet":{},"params":[],"statement":"SELE
400400
* SELECT * FROM book_country
401401
* ```
402402
*/
403-
export const getBookCountries = new PreparedQuery<IGetBookCountriesParams,IGetBookCountriesResult>(getBookCountriesIR);
403+
export const getBookCountries = new PreparedQuery<IGetBookCountriesParams,IGetBookCountriesResult>("getBookCountries",getBookCountriesIR);
404404

405405

packages/example/src/comments/comments.queries.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const getAllCommentsIR: any = {"usedParamSet":{"id":true},"params":[{"name":"id"
2828
* SELECT * FROM book_comments WHERE id = :id! OR user_id = :id
2929
* ```
3030
*/
31-
export const getAllComments = new PreparedQuery<IGetAllCommentsParams,IGetAllCommentsResult>(getAllCommentsIR);
31+
export const getAllComments = new PreparedQuery<IGetAllCommentsParams,IGetAllCommentsResult>("getAllComments",getAllCommentsIR);
3232

3333

3434
/** 'GetAllCommentsByIds' parameters type */
@@ -58,7 +58,7 @@ const getAllCommentsByIdsIR: any = {"usedParamSet":{"ids":true},"params":[{"name
5858
* SELECT * FROM book_comments WHERE id in :ids AND id in :ids!
5959
* ```
6060
*/
61-
export const getAllCommentsByIds = new PreparedQuery<IGetAllCommentsByIdsParams,IGetAllCommentsByIdsResult>(getAllCommentsByIdsIR);
61+
export const getAllCommentsByIds = new PreparedQuery<IGetAllCommentsByIdsParams,IGetAllCommentsByIdsResult>("getAllCommentsByIds",getAllCommentsByIdsIR);
6262

6363

6464
/** 'InsertComment' parameters type */
@@ -93,7 +93,7 @@ const insertCommentIR: any = {"usedParamSet":{"comments":true},"params":[{"name"
9393
* VALUES :comments RETURNING *
9494
* ```
9595
*/
96-
export const insertComment = new PreparedQuery<IInsertCommentParams,IInsertCommentResult>(insertCommentIR);
96+
export const insertComment = new PreparedQuery<IInsertCommentParams,IInsertCommentResult>("insertComment",insertCommentIR);
9797

9898

9999
/** 'SelectExistsTest' parameters type */
@@ -118,6 +118,6 @@ const selectExistsTestIR: any = {"usedParamSet":{},"params":[],"statement":"SELE
118118
* SELECT EXISTS ( SELECT 1 WHERE true ) AS "isTransactionExists"
119119
* ```
120120
*/
121-
export const selectExistsTest = new PreparedQuery<ISelectExistsTestParams,ISelectExistsTestResult>(selectExistsTestIR);
121+
export const selectExistsTest = new PreparedQuery<ISelectExistsTestParams,ISelectExistsTestResult>("selectExistsTest",selectExistsTestIR);
122122

123123

packages/example/src/notifications/notifications.queries.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const sendNotificationsIR: any = {"usedParamSet":{"notifications":true},"params"
3636
* VALUES :notifications RETURNING id as notification_id
3737
* ```
3838
*/
39-
export const sendNotifications = new PreparedQuery<ISendNotificationsParams,ISendNotificationsResult>(sendNotificationsIR);
39+
export const sendNotifications = new PreparedQuery<ISendNotificationsParams,ISendNotificationsResult>("sendNotifications",sendNotificationsIR);
4040

4141

4242
/** 'GetNotifications' parameters type */
@@ -71,7 +71,7 @@ const getNotificationsIR: any = {"usedParamSet":{"userId":true,"date":true},"par
7171
* AND created_at > :date!
7272
* ```
7373
*/
74-
export const getNotifications = new PreparedQuery<IGetNotificationsParams,IGetNotificationsResult>(getNotificationsIR);
74+
export const getNotifications = new PreparedQuery<IGetNotificationsParams,IGetNotificationsResult>("getNotifications",getNotificationsIR);
7575

7676

7777
/** 'ThresholdFrogs' parameters type */
@@ -103,6 +103,6 @@ const thresholdFrogsIR: any = {"usedParamSet":{"numFrogs":true},"params":[{"name
103103
* WHERE CAST (n.payload->'num_frogs' AS int) > :numFrogs!
104104
* ```
105105
*/
106-
export const thresholdFrogs = new PreparedQuery<IThresholdFrogsParams,IThresholdFrogsResult>(thresholdFrogsIR);
106+
export const thresholdFrogs = new PreparedQuery<IThresholdFrogsParams,IThresholdFrogsResult>("thresholdFrogs",thresholdFrogsIR);
107107

108108

packages/runtime/src/tag.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class PreparedQuery<TParamType, TResultType> {
9797
params: TParamType,
9898
dbConnection: IDatabaseConnection,
9999
) => Promise<Array<TResultType>>;
100+
public readonly queryName: string;
100101

101102
public runWithCounts: (
102103
params: TParamType,
@@ -110,7 +111,8 @@ export class PreparedQuery<TParamType, TResultType> {
110111

111112
private readonly queryIR: SQLQueryIR;
112113

113-
constructor(queryIR: SQLQueryIR) {
114+
constructor(queryName: string, queryIR: SQLQueryIR) {
115+
this.queryName = queryName;
114116
this.queryIR = queryIR;
115117
this.run = async (params, connection) => {
116118
const { query: processedQuery, bindings } = processSQLQueryIR(

0 commit comments

Comments
 (0)