@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
28 lines • 1.17 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.escapeComposite = escapeComposite;
const escapeString_1 = require("./escapeString");
const parseCompositeRow_1 = require("./parseCompositeRow");
/**
* PostgreSQL doesn't allow comparison like `WHERE (a, b) = '(1,2)'` - it throws
* "Input of anonymous composite types is not implemented" error. So to compare,
* we have to convert the stringified row representation to ROW() notation
* manually: `WHERE (a, b) = ROW('1', '2')`
*
* Notice that we don't work with ROWs consisting of 1 element; instead, we
* treat them as the element itself. I.e. instead of emitting "(123)" or
* "ROW(123)", we always emit just "123".
*
* - "1" => "1"
* - "(1)" => "1"
* - "(1,2)" => "ROW('1','2')"
*/
function escapeComposite(v) {
if (v === null || v === undefined) {
return "NULL";
}
const parts = v.startsWith("(") && v.endsWith(")") ? (0, parseCompositeRow_1.parseCompositeRow)(v) : [v];
const list = parts.map((v) => (0, escapeString_1.escapeString)(v)).join(",");
return parts.length > 1 ? `ROW(${list})` : list;
}
//# sourceMappingURL=escapeComposite.js.map
;