UNPKG

postgrejs

Version:

Professional PostgreSQL client NodeJS

30 lines (29 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringifyArrayForSQL = stringifyArrayForSQL; exports.stringifyValueForSQL = stringifyValueForSQL; const uuid_type_js_1 = require("../data-types/uuid-type.js"); const escape_literal_js_1 = require("./escape-literal.js"); function stringifyArrayForSQL(v, options, encode) { const arr = v.map(x => stringifyValueForSQL(x, options, encode)); return 'ARRAY[' + arr.join(',') + ']'; } function stringifyValueForSQL(v, options, encode) { if (v == null) return 'null'; if (typeof v === 'boolean') return v ? 'true' : 'false'; if (Array.isArray(v)) return stringifyArrayForSQL(v, options, encode); if (encode) v = encode(v, options || {}); if (typeof v === 'number') return '' + v; if (typeof v === 'bigint') return v.toString(); if (typeof v === 'string' && uuid_type_js_1.UuidType.isType(v)) return (0, escape_literal_js_1.escapeLiteral)('' + v) + '::uuid'; if (typeof v === 'object') return (0, escape_literal_js_1.escapeLiteral)(JSON.stringify(v)) + '::json'; return (0, escape_literal_js_1.escapeLiteral)('' + v); }