UNPKG

postgrejs

Version:

Professional PostgreSQL client NodeJS

27 lines (26 loc) 634 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.escapeLiteral = escapeLiteral; // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c function escapeLiteral(str) { let backSlash = false; let out = "'"; let i; let c; const l = str.length; for (i = 0; i < l; i++) { c = str[i]; if (c === "'") out += c + c; else if (c === '\\') { out += c + c; backSlash = true; } else out += c; } out += "'"; if (backSlash) out = ' E' + out; return out; }