Skip to content

Support embedding of BoundQuery into surql#581

Merged
macjuul merged 3 commits intosurrealdb:mainfrom
akkie:feature-578-support-embedding-of-bound-query
Mar 16, 2026
Merged

Support embedding of BoundQuery into surql#581
macjuul merged 3 commits intosurrealdb:mainfrom
akkie:feature-578-support-embedding-of-bound-query

Conversation

@akkie
Copy link
Contributor

@akkie akkie commented Mar 15, 2026

What is the motivation?

The surql tagged template function creates parameterized SurrealQL queries with automatic value binding and SQL injection prevention. But this function does not support to compose queries with other surql functions.

As example:

const username = "john";
const byUserName = surql`username = ${username}`;
const query = surql`SELECT * FROM user WHERE ${byUserName}`;

What does this change do?

The PR allows to embed surql queries into other surql queries. At the end, the surql query returns a BoundQuery. This BoundQuery contains the query and the bindings. The surql function was adapted to embed the query of the given BoundQuery and to merge the bindings into the outer Boundquery.

What is your testing strategy?

There are three new tests implemented which tests the scenario.

Is this related to any issues?

Fixes #578

Have you read the Contributing Guidelines?

@akkie akkie requested a review from macjuul as a code owner March 15, 2026 08:50
Copilot AI review requested due to automatic review settings March 15, 2026 08:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the surql tagged template utility to allow embedding an existing BoundQuery inside another surql template, enabling composable query fragments while preserving bindings.

Changes:

  • Add BoundQuery interpolation support to surql by inlining the subquery string and merging its bindings.
  • Add unit tests + snapshots covering embedded, multiple embedded, and mixed embedded/non-embedded interpolation scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/sdk/src/utils/tagged-template.ts Teach surql to detect BoundQuery values and merge query/bindings into the outer query.
packages/tests/unit/utilities/tagged-template.test.ts Add tests validating embedded BoundQuery composition and binding behavior.
packages/tests/unit/utilities/snapshots/tagged-template.test.ts.snap Add expected query snapshots for the new composition scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@macjuul macjuul merged commit ad2deab into surrealdb:main Mar 16, 2026
15 checks passed
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.

Feature: Support embedding of a BoundQuery into another BoundQuery

4 participants