Skip to content

Commit

Permalink
refactor: simplify the escapeIdentifier logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jul 29, 2018
1 parent 6c840aa commit 00d749c
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions lib/client.js
Expand Up @@ -305,20 +305,7 @@ Client.prototype.getTypeParser = function (oid, format) {

// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
Client.prototype.escapeIdentifier = function (str) {
var escaped = '"'

for (var i = 0; i < str.length; i++) {
var c = str[i]
if (c === '"') {
escaped += c + c
} else {
escaped += c
}
}

escaped += '"'

return escaped
return '"' + str.replace(/"/g, '""') + '"'
}

// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
Expand Down

1 comment on commit 00d749c

@benjie
Copy link
Contributor

@benjie benjie commented on 00d749c May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice; this change improves this functions performance around 11x!

https://jsperf.com/local-var-vs-direct-access-sql-escaping/1

Please sign in to comment.