doc: show the use of string expressions in the SQLTagStore example

If a users attempts to escape strings with quotes in SQLTagStore
template strings (`'${expression}'`), as is usually required for
SQL query strings, the queries would fail. This change shows an
example on the correct use (`${expression}`).

PR-URL: https://github.com/nodejs/node/pull/60873
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
schliepa
2025-11-30 14:31:56 +01:00
committed by GitHub
parent 6274eb78fb
commit d0c102495a

View File

@@ -550,8 +550,8 @@ sql.run`INSERT INTO users VALUES (1, 'Alice')`;
sql.run`INSERT INTO users VALUES (2, 'Bob')`;
// Using the 'get' method to retrieve a single row.
const id = 1;
const user = sql.get`SELECT * FROM users WHERE id = ${id}`;
const name = 'Alice';
const user = sql.get`SELECT * FROM users WHERE name = ${name}`;
console.log(user); // { id: 1, name: 'Alice' }
// Using the 'all' method to retrieve all rows.
@@ -577,8 +577,8 @@ sql.run`INSERT INTO users VALUES (1, 'Alice')`;
sql.run`INSERT INTO users VALUES (2, 'Bob')`;
// Using the 'get' method to retrieve a single row.
const id = 1;
const user = sql.get`SELECT * FROM users WHERE id = ${id}`;
const name = 'Alice';
const user = sql.get`SELECT * FROM users WHERE name = ${name}`;
console.log(user); // { id: 1, name: 'Alice' }
// Using the 'all' method to retrieve all rows.