Feature request: tagged template raw queries
See original GitHub issueHi, looking good so far, but this is a feature that I would like to see, something like this
await db.sql<User & { posts: Post[] }>`
SELECT
u.*,
(SELECT json_agg(post) FROM post WHERE user_id = user.id) as posts
FROM user
WHERE id = ${ userId }`
and userId would be escaped automatically. When doing raw queries with bindings as an array at the end it’s quite difficult to keep track on which ? is should correspond to which binding.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Using raw queries with tagged template literals doesn't ...
Bug description It seems to me that the raw queries feature does not really work with tagged template literals using parameters.
Read more >Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >[RFC] Support for tagged template literals - ReScript Forum
Use raw to directly directly inline the tagged template. referenced post. %%raw("require('gql')` your query `").
Read more >8. Template literals - Exploring JS
Tagged templates are function calls. In the previous example, the method String.raw is called to produce the result of the tagged template. 8.2...
Read more >ES6 tagged templates practical usability - Stack Overflow
You can use tagged templates to build APIs that are more expressive than regular function calls. For example, I'm working on a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, I’ll add a way to use identifiers.
I don’t want to have two functions that do the same thing. Kysely doesn’t yet have that many users. Now’s the time to break the API if it improves it.
Everything seems cleaner and better with tagged templates 😄
Completely raw query
Subquery
I think we are going to replace
raw
with thesql
tag you suggested in the next version.