Skip to content

Commit af8bbff

Browse files
committed
Update named placeholder documentation to include unnamed fallback
1 parent ee3fd24 commit af8bbff

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

documentation/Extras.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Named placeholders
44

5-
You can use named placeholders for parameters by setting `namedPlaceholders` config value or query/execute time option. Named placeholders are converted to unnamed `?` on the client (mysql protocol does not support named parameters). If you reference parameter multiple times under the same name it is sent to server multiple times.
5+
You can use named placeholders for parameters by setting `namedPlaceholders` config value or query/execute time option. Named placeholders are converted to unnamed `?` on the client (mysql protocol does not support named parameters). If you reference parameter multiple times under the same name it is sent to server multiple times. Unnamed placeholders can still be used by providing the values as an array instead of an object.
66

77
```js
88
connection.config.namedPlaceholders = true;
@@ -18,8 +18,14 @@ connection.execute('select :x + :x as z', { x: 1 }, (err, rows) => {
1818
connection.query('select :x + :x as z', { x: 1 }, (err, rows) => {
1919
// query select 1 + 1 as z
2020
});
21+
22+
// unnamed placeholders are still valid if the values are provided in an array
23+
connection.query('select ? + ? as z', [1, 1], (err, rows) => {
24+
// query select 1 + 1 as z
25+
});
2126
```
2227

28+
2329
## Receiving rows as array of columns instead of hash with column name as key:
2430

2531
```js

0 commit comments

Comments
 (0)