Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TypeScript plugin or runtime tracing to allow query composition? #233

@rattrayalex

Description

@rattrayalex

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions