Skip to content

Bind a fragment to a database - #177

Draft
Fil wants to merge 4 commits into
toph/sqlfrom
fil/sql-bind
Draft

Bind a fragment to a database#177
Fil wants to merge 4 commits into
toph/sqlfrom
fil/sql-bind

Conversation

@Fil

@Fil Fil commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
sql`fragment`.bind(database)

ties a fragment to a client:

const rows = await sql`SELECT 1`.bind(db).query();

.bind(db) returns a bound copy of the fragment (the original stays unbound). A fragment can only belong to one database: interpolating fragments bound to different databases throws an error, as well as querying a bound fragment against a different database. An unbound fragment still takes an explicit .query(db).

.flat() uses the bound database's dialect if present.

Keeping this as a PR against #176 since I'm not sure I took the correct approach altogether.

@Fil
Fil requested a review from tophtucker July 16, 2026 11:38
@Fil Fil mentioned this pull request Jul 16, 2026
4 tasks
@Fil
Fil marked this pull request as draft July 16, 2026 12:34
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.

1 participant