UNPKG

postgrejs

Version:

Professional PostgreSQL client NodeJS

37 lines (36 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrayInt8Type = exports.Int8Type = void 0; const constants_js_1 = require("../constants.js"); const bigint_methods_js_1 = require("../util/bigint-methods.js"); const maxSafeInteger = BigInt(Number.MAX_SAFE_INTEGER); exports.Int8Type = { name: 'int8', oid: constants_js_1.DataTypeOIDs.int8, jsType: 'BigInt', parseBinary(buf) { const v = typeof buf.readBigInt64BE === 'function' ? buf.readBigInt64BE(0) : (0, bigint_methods_js_1.readBigInt64BE)(buf); return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v; }, encodeBinary(buf, v) { buf.writeBigInt64BE(v); }, parseText(s) { const v = BigInt(s); return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v; }, isType(v) { return (typeof v === 'bigint' || (typeof v === 'number' && Number.isInteger(v) && v > Number.MAX_SAFE_INTEGER)); }, }; exports.ArrayInt8Type = { ...exports.Int8Type, name: '_int8', oid: constants_js_1.DataTypeOIDs._int8, elementsOID: constants_js_1.DataTypeOIDs.int8, };