Skip to content

Add support for native sql tagged templates in discover - #39

Open
haydn wants to merge 1 commit into
ilbertt:mainfrom
haydn:support-native-sql-generics
Open

haydn wants to merge 1 commit into
ilbertt:mainfrom
haydn:support-native-sql-generics

Conversation

@haydn

@haydn haydn commented Sep 20, 2026

Copy link
Copy Markdown

Hey @ilbertt. Love the tool. This PR is a bit of an experiment/proposal for an alternative way of discovering the SQL tagged-templates.

The gist of it is this:

import type { Queries } from '#queries.gen.ts';
import { sql } from 'bun';

const messages = await sql<Queries['ListMessages'][]>`
  SELECT
    id, body, created_at
  FROM
    messages
  ORDER BY created_at DESC
`;

IMO, there are two advantages to this approach:

  1. There's no runtime code needed (bun-sqlgen would be a dev-only dependency).
  2. The sql<Type>`SELECT now()` pattern is better recognised by other tooling (syntax highlighters, formatters, code completions etc).

@haydn
haydn force-pushed the support-native-sql-generics branch from 12e4586 to 2ef3053 Compare September 20, 2026 03:32

@ilbertt ilbertt left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @haydn, thanks for the PR!

I think we should just have one way to type the query to avoid introducing complexity and more documentation. I'm not attached to the current named tag approach, and I really like the zero runtime advantage that your approach would introduce.

What I like about the current named tag approach is that the flow feels more "natural": I assign the name to the query, and the generator picks it up to generate its type. In your approach, the generator creates the type because you referenced it, which feels weird.

Also, I'm a bit scared that we would have to handle many edge cases like type aliases (e.g. import type { Queries as Q }...).

What are your thoughts?


By the way, #40 moved all the advanced cases from the simple (which has also been renamed into "basic" in #42) example to the advanced example, in case you want to update your branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants