postgrejs
Version:
Professional PostgreSQL client NodeJS
53 lines (52 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayBoxType = exports.BoxType = void 0;
const constants_js_1 = require("../constants.js");
const BOX_PATTERN1 = /^\( *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *\)$/;
const BOX_PATTERN2 = /^\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\)$/;
const BOX_PATTERN3 = /^(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*)$/;
exports.BoxType = {
name: 'box',
oid: constants_js_1.DataTypeOIDs.box,
jsType: 'object',
arraySeparator: ';',
parseBinary(v) {
return {
x1: v.readDoubleBE(0),
y1: v.readDoubleBE(8),
x2: v.readDoubleBE(16),
y2: v.readDoubleBE(24),
};
},
encodeBinary(buf, v) {
buf.writeDoubleBE(v.x1);
buf.writeDoubleBE(v.y1);
buf.writeDoubleBE(v.x2);
buf.writeDoubleBE(v.y2);
},
parseText(v) {
const m = v.match(BOX_PATTERN1) || v.match(BOX_PATTERN2) || v.match(BOX_PATTERN3);
if (!m)
return undefined;
return {
x1: parseFloat(m[1]),
y1: parseFloat(m[2]),
x2: parseFloat(m[3]),
y2: parseFloat(m[4]),
};
},
isType(v) {
return (typeof v === 'object' &&
Object.keys(v).length === 4 &&
typeof v.x1 === 'number' &&
typeof v.y1 === 'number' &&
typeof v.x2 === 'number' &&
typeof v.y2 === 'number');
},
};
exports.ArrayBoxType = {
...exports.BoxType,
name: '_box',
oid: constants_js_1.DataTypeOIDs._box,
elementsOID: constants_js_1.DataTypeOIDs.box,
};