MCPcopy
hub / github.com/sequelize/sequelize / stringify

Function stringify

lib/dialects/postgres/range.js:29–55  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

27}
28
29function stringify(data) {
30 if (data === null) return null;
31
32 if (!Array.isArray(data)) throw new Error('range must be an array');
33 if (!data.length) return 'empty';
34 if (data.length !== 2) throw new Error('range array length must be 0 (empty) or 2 (lower and upper bounds)');
35
36 if (Object.prototype.hasOwnProperty.call(data, 'inclusive')) {
37 if (data.inclusive === false) data.inclusive = [false, false];
38 else if (!data.inclusive) data.inclusive = [true, false];
39 else if (data.inclusive === true) data.inclusive = [true, true];
40 } else {
41 data.inclusive = [true, false];
42 }
43
44 _.each(data, (value, index) => {
45 if (_.isObject(value)) {
46 if (Object.prototype.hasOwnProperty.call(value, 'inclusive')) data.inclusive[index] = !!value.inclusive;
47 if (Object.prototype.hasOwnProperty.call(value, 'value')) data[index] = value.value;
48 }
49 });
50
51 const lowerBound = stringifyRangeBound(data[0]);
52 const upperBound = stringifyRangeBound(data[1]);
53
54 return `${(data.inclusive[0] ? '[' : '(') + lowerBound},${upperBound}${data.inclusive[1] ? ']' : ')'}`;
55}
56exports.stringify = stringify;
57
58function parse(value, parser) {

Callers 1

_groupJoinDataMethod · 0.50

Calls 1

stringifyRangeBoundFunction · 0.85

Tested by

no test coverage detected