adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

@pgtyped/cli with postgres.js #576

Open sudowoodo200 opened 4 months ago

sudowoodo200 commented 4 months ago

Is your feature request related to a problem? Please describe. I think postgres.js is the best query client out there and includes it's own type hinting facility as well. Instead of bridging pgtyped connection from pg to postgres.js, why not enable usage of the postgres.js client while still using @pgtyped/cli? This also gets us transactions for free.

Describe the solution you'd like Have the cli read and generate postgres.js sql queries, which differ from @pgtyped/runtime sql in their use of templates. For instance

// postgres.js
await sql`SELECT * from users where id = ${userID}`

can be augmented into

await sql<Users[]>`SELECT * from users where id = ${userID}`

The list of dynamic query templating is finite: https://github.com/porsager/postgres?tab=readme-ov-file#queries

Additional context Would love postgres.js to collab too, but thought it'd be straightfwd to support it in the cli here.