postgrejs
Version:
Professional PostgreSQL client NodeJS
43 lines (42 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayInt2VectorType = exports.Int2VectorType = void 0;
const constants_js_1 = require("../constants.js");
const decode_binaryarray_js_1 = require("../util/decode-binaryarray.js");
const encode_binaryarray_js_1 = require("../util/encode-binaryarray.js");
const fast_parseint_js_1 = require("../util/fast-parseint.js");
exports.Int2VectorType = {
name: 'int2vector',
oid: constants_js_1.DataTypeOIDs.int2vector,
jsType: 'array',
parseBinary(v) {
return (0, decode_binaryarray_js_1.decodeBinaryArray)(v, b => b.readInt16BE()) || undefined;
},
encodeBinary(buf, v) {
(0, encode_binaryarray_js_1.encodeBinaryArray)(buf, v, constants_js_1.DataTypeOIDs.int2, {}, (io, x) => {
io.writeInt16BE(x);
});
},
encodeCalculateDim(v) {
return [v.length];
},
parseText(str) {
return str.split(' ').map(fast_parseint_js_1.fastParseInt);
},
encodeText(v) {
return v.join(' ');
},
isType(v) {
return (Array.isArray(v) &&
!v.find(x => !(typeof x === 'number' &&
Number.isInteger(x) &&
x >= -32768 &&
x <= 32767)));
},
};
exports.ArrayInt2VectorType = {
...exports.Int2VectorType,
name: '_int2vector',
oid: constants_js_1.DataTypeOIDs._int2vector,
elementsOID: constants_js_1.DataTypeOIDs.int2vector,
};