Skip to content

Commit 5cbf163

Browse files
committed
Small performance improvement on escapeId
1 parent bd18106 commit 5cbf163

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unreleased
22
==========
33

44
* Add `.toSqlString()` escape overriding
5+
* Small performance improvement on `escapeId`
56

67
2.2.0 / 2016-11-01
78
==================

lib/SqlString.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var SqlString = exports;
22

3+
var ID_GLOBAL_REGEXP = /`/g;
4+
var QUAL_GLOBAL_REGEXP = /\./g;
35
var CHARS_GLOBAL_REGEXP = /[\0\b\t\n\r\x1a\"\'\\]/g; // eslint-disable-line no-control-regex
46
var CHARS_ESCAPE_MAP = {
57
'\0' : '\\0',
@@ -22,13 +24,11 @@ SqlString.escapeId = function escapeId(val, forbidQualified) {
2224
}
2325

2426
return sql;
27+
} else if (forbidQualified) {
28+
return '`' + String(val).replace(ID_GLOBAL_REGEXP, '``') + '`';
29+
} else {
30+
return '`' + String(val).replace(ID_GLOBAL_REGEXP, '``').replace(QUAL_GLOBAL_REGEXP, '`.`') + '`';
2531
}
26-
27-
if (forbidQualified) {
28-
return '`' + String(val).replace(/`/g, '``') + '`';
29-
}
30-
31-
return '`' + String(val).replace(/`/g, '``').replace(/\./g, '`.`') + '`';
3232
};
3333

3434
SqlString.escape = function escape(val, stringifyObjects, timeZone) {

0 commit comments

Comments
 (0)