Support embedding of BoundQuery into surql#581
Merged
macjuul merged 3 commits intosurrealdb:mainfrom Mar 16, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
BoundQueryinterpolation support tosurqlby 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
approved these changes
Mar 16, 2026
welpie21
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
surqlfunctions.As example:
What does this change do?
The PR allows to embed
surqlqueries into othersurqlqueries. At the end, thesurqlquery returns aBoundQuery. ThisBoundQuerycontains the query and the bindings. Thesurqlfunction was adapted to embed the query of the givenBoundQueryand to merge the bindings into the outerBoundquery.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?