Skip to content

Commit a0f2cec

Browse files
committed
docs: add documentation about second argument to escapeId
closes #1533
1 parent 7f8b5c4 commit a0f2cec

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Readme.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,16 @@ It also supports adding qualified identifiers. It will escape both parts.
700700
```js
701701
var sorter = 'date';
702702
var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId('posts.' + sorter);
703-
connection.query(sql, function(err, results) {
704-
// ...
705-
});
703+
// -> SELECT * FROM posts ORDER BY `posts`.`date`
704+
```
705+
706+
If you do not want to treat `.` as qualified identifiers, you can set the second
707+
argument to `true` in order to keep the string as a literal identifier:
708+
709+
```js
710+
var sorter = 'date.2';
711+
var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId(sorter, true);
712+
// -> SELECT * FROM posts ORDER BY `date.2`
706713
```
707714

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

0 commit comments

Comments
 (0)