-
-
Notifications
You must be signed in to change notification settings - Fork 106
Closed
Description
https://github.com/xialvjun/ts-sql-plugin is an interesting project that uses a TS plugin to typecheck sql query strings.
https://github.com/mmkal/slonik-tools/tree/master/packages/typegen#readme is also an interesting project that uses runtime tracing to detect query types on first run.
Both should allow you to do something roughly like this:
const notDeleted = (asOf = null) => sql`
deleted_at is null or deleted_at > ${asOf || sql`now()`}
`
const myQuery = (bar) => sql`
select * from mytable
where ${notDeleted()}
and foo = ${bar}
`
// result is fully typed
const result = await db.query(myQuery(bar))
Is pgTyped interested in experimenting with such techniques to enable query composition, for convenient sharing of common conditions etc?
pasiba
Metadata
Metadata
Assignees
Labels
No labels