SQL-in-TS
It sometimes makes sense to inline your queries instead of collecting them in separate SQL files.
PgTyped supports inlined queries using the sql
template literal.
To see how that works lets write some queries in users/queries.ts
:
users/queries.ts
PgTyped parses your TS files, scanning them for sql
queries and generating corresponding TS interfaces in users/queries.types.ts
:
users/queries.types.ts
We can now pass the ISelectUserIdsQuery
as a generic parameter to our query in users/queries.ts
:
users/queries.ts
For more information on writing queries in TS files checkout the SQL-in-TS guide.