UNPKG

postgrejs

Version:

Professional PostgreSQL client NodeJS

40 lines (39 loc) 1.17 kB
import { DataTypeOIDs } from '../constants.js'; import { decodeBinaryArray } from '../util/decode-binaryarray.js'; import { encodeBinaryArray } from '../util/encode-binaryarray.js'; import { fastParseInt } from '../util/fast-parseint.js'; export const Int2VectorType = { name: 'int2vector', oid: DataTypeOIDs.int2vector, jsType: 'array', parseBinary(v) { return decodeBinaryArray(v, b => b.readInt16BE()) || undefined; }, encodeBinary(buf, v) { encodeBinaryArray(buf, v, DataTypeOIDs.int2, {}, (io, x) => { io.writeInt16BE(x); }); }, encodeCalculateDim(v) { return [v.length]; }, parseText(str) { return str.split(' ').map(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))); }, }; export const ArrayInt2VectorType = { ...Int2VectorType, name: '_int2vector', oid: DataTypeOIDs._int2vector, elementsOID: DataTypeOIDs.int2vector, };