Skip to content

Commit 1056978

Browse files
committed
docs: add documentation about second argument to escapeId
1 parent 7f915f9 commit 1056978

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,24 @@ provided by a user, you should escape it with `SqlString.escapeId(identifier)` l
9696
```js
9797
var sorter = 'date';
9898
var sql = 'SELECT * FROM posts ORDER BY ' + SqlString.escapeId(sorter);
99+
// -> SELECT * FROM posts ORDER BY `date`
99100
```
100101

101102
It also supports adding qualified identifiers. It will escape both parts.
102103

103104
```js
104105
var sorter = 'date';
105106
var sql = 'SELECT * FROM posts ORDER BY ' + SqlString.escapeId('posts.' + sorter);
107+
// -> SELECT * FROM posts ORDER BY `posts`.`date`
108+
```
109+
110+
If you do not want to treat `.` as qualified identifiers, you can set the second
111+
argument to `true` in order to keep the string as a literal identifier:
112+
113+
```js
114+
var sorter = 'date.2';
115+
var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId(sorter, true);
116+
// -> SELECT * FROM posts ORDER BY `date.2`
106117
```
107118

108119
Alternatively, you can use `??` characters as placeholders for identifiers you would

0 commit comments

Comments
 (0)