Title: template literal style ambiguity · Issue #186 · sqlitecloud/sqlitecloud-js · GitHub
Open Graph Title: template literal style ambiguity · Issue #186 · sqlitecloud/sqlitecloud-js
X Title: template literal style ambiguity · Issue #186 · sqlitecloud/sqlitecloud-js
Description: When using the template-literal-style: const result = await connection.sql` SELECT * FROM artists WHERE name LIKE "%${filter}%" LIMIT ${limit} `; there is ambiguity about the expectation. In this case 3, I'd expect the query to work but ...
Open Graph Description: When using the template-literal-style: const result = await connection.sql` SELECT * FROM artists WHERE name LIKE "%${filter}%" LIMIT ${limit} `; there is ambiguity about the expectation. In this c...
X Description: When using the template-literal-style: const result = await connection.sql` SELECT * FROM artists WHERE name LIKE "%${filter}%" LIMIT ${limit} `; there is ambiguity about the expectation....
Opengraph URL: https://github.com/sqlitecloud/sqlitecloud-js/issues/186
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"template literal style ambiguity","articleBody":"When using the template-literal-style:\r\n```\r\nconst result = await connection.sql`\r\n SELECT * FROM artists\r\n WHERE name LIKE \"%${filter}%\"\r\n LIMIT ${limit}\r\n`;\r\n```\r\n\r\nthere is ambiguity about the expectation. In this case 3, I'd expect the query to work but the prepared statement requires the entire string `%myvalue%` as value.\r\nIn the case above, the query is converted into\r\n```\r\nSELECT * FROM artists\r\nWHERE name LIKE \"%?%\"\r\nLIMIT ?\r\n```\r\nwith parameters `[\"myvalue\", 10]`. \r\nSQLite instead requires parameters to be `[\"%myvalue%, 10]`.\r\n\r\n**This template literal syntax should be deprecated.**\r\n**The correct syntax to properly escape parameters without ambiguity is (case 5 below)**:\r\n```\r\nconst result = await connection.sql(`\r\n SELECT * FROM artists\r\n WHERE name LIKE ?\r\n LIMIT ?\r\n`, `%${filter}%`, 10);\r\n```\r\n\r\n## Tested cases\r\n\r\n### Case 1 ✅ \r\n:warning: parameters are not escaped\r\n```\r\nconst result = await connection.sql(`\r\n SELECT * FROM artists\r\n WHERE name LIKE \"%${filter}%\"\r\n LIMIT ${limit}\r\n`);\r\n```\r\n\r\n### Case 2 ✅\r\n```\r\nfilter = `%${filter}%`\r\nconst result = await connection.sql`\r\n SELECT * FROM artists\r\n WHERE name LIKE ${filter}\r\n LIMIT ${limit}\r\n`;\r\n```\r\n\r\n### Case 3 ❌\r\n```\r\nconst result = await connection.sql`\r\n SELECT * FROM artists\r\n WHERE name LIKE \"%${filter}%\"\r\n LIMIT ${limit}\r\n`;\r\n```\r\n\r\n### Case 4 ✅ \r\n```\r\nconst result = await connection.sql(`\r\n SELECT * FROM artists\r\n WHERE name LIKE ?\r\n LIMIT ${limit}\r\n`, `%${filter}%`);","author":{"url":"https://github.com/danielebriggi","@type":"Person","name":"danielebriggi"},"datePublished":"2025-01-02T15:41:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/186/sqlitecloud-js/issues/186"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e374399d-c0fb-3191-1e16-d0ae95521a30 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ABC4:24665B:48C3FB:5EC66B:69922370 |
| html-safe-nonce | 1952c11e0e29e38bdd4156c4fcbf69b4d621ecea83422aa41c2f852b2c96a00b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkM0OjI0NjY1Qjo0OEMzRkI6NUVDNjZCOjY5OTIyMzcwIiwidmlzaXRvcl9pZCI6IjkxNDcxNTI2NTEzNDI5Nzk5NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 37c6d34c867351a2fd1e8b2aabd833285bee4725495cb05758503104db13716d |
| hovercard-subject-tag | issue:2766241279 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlitecloud/sqlitecloud-js/186/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af94ba44d850bd0dd6125e14f6804cbba4fca982d821aba44d65f9e7cebcf126/sqlitecloud/sqlitecloud-js/issues/186 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af94ba44d850bd0dd6125e14f6804cbba4fca982d821aba44d65f9e7cebcf126/sqlitecloud/sqlitecloud-js/issues/186 |
| og:image:alt | When using the template-literal-style: const result = await connection.sql` SELECT * FROM artists WHERE name LIKE "%${filter}%" LIMIT ${limit} `; there is ambiguity about the expectation. In this c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danielebriggi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlitecloud/sqlitecloud-js git https://github.com/sqlitecloud/sqlitecloud-js.git |
| octolytics-dimension-user_id | 71080346 |
| octolytics-dimension-user_login | sqlitecloud |
| octolytics-dimension-repository_id | 528857500 |
| octolytics-dimension-repository_nwo | sqlitecloud/sqlitecloud-js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 528857500 |
| octolytics-dimension-repository_network_root_nwo | sqlitecloud/sqlitecloud-js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width