relq 1.0.55 → 1.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/condition/array-condition-builder.cjs +24 -0
- package/dist/cjs/condition/condition-collector.cjs +112 -4
- package/dist/cjs/condition/geometric-condition-builder.cjs +33 -13
- package/dist/cjs/condition/index.cjs +4 -1
- package/dist/cjs/condition/network-condition-builder.cjs +13 -6
- package/dist/cjs/condition/postgis-condition-builder.cjs +188 -0
- package/dist/cjs/condition/range-condition-builder.cjs +21 -5
- package/dist/cjs/config/config.cjs +6 -0
- package/dist/cjs/core/relq-client.cjs +4 -0
- package/dist/config.d.ts +69 -0
- package/dist/esm/condition/array-condition-builder.js +24 -0
- package/dist/esm/condition/condition-collector.js +112 -4
- package/dist/esm/condition/geometric-condition-builder.js +33 -13
- package/dist/esm/condition/index.js +1 -0
- package/dist/esm/condition/network-condition-builder.js +13 -6
- package/dist/esm/condition/postgis-condition-builder.js +180 -0
- package/dist/esm/condition/range-condition-builder.js +21 -5
- package/dist/esm/config/config.js +6 -0
- package/dist/esm/core/relq-client.js +4 -0
- package/dist/index.d.ts +426 -401
- package/package.json +1 -1
|
@@ -92,6 +92,22 @@ class ArrayConditionCollector {
|
|
|
92
92
|
});
|
|
93
93
|
return this.parent;
|
|
94
94
|
}
|
|
95
|
+
slice(column, start, end, values) {
|
|
96
|
+
this.parent.conditions.push({
|
|
97
|
+
method: 'array_slice',
|
|
98
|
+
column,
|
|
99
|
+
values: { start, end, values }
|
|
100
|
+
});
|
|
101
|
+
return this.parent;
|
|
102
|
+
}
|
|
103
|
+
atIndex(column, index, value) {
|
|
104
|
+
this.parent.conditions.push({
|
|
105
|
+
method: 'array_at_index',
|
|
106
|
+
column,
|
|
107
|
+
values: { index, value }
|
|
108
|
+
});
|
|
109
|
+
return this.parent;
|
|
110
|
+
}
|
|
95
111
|
containsPattern(column, pattern, matchType = 'prefix') {
|
|
96
112
|
this.parent.conditions.push({
|
|
97
113
|
method: 'array_contains_pattern',
|
|
@@ -237,6 +253,14 @@ function buildArrayConditionSQL(condition) {
|
|
|
237
253
|
}
|
|
238
254
|
case 'array_length':
|
|
239
255
|
return (0, pg_format_1.default)('array_length(%I, 1) = %L', column, values);
|
|
256
|
+
case 'array_slice': {
|
|
257
|
+
const { start, end, values: sliceValues } = values;
|
|
258
|
+
return (0, pg_format_1.default)('%I[%s:%s] = ARRAY[%s]', column, start, end, sliceValues.map(v => (0, pg_format_1.default)('%L', v)).join(','));
|
|
259
|
+
}
|
|
260
|
+
case 'array_at_index': {
|
|
261
|
+
const { index, value } = values;
|
|
262
|
+
return (0, pg_format_1.default)('%I[%s] = %L', column, index, value);
|
|
263
|
+
}
|
|
240
264
|
case 'array_contains_pattern': {
|
|
241
265
|
const { pattern, matchType } = values;
|
|
242
266
|
const likePattern = formatLikePattern(pattern, matchType);
|
|
@@ -13,6 +13,7 @@ const fulltext_condition_builder_1 = require("./fulltext-condition-builder.cjs")
|
|
|
13
13
|
const range_condition_builder_1 = require("./range-condition-builder.cjs");
|
|
14
14
|
const geometric_condition_builder_1 = require("./geometric-condition-builder.cjs");
|
|
15
15
|
const network_condition_builder_1 = require("./network-condition-builder.cjs");
|
|
16
|
+
const postgis_condition_builder_1 = require("./postgis-condition-builder.cjs");
|
|
16
17
|
class ConditionCollector {
|
|
17
18
|
conditions = [];
|
|
18
19
|
_jsonb;
|
|
@@ -21,12 +22,16 @@ class ConditionCollector {
|
|
|
21
22
|
_range;
|
|
22
23
|
_geometric;
|
|
23
24
|
_network;
|
|
25
|
+
_postgis;
|
|
24
26
|
get jsonb() {
|
|
25
27
|
if (!this._jsonb) {
|
|
26
28
|
this._jsonb = new jsonb_condition_builder_1.JsonbConditionCollector(this);
|
|
27
29
|
}
|
|
28
30
|
return this._jsonb;
|
|
29
31
|
}
|
|
32
|
+
get json() {
|
|
33
|
+
return this.jsonb;
|
|
34
|
+
}
|
|
30
35
|
get array() {
|
|
31
36
|
if (!this._array) {
|
|
32
37
|
this._array = new array_condition_builder_1.ArrayConditionCollector(this);
|
|
@@ -57,6 +62,12 @@ class ConditionCollector {
|
|
|
57
62
|
}
|
|
58
63
|
return this._network;
|
|
59
64
|
}
|
|
65
|
+
get postgis() {
|
|
66
|
+
if (!this._postgis) {
|
|
67
|
+
this._postgis = new postgis_condition_builder_1.PostgisConditionCollector(this);
|
|
68
|
+
}
|
|
69
|
+
return this._postgis;
|
|
70
|
+
}
|
|
60
71
|
equal(column, value) {
|
|
61
72
|
this.conditions.push({ method: 'equal', column, values: value });
|
|
62
73
|
return this;
|
|
@@ -133,6 +144,66 @@ class ConditionCollector {
|
|
|
133
144
|
this.conditions.push({ method: 'ilike', column, values: pattern });
|
|
134
145
|
return this;
|
|
135
146
|
}
|
|
147
|
+
notIlike(column, pattern) {
|
|
148
|
+
this.conditions.push({ method: 'notIlike', column, values: pattern });
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
regex(column, pattern) {
|
|
152
|
+
this.conditions.push({ method: 'regex', column, values: pattern });
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
iregex(column, pattern) {
|
|
156
|
+
this.conditions.push({ method: 'iregex', column, values: pattern });
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
notRegex(column, pattern) {
|
|
160
|
+
this.conditions.push({ method: 'notRegex', column, values: pattern });
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
notIregex(column, pattern) {
|
|
164
|
+
this.conditions.push({ method: 'notIregex', column, values: pattern });
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
similarTo(column, pattern) {
|
|
168
|
+
this.conditions.push({ method: 'similarTo', column, values: pattern });
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
notSimilarTo(column, pattern) {
|
|
172
|
+
this.conditions.push({ method: 'notSimilarTo', column, values: pattern });
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
isTrue(column) {
|
|
176
|
+
this.conditions.push({ method: 'isTrue', column });
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
isFalse(column) {
|
|
180
|
+
this.conditions.push({ method: 'isFalse', column });
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
distinctFrom(column, value) {
|
|
184
|
+
this.conditions.push({ method: 'distinctFrom', column, values: value });
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
notDistinctFrom(column, value) {
|
|
188
|
+
this.conditions.push({ method: 'notDistinctFrom', column, values: value });
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
overlaps(start, end) {
|
|
192
|
+
this.conditions.push({
|
|
193
|
+
method: 'overlaps',
|
|
194
|
+
values: { startColumn: start[0], startValue: start[1], endColumn: end[0], endValue: end[1] }
|
|
195
|
+
});
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
greaterThanOrEqual(column, value) {
|
|
199
|
+
return this.greaterThanEqual(column, value);
|
|
200
|
+
}
|
|
201
|
+
lessThanOrEqual(column, value) {
|
|
202
|
+
return this.lessThanEqual(column, value);
|
|
203
|
+
}
|
|
204
|
+
notNull(column) {
|
|
205
|
+
return this.isNotNull(column);
|
|
206
|
+
}
|
|
136
207
|
in(column, values) {
|
|
137
208
|
this.conditions.push({ method: 'in', column, values });
|
|
138
209
|
return this;
|
|
@@ -169,8 +240,10 @@ class ConditionCollector {
|
|
|
169
240
|
this.conditions.push({ method: 'and', values: subBuilder.getConditions() });
|
|
170
241
|
return this;
|
|
171
242
|
}
|
|
172
|
-
|
|
173
|
-
|
|
243
|
+
not(callback) {
|
|
244
|
+
const subBuilder = new ConditionCollector();
|
|
245
|
+
callback(subBuilder);
|
|
246
|
+
this.conditions.push({ method: 'not', values: subBuilder.getConditions() });
|
|
174
247
|
return this;
|
|
175
248
|
}
|
|
176
249
|
getConditions() {
|
|
@@ -205,6 +278,9 @@ function buildConditionSQL(condition) {
|
|
|
205
278
|
if (method.startsWith('network_')) {
|
|
206
279
|
return (0, network_condition_builder_1.buildNetworkConditionSQL)(condition);
|
|
207
280
|
}
|
|
281
|
+
if (method.startsWith('postgis_')) {
|
|
282
|
+
return (0, postgis_condition_builder_1.buildPostgisConditionSQL)(condition);
|
|
283
|
+
}
|
|
208
284
|
const col = column ? formatColumn(column) : '';
|
|
209
285
|
switch (method) {
|
|
210
286
|
case 'equal':
|
|
@@ -255,6 +331,36 @@ function buildConditionSQL(condition) {
|
|
|
255
331
|
return `${col} NOT LIKE ${(0, pg_format_1.default)('%L', values)}`;
|
|
256
332
|
case 'ilike':
|
|
257
333
|
return `${col} ILIKE ${(0, pg_format_1.default)('%L', values)}`;
|
|
334
|
+
case 'notIlike':
|
|
335
|
+
return `${col} NOT ILIKE ${(0, pg_format_1.default)('%L', values)}`;
|
|
336
|
+
case 'regex':
|
|
337
|
+
return `${col} ~ ${(0, pg_format_1.default)('%L', values)}`;
|
|
338
|
+
case 'iregex':
|
|
339
|
+
return `${col} ~* ${(0, pg_format_1.default)('%L', values)}`;
|
|
340
|
+
case 'notRegex':
|
|
341
|
+
return `${col} !~ ${(0, pg_format_1.default)('%L', values)}`;
|
|
342
|
+
case 'notIregex':
|
|
343
|
+
return `${col} !~* ${(0, pg_format_1.default)('%L', values)}`;
|
|
344
|
+
case 'similarTo':
|
|
345
|
+
return `${col} SIMILAR TO ${(0, pg_format_1.default)('%L', values)}`;
|
|
346
|
+
case 'notSimilarTo':
|
|
347
|
+
return `${col} NOT SIMILAR TO ${(0, pg_format_1.default)('%L', values)}`;
|
|
348
|
+
case 'isTrue':
|
|
349
|
+
return `${col} IS TRUE`;
|
|
350
|
+
case 'isFalse':
|
|
351
|
+
return `${col} IS FALSE`;
|
|
352
|
+
case 'distinctFrom':
|
|
353
|
+
return `${col} IS DISTINCT FROM ${(0, pg_format_1.default)('%L', values)}`;
|
|
354
|
+
case 'notDistinctFrom':
|
|
355
|
+
return `${col} IS NOT DISTINCT FROM ${(0, pg_format_1.default)('%L', values)}`;
|
|
356
|
+
case 'overlaps': {
|
|
357
|
+
const { startColumn, startValue, endColumn, endValue } = values;
|
|
358
|
+
const startCol = formatColumn(startColumn);
|
|
359
|
+
const endCol = formatColumn(endColumn);
|
|
360
|
+
const startVal = startValue instanceof Date ? startValue.toISOString() : startValue;
|
|
361
|
+
const endVal = endValue instanceof Date ? endValue.toISOString() : endValue;
|
|
362
|
+
return `(${startCol}, ${endCol}) OVERLAPS (${(0, pg_format_1.default)('%L', startVal)}, ${(0, pg_format_1.default)('%L', endVal)})`;
|
|
363
|
+
}
|
|
258
364
|
case 'in': {
|
|
259
365
|
const valueList = Array.isArray(values) ? values : [values];
|
|
260
366
|
const formattedValues = valueList.map(v => (0, pg_format_1.default)('%L', v)).join(', ');
|
|
@@ -281,8 +387,10 @@ function buildConditionSQL(condition) {
|
|
|
281
387
|
const andConditions = values;
|
|
282
388
|
return `(${andConditions.map(c => buildConditionSQL(c)).join(' AND ')})`;
|
|
283
389
|
}
|
|
284
|
-
case '
|
|
285
|
-
|
|
390
|
+
case 'not': {
|
|
391
|
+
const notConditions = values;
|
|
392
|
+
return `NOT (${notConditions.map(c => buildConditionSQL(c)).join(' AND ')})`;
|
|
393
|
+
}
|
|
286
394
|
default:
|
|
287
395
|
return '';
|
|
288
396
|
}
|
|
@@ -6,6 +6,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.GeometricConditionCollector = void 0;
|
|
7
7
|
exports.buildGeometricConditionSQL = buildGeometricConditionSQL;
|
|
8
8
|
const pg_format_1 = __importDefault(require("../addon/pg-format/index.cjs"));
|
|
9
|
+
function geometricToSQL(input) {
|
|
10
|
+
if (typeof input === 'string')
|
|
11
|
+
return input;
|
|
12
|
+
if (Array.isArray(input) && input.length === 2 && typeof input[0] === 'number' && typeof input[1] === 'number') {
|
|
13
|
+
return `(${input[0]},${input[1]})`;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(input) && input.length === 2 && Array.isArray(input[0]) && typeof input[1] === 'number') {
|
|
16
|
+
const [center, radius] = input;
|
|
17
|
+
return `<(${center[0]},${center[1]}),${radius}>`;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(input) && input.length === 2 && Array.isArray(input[0]) && Array.isArray(input[1])) {
|
|
20
|
+
const [p1, p2] = input;
|
|
21
|
+
return `((${p1[0]},${p1[1]}),(${p2[0]},${p2[1]}))`;
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(input) && input.length > 2) {
|
|
24
|
+
const points = input;
|
|
25
|
+
return `(${points.map(p => `(${p[0]},${p[1]})`).join(',')})`;
|
|
26
|
+
}
|
|
27
|
+
return String(input);
|
|
28
|
+
}
|
|
9
29
|
class GeometricConditionCollector {
|
|
10
30
|
parent;
|
|
11
31
|
constructor(parent) {
|
|
@@ -15,7 +35,7 @@ class GeometricConditionCollector {
|
|
|
15
35
|
this.parent.conditions.push({
|
|
16
36
|
method: 'geometric_contains',
|
|
17
37
|
column,
|
|
18
|
-
values: value
|
|
38
|
+
values: geometricToSQL(value)
|
|
19
39
|
});
|
|
20
40
|
return this.parent;
|
|
21
41
|
}
|
|
@@ -23,7 +43,7 @@ class GeometricConditionCollector {
|
|
|
23
43
|
this.parent.conditions.push({
|
|
24
44
|
method: 'geometric_contained_by',
|
|
25
45
|
column,
|
|
26
|
-
values: value
|
|
46
|
+
values: geometricToSQL(value)
|
|
27
47
|
});
|
|
28
48
|
return this.parent;
|
|
29
49
|
}
|
|
@@ -31,7 +51,7 @@ class GeometricConditionCollector {
|
|
|
31
51
|
this.parent.conditions.push({
|
|
32
52
|
method: 'geometric_overlaps',
|
|
33
53
|
column,
|
|
34
|
-
values: value
|
|
54
|
+
values: geometricToSQL(value)
|
|
35
55
|
});
|
|
36
56
|
return this.parent;
|
|
37
57
|
}
|
|
@@ -39,7 +59,7 @@ class GeometricConditionCollector {
|
|
|
39
59
|
this.parent.conditions.push({
|
|
40
60
|
method: 'geometric_strictly_left',
|
|
41
61
|
column,
|
|
42
|
-
values: value
|
|
62
|
+
values: geometricToSQL(value)
|
|
43
63
|
});
|
|
44
64
|
return this.parent;
|
|
45
65
|
}
|
|
@@ -47,7 +67,7 @@ class GeometricConditionCollector {
|
|
|
47
67
|
this.parent.conditions.push({
|
|
48
68
|
method: 'geometric_strictly_right',
|
|
49
69
|
column,
|
|
50
|
-
values: value
|
|
70
|
+
values: geometricToSQL(value)
|
|
51
71
|
});
|
|
52
72
|
return this.parent;
|
|
53
73
|
}
|
|
@@ -55,7 +75,7 @@ class GeometricConditionCollector {
|
|
|
55
75
|
this.parent.conditions.push({
|
|
56
76
|
method: 'geometric_below',
|
|
57
77
|
column,
|
|
58
|
-
values: value
|
|
78
|
+
values: geometricToSQL(value)
|
|
59
79
|
});
|
|
60
80
|
return this.parent;
|
|
61
81
|
}
|
|
@@ -63,7 +83,7 @@ class GeometricConditionCollector {
|
|
|
63
83
|
this.parent.conditions.push({
|
|
64
84
|
method: 'geometric_above',
|
|
65
85
|
column,
|
|
66
|
-
values: value
|
|
86
|
+
values: geometricToSQL(value)
|
|
67
87
|
});
|
|
68
88
|
return this.parent;
|
|
69
89
|
}
|
|
@@ -71,7 +91,7 @@ class GeometricConditionCollector {
|
|
|
71
91
|
this.parent.conditions.push({
|
|
72
92
|
method: 'geometric_intersects',
|
|
73
93
|
column,
|
|
74
|
-
values: value
|
|
94
|
+
values: geometricToSQL(value)
|
|
75
95
|
});
|
|
76
96
|
return this.parent;
|
|
77
97
|
}
|
|
@@ -109,7 +129,7 @@ class GeometricConditionCollector {
|
|
|
109
129
|
this.parent.conditions.push({
|
|
110
130
|
method: 'geometric_same_as',
|
|
111
131
|
column,
|
|
112
|
-
values: value
|
|
132
|
+
values: geometricToSQL(value)
|
|
113
133
|
});
|
|
114
134
|
return this.parent;
|
|
115
135
|
}
|
|
@@ -117,7 +137,7 @@ class GeometricConditionCollector {
|
|
|
117
137
|
this.parent.conditions.push({
|
|
118
138
|
method: 'geometric_distance_lt',
|
|
119
139
|
column,
|
|
120
|
-
values: { value, threshold: maxDistance }
|
|
140
|
+
values: { value: geometricToSQL(value), threshold: maxDistance }
|
|
121
141
|
});
|
|
122
142
|
return this.parent;
|
|
123
143
|
}
|
|
@@ -125,7 +145,7 @@ class GeometricConditionCollector {
|
|
|
125
145
|
this.parent.conditions.push({
|
|
126
146
|
method: 'geometric_distance_lte',
|
|
127
147
|
column,
|
|
128
|
-
values: { value, threshold: maxDistance }
|
|
148
|
+
values: { value: geometricToSQL(value), threshold: maxDistance }
|
|
129
149
|
});
|
|
130
150
|
return this.parent;
|
|
131
151
|
}
|
|
@@ -133,7 +153,7 @@ class GeometricConditionCollector {
|
|
|
133
153
|
this.parent.conditions.push({
|
|
134
154
|
method: 'geometric_distance_gt',
|
|
135
155
|
column,
|
|
136
|
-
values: { value, threshold: minDistance }
|
|
156
|
+
values: { value: geometricToSQL(value), threshold: minDistance }
|
|
137
157
|
});
|
|
138
158
|
return this.parent;
|
|
139
159
|
}
|
|
@@ -141,7 +161,7 @@ class GeometricConditionCollector {
|
|
|
141
161
|
this.parent.conditions.push({
|
|
142
162
|
method: 'geometric_distance_between',
|
|
143
163
|
column,
|
|
144
|
-
values: { value, min: minDistance, max: maxDistance }
|
|
164
|
+
values: { value: geometricToSQL(value), min: minDistance, max: maxDistance }
|
|
145
165
|
});
|
|
146
166
|
return this.parent;
|
|
147
167
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildNetworkConditionSQL = exports.NetworkConditionCollector = exports.buildGeometricConditionSQL = exports.GeometricConditionCollector = exports.buildRangeConditionSQL = exports.RangeConditionCollector = exports.buildFulltextConditionSQL = exports.FulltextConditionCollector = exports.buildArrayConditionSQL = exports.ArrayConditionCollector = exports.buildJsonbConditionSQL = exports.JsonbConditionCollector = exports.buildConditionsSQL = exports.buildConditionSQL = exports.ConditionCollector = void 0;
|
|
3
|
+
exports.buildPostgisConditionSQL = exports.PostgisConditionCollector = exports.buildNetworkConditionSQL = exports.NetworkConditionCollector = exports.buildGeometricConditionSQL = exports.GeometricConditionCollector = exports.buildRangeConditionSQL = exports.RangeConditionCollector = exports.buildFulltextConditionSQL = exports.FulltextConditionCollector = exports.buildArrayConditionSQL = exports.ArrayConditionCollector = exports.buildJsonbConditionSQL = exports.JsonbConditionCollector = exports.buildConditionsSQL = exports.buildConditionSQL = exports.ConditionCollector = void 0;
|
|
4
4
|
var condition_collector_1 = require("./condition-collector.cjs");
|
|
5
5
|
Object.defineProperty(exports, "ConditionCollector", { enumerable: true, get: function () { return condition_collector_1.ConditionCollector; } });
|
|
6
6
|
Object.defineProperty(exports, "buildConditionSQL", { enumerable: true, get: function () { return condition_collector_1.buildConditionSQL; } });
|
|
@@ -23,3 +23,6 @@ Object.defineProperty(exports, "buildGeometricConditionSQL", { enumerable: true,
|
|
|
23
23
|
var network_condition_builder_1 = require("./network-condition-builder.cjs");
|
|
24
24
|
Object.defineProperty(exports, "NetworkConditionCollector", { enumerable: true, get: function () { return network_condition_builder_1.NetworkConditionCollector; } });
|
|
25
25
|
Object.defineProperty(exports, "buildNetworkConditionSQL", { enumerable: true, get: function () { return network_condition_builder_1.buildNetworkConditionSQL; } });
|
|
26
|
+
var postgis_condition_builder_1 = require("./postgis-condition-builder.cjs");
|
|
27
|
+
Object.defineProperty(exports, "PostgisConditionCollector", { enumerable: true, get: function () { return postgis_condition_builder_1.PostgisConditionCollector; } });
|
|
28
|
+
Object.defineProperty(exports, "buildPostgisConditionSQL", { enumerable: true, get: function () { return postgis_condition_builder_1.buildPostgisConditionSQL; } });
|
|
@@ -6,6 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.NetworkConditionCollector = void 0;
|
|
7
7
|
exports.buildNetworkConditionSQL = buildNetworkConditionSQL;
|
|
8
8
|
const pg_format_1 = __importDefault(require("../addon/pg-format/index.cjs"));
|
|
9
|
+
function networkToSQL(address) {
|
|
10
|
+
if (typeof address === 'string')
|
|
11
|
+
return address;
|
|
12
|
+
const { octets, mask } = address;
|
|
13
|
+
const ip = octets.join('.');
|
|
14
|
+
return mask !== undefined ? `${ip}/${mask}` : ip;
|
|
15
|
+
}
|
|
9
16
|
class NetworkConditionCollector {
|
|
10
17
|
parent;
|
|
11
18
|
constructor(parent) {
|
|
@@ -15,7 +22,7 @@ class NetworkConditionCollector {
|
|
|
15
22
|
this.parent.conditions.push({
|
|
16
23
|
method: 'network_contained_by_strict',
|
|
17
24
|
column,
|
|
18
|
-
values: value
|
|
25
|
+
values: networkToSQL(value)
|
|
19
26
|
});
|
|
20
27
|
return this.parent;
|
|
21
28
|
}
|
|
@@ -23,7 +30,7 @@ class NetworkConditionCollector {
|
|
|
23
30
|
this.parent.conditions.push({
|
|
24
31
|
method: 'network_contained_by_or_equal',
|
|
25
32
|
column,
|
|
26
|
-
values: value
|
|
33
|
+
values: networkToSQL(value)
|
|
27
34
|
});
|
|
28
35
|
return this.parent;
|
|
29
36
|
}
|
|
@@ -31,7 +38,7 @@ class NetworkConditionCollector {
|
|
|
31
38
|
this.parent.conditions.push({
|
|
32
39
|
method: 'network_contains_strict',
|
|
33
40
|
column,
|
|
34
|
-
values: value
|
|
41
|
+
values: networkToSQL(value)
|
|
35
42
|
});
|
|
36
43
|
return this.parent;
|
|
37
44
|
}
|
|
@@ -39,7 +46,7 @@ class NetworkConditionCollector {
|
|
|
39
46
|
this.parent.conditions.push({
|
|
40
47
|
method: 'network_contains_or_equal',
|
|
41
48
|
column,
|
|
42
|
-
values: value
|
|
49
|
+
values: networkToSQL(value)
|
|
43
50
|
});
|
|
44
51
|
return this.parent;
|
|
45
52
|
}
|
|
@@ -47,7 +54,7 @@ class NetworkConditionCollector {
|
|
|
47
54
|
this.parent.conditions.push({
|
|
48
55
|
method: 'network_overlaps',
|
|
49
56
|
column,
|
|
50
|
-
values: value
|
|
57
|
+
values: networkToSQL(value)
|
|
51
58
|
});
|
|
52
59
|
return this.parent;
|
|
53
60
|
}
|
|
@@ -55,7 +62,7 @@ class NetworkConditionCollector {
|
|
|
55
62
|
this.parent.conditions.push({
|
|
56
63
|
method: 'network_same_family',
|
|
57
64
|
column,
|
|
58
|
-
values: value
|
|
65
|
+
values: networkToSQL(value)
|
|
59
66
|
});
|
|
60
67
|
return this.parent;
|
|
61
68
|
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PostgisConditionCollector = void 0;
|
|
7
|
+
exports.buildPostgisConditionSQL = buildPostgisConditionSQL;
|
|
8
|
+
const pg_format_1 = __importDefault(require("../addon/pg-format/index.cjs"));
|
|
9
|
+
function isGeoJson(input) {
|
|
10
|
+
return typeof input === 'object' && input !== null && 'type' in input && 'coordinates' in input;
|
|
11
|
+
}
|
|
12
|
+
function geometryInputToSQL(input) {
|
|
13
|
+
if (isGeoJson(input)) {
|
|
14
|
+
return { sql: JSON.stringify(input), isGeoJson: true };
|
|
15
|
+
}
|
|
16
|
+
return { sql: input, isGeoJson: false };
|
|
17
|
+
}
|
|
18
|
+
class PostgisConditionCollector {
|
|
19
|
+
parent;
|
|
20
|
+
constructor(parent) {
|
|
21
|
+
this.parent = parent;
|
|
22
|
+
}
|
|
23
|
+
contains(column, geometry) {
|
|
24
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
25
|
+
this.parent.conditions.push({
|
|
26
|
+
method: 'postgis_contains',
|
|
27
|
+
column,
|
|
28
|
+
values: { geometry: sql, isGeoJson }
|
|
29
|
+
});
|
|
30
|
+
return this.parent;
|
|
31
|
+
}
|
|
32
|
+
within(column, geometry) {
|
|
33
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
34
|
+
this.parent.conditions.push({
|
|
35
|
+
method: 'postgis_within',
|
|
36
|
+
column,
|
|
37
|
+
values: { geometry: sql, isGeoJson }
|
|
38
|
+
});
|
|
39
|
+
return this.parent;
|
|
40
|
+
}
|
|
41
|
+
intersects(column, geometry) {
|
|
42
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
43
|
+
this.parent.conditions.push({
|
|
44
|
+
method: 'postgis_intersects',
|
|
45
|
+
column,
|
|
46
|
+
values: { geometry: sql, isGeoJson }
|
|
47
|
+
});
|
|
48
|
+
return this.parent;
|
|
49
|
+
}
|
|
50
|
+
overlaps(column, geometry) {
|
|
51
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
52
|
+
this.parent.conditions.push({
|
|
53
|
+
method: 'postgis_overlaps',
|
|
54
|
+
column,
|
|
55
|
+
values: { geometry: sql, isGeoJson }
|
|
56
|
+
});
|
|
57
|
+
return this.parent;
|
|
58
|
+
}
|
|
59
|
+
crosses(column, geometry) {
|
|
60
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
61
|
+
this.parent.conditions.push({
|
|
62
|
+
method: 'postgis_crosses',
|
|
63
|
+
column,
|
|
64
|
+
values: { geometry: sql, isGeoJson }
|
|
65
|
+
});
|
|
66
|
+
return this.parent;
|
|
67
|
+
}
|
|
68
|
+
touches(column, geometry) {
|
|
69
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
70
|
+
this.parent.conditions.push({
|
|
71
|
+
method: 'postgis_touches',
|
|
72
|
+
column,
|
|
73
|
+
values: { geometry: sql, isGeoJson }
|
|
74
|
+
});
|
|
75
|
+
return this.parent;
|
|
76
|
+
}
|
|
77
|
+
disjoint(column, geometry) {
|
|
78
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
79
|
+
this.parent.conditions.push({
|
|
80
|
+
method: 'postgis_disjoint',
|
|
81
|
+
column,
|
|
82
|
+
values: { geometry: sql, isGeoJson }
|
|
83
|
+
});
|
|
84
|
+
return this.parent;
|
|
85
|
+
}
|
|
86
|
+
equals(column, geometry) {
|
|
87
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
88
|
+
this.parent.conditions.push({
|
|
89
|
+
method: 'postgis_equals',
|
|
90
|
+
column,
|
|
91
|
+
values: { geometry: sql, isGeoJson }
|
|
92
|
+
});
|
|
93
|
+
return this.parent;
|
|
94
|
+
}
|
|
95
|
+
dwithin(column, geometry, distance) {
|
|
96
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
97
|
+
this.parent.conditions.push({
|
|
98
|
+
method: 'postgis_dwithin',
|
|
99
|
+
column,
|
|
100
|
+
values: { geometry: sql, isGeoJson, distance }
|
|
101
|
+
});
|
|
102
|
+
return this.parent;
|
|
103
|
+
}
|
|
104
|
+
distanceLessThan(column, geometry, distance) {
|
|
105
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
106
|
+
this.parent.conditions.push({
|
|
107
|
+
method: 'postgis_distance_lt',
|
|
108
|
+
column,
|
|
109
|
+
values: { geometry: sql, isGeoJson, distance }
|
|
110
|
+
});
|
|
111
|
+
return this.parent;
|
|
112
|
+
}
|
|
113
|
+
distanceGreaterThan(column, geometry, distance) {
|
|
114
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
115
|
+
this.parent.conditions.push({
|
|
116
|
+
method: 'postgis_distance_gt',
|
|
117
|
+
column,
|
|
118
|
+
values: { geometry: sql, isGeoJson, distance }
|
|
119
|
+
});
|
|
120
|
+
return this.parent;
|
|
121
|
+
}
|
|
122
|
+
coveredBy(column, geometry) {
|
|
123
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
124
|
+
this.parent.conditions.push({
|
|
125
|
+
method: 'postgis_covered_by',
|
|
126
|
+
column,
|
|
127
|
+
values: { geometry: sql, isGeoJson }
|
|
128
|
+
});
|
|
129
|
+
return this.parent;
|
|
130
|
+
}
|
|
131
|
+
covers(column, geometry) {
|
|
132
|
+
const { sql, isGeoJson } = geometryInputToSQL(geometry);
|
|
133
|
+
this.parent.conditions.push({
|
|
134
|
+
method: 'postgis_covers',
|
|
135
|
+
column,
|
|
136
|
+
values: { geometry: sql, isGeoJson }
|
|
137
|
+
});
|
|
138
|
+
return this.parent;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.PostgisConditionCollector = PostgisConditionCollector;
|
|
142
|
+
function formatGeometrySQL(geometry, isGeoJson) {
|
|
143
|
+
if (isGeoJson) {
|
|
144
|
+
return (0, pg_format_1.default)('ST_GeomFromGeoJSON(%L)', geometry);
|
|
145
|
+
}
|
|
146
|
+
return (0, pg_format_1.default)('ST_GeomFromText(%L)', geometry);
|
|
147
|
+
}
|
|
148
|
+
function buildPostgisConditionSQL(condition) {
|
|
149
|
+
const { method, column, values } = condition;
|
|
150
|
+
const { geometry, isGeoJson } = values;
|
|
151
|
+
const geomSQL = formatGeometrySQL(geometry, isGeoJson);
|
|
152
|
+
switch (method) {
|
|
153
|
+
case 'postgis_contains':
|
|
154
|
+
return (0, pg_format_1.default)('ST_Contains(%I, ', column) + geomSQL + ')';
|
|
155
|
+
case 'postgis_within':
|
|
156
|
+
return (0, pg_format_1.default)('ST_Within(%I, ', column) + geomSQL + ')';
|
|
157
|
+
case 'postgis_intersects':
|
|
158
|
+
return (0, pg_format_1.default)('ST_Intersects(%I, ', column) + geomSQL + ')';
|
|
159
|
+
case 'postgis_overlaps':
|
|
160
|
+
return (0, pg_format_1.default)('ST_Overlaps(%I, ', column) + geomSQL + ')';
|
|
161
|
+
case 'postgis_crosses':
|
|
162
|
+
return (0, pg_format_1.default)('ST_Crosses(%I, ', column) + geomSQL + ')';
|
|
163
|
+
case 'postgis_touches':
|
|
164
|
+
return (0, pg_format_1.default)('ST_Touches(%I, ', column) + geomSQL + ')';
|
|
165
|
+
case 'postgis_disjoint':
|
|
166
|
+
return (0, pg_format_1.default)('ST_Disjoint(%I, ', column) + geomSQL + ')';
|
|
167
|
+
case 'postgis_equals':
|
|
168
|
+
return (0, pg_format_1.default)('ST_Equals(%I, ', column) + geomSQL + ')';
|
|
169
|
+
case 'postgis_dwithin': {
|
|
170
|
+
const { distance } = values;
|
|
171
|
+
return (0, pg_format_1.default)('ST_DWithin(%I, ', column) + geomSQL + (0, pg_format_1.default)(', %s)', distance);
|
|
172
|
+
}
|
|
173
|
+
case 'postgis_distance_lt': {
|
|
174
|
+
const { distance } = values;
|
|
175
|
+
return (0, pg_format_1.default)('ST_Distance(%I, ', column) + geomSQL + (0, pg_format_1.default)(') < %s', distance);
|
|
176
|
+
}
|
|
177
|
+
case 'postgis_distance_gt': {
|
|
178
|
+
const { distance } = values;
|
|
179
|
+
return (0, pg_format_1.default)('ST_Distance(%I, ', column) + geomSQL + (0, pg_format_1.default)(') > %s', distance);
|
|
180
|
+
}
|
|
181
|
+
case 'postgis_covered_by':
|
|
182
|
+
return (0, pg_format_1.default)('ST_CoveredBy(%I, ', column) + geomSQL + ')';
|
|
183
|
+
case 'postgis_covers':
|
|
184
|
+
return (0, pg_format_1.default)('ST_Covers(%I, ', column) + geomSQL + ')';
|
|
185
|
+
default:
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
}
|