@relq/orm 0.1.0
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/LICENSE +21 -0
- package/README.md +236 -0
- package/dist/cjs/__test-types.cjs +17 -0
- package/dist/cjs/addon/cursor.cjs +1473 -0
- package/dist/cjs/addon/pg.cjs +4969 -0
- package/dist/cjs/cache/index.cjs +9 -0
- package/dist/cjs/cache/query-cache.cjs +311 -0
- package/dist/cjs/condition/array-condition-builder.cjs +527 -0
- package/dist/cjs/condition/array-numeric-condition-builder.cjs +186 -0
- package/dist/cjs/condition/array-specialized-condition-builder.cjs +206 -0
- package/dist/cjs/condition/array-string-condition-builder.cjs +146 -0
- package/dist/cjs/condition/base-condition-builder.cjs +2 -0
- package/dist/cjs/condition/condition-collector.cjs +461 -0
- package/dist/cjs/condition/fulltext-condition-builder.cjs +61 -0
- package/dist/cjs/condition/geometric-condition-builder.cjs +228 -0
- package/dist/cjs/condition/index.cjs +29 -0
- package/dist/cjs/condition/jsonb-condition-builder.cjs +448 -0
- package/dist/cjs/condition/network-condition-builder.cjs +237 -0
- package/dist/cjs/condition/postgis-condition-builder.cjs +188 -0
- package/dist/cjs/condition/range-condition-builder.cjs +98 -0
- package/dist/cjs/core/helpers/ConnectedAggregateBuilder.cjs +132 -0
- package/dist/cjs/core/helpers/ConnectedCTEBuilder.cjs +53 -0
- package/dist/cjs/core/helpers/ConnectedCountBuilder.cjs +73 -0
- package/dist/cjs/core/helpers/ConnectedDeleteBuilder.cjs +65 -0
- package/dist/cjs/core/helpers/ConnectedInsertBuilder.cjs +112 -0
- package/dist/cjs/core/helpers/ConnectedInsertFromSelectBuilder.cjs +66 -0
- package/dist/cjs/core/helpers/ConnectedQueryBuilder.cjs +146 -0
- package/dist/cjs/core/helpers/ConnectedRawQueryBuilder.cjs +46 -0
- package/dist/cjs/core/helpers/ConnectedSelectBuilder.cjs +331 -0
- package/dist/cjs/core/helpers/ConnectedTransactionBuilder.cjs +105 -0
- package/dist/cjs/core/helpers/ConnectedUpdateBuilder.cjs +79 -0
- package/dist/cjs/core/helpers/PaginateBuilder.cjs +178 -0
- package/dist/cjs/core/helpers/ReturningExecutor.cjs +70 -0
- package/dist/cjs/core/helpers/capability-guard.cjs +10 -0
- package/dist/cjs/core/helpers/index.cjs +31 -0
- package/dist/cjs/core/helpers/methods.cjs +10 -0
- package/dist/cjs/core/helpers/query-convenience.cjs +238 -0
- package/dist/cjs/core/helpers/select-joins.cjs +251 -0
- package/dist/cjs/core/helpers/select-pagination.cjs +233 -0
- package/dist/cjs/core/helpers/select-types.cjs +2 -0
- package/dist/cjs/core/pg-family/cockroachdb-client/capabilities.cjs +31 -0
- package/dist/cjs/core/pg-family/cockroachdb-client/index.cjs +7 -0
- package/dist/cjs/core/pg-family/cockroachdb-client/relq-cockroach.cjs +16 -0
- package/dist/cjs/core/pg-family/dsql-client/capabilities.cjs +31 -0
- package/dist/cjs/core/pg-family/dsql-client/index.cjs +7 -0
- package/dist/cjs/core/pg-family/dsql-client/relq-dsql.cjs +16 -0
- package/dist/cjs/core/pg-family/index.cjs +19 -0
- package/dist/cjs/core/pg-family/nile-client/capabilities.cjs +31 -0
- package/dist/cjs/core/pg-family/nile-client/index.cjs +7 -0
- package/dist/cjs/core/pg-family/nile-client/relq-nile.cjs +36 -0
- package/dist/cjs/core/pg-family/nile-client/tenant-context.cjs +44 -0
- package/dist/cjs/core/pg-family/pg-client/capabilities.cjs +31 -0
- package/dist/cjs/core/pg-family/pg-client/index.cjs +7 -0
- package/dist/cjs/core/pg-family/pg-client/relq-postgres.cjs +43 -0
- package/dist/cjs/core/pg-family/shared/pg-base.cjs +385 -0
- package/dist/cjs/core/pg-family/shared/pg-dialect.cjs +67 -0
- package/dist/cjs/core/pg-family/shared/pg-error-parser.cjs +34 -0
- package/dist/cjs/core/pg-family/shared/pg-type-coercion.cjs +14 -0
- package/dist/cjs/core/relq-base.cjs +307 -0
- package/dist/cjs/core/relq-client.cjs +56 -0
- package/dist/cjs/core/shared/cleanup.cjs +36 -0
- package/dist/cjs/core/shared/column-mapping.cjs +97 -0
- package/dist/cjs/core/shared/errors.cjs +17 -0
- package/dist/cjs/core/shared/index.cjs +24 -0
- package/dist/cjs/core/shared/table-accessor.cjs +22 -0
- package/dist/cjs/core/shared/transform.cjs +35 -0
- package/dist/cjs/core/shared/types.cjs +2 -0
- package/dist/cjs/core/shared/validation.cjs +140 -0
- package/dist/cjs/core/types/core.types.cjs +2 -0
- package/dist/cjs/count/count-builder.cjs +88 -0
- package/dist/cjs/count/index.cjs +5 -0
- package/dist/cjs/delete/delete-builder.cjs +176 -0
- package/dist/cjs/delete/index.cjs +5 -0
- package/dist/cjs/explain/explain-builder.cjs +99 -0
- package/dist/cjs/explain/index.cjs +5 -0
- package/dist/cjs/index.cjs +26 -0
- package/dist/cjs/insert/conflict-builder.cjs +213 -0
- package/dist/cjs/insert/index.cjs +5 -0
- package/dist/cjs/insert/insert-builder.cjs +320 -0
- package/dist/cjs/insert/insert-from-select-builder.cjs +86 -0
- package/dist/cjs/pubsub/index.cjs +7 -0
- package/dist/cjs/pubsub/listen-notify-builder.cjs +57 -0
- package/dist/cjs/pubsub/listener-connection.cjs +180 -0
- package/dist/cjs/raw/index.cjs +8 -0
- package/dist/cjs/raw/raw-query-builder.cjs +27 -0
- package/dist/cjs/raw/sql-template.cjs +73 -0
- package/dist/cjs/select/aggregate-builder.cjs +179 -0
- package/dist/cjs/select/index.cjs +16 -0
- package/dist/cjs/select/join-builder.cjs +192 -0
- package/dist/cjs/select/join-condition-builder.cjs +189 -0
- package/dist/cjs/select/join-internals.cjs +5 -0
- package/dist/cjs/select/join-many-condition-builder.cjs +159 -0
- package/dist/cjs/select/scalar-query-builder.cjs +134 -0
- package/dist/cjs/select/scalar-select-builder.cjs +78 -0
- package/dist/cjs/select/select-builder.cjs +426 -0
- package/dist/cjs/select/sql-expression.cjs +38 -0
- package/dist/cjs/select/table-proxy.cjs +99 -0
- package/dist/cjs/shared/aws-dsql.cjs +181 -0
- package/dist/cjs/shared/errors/relq-errors.cjs +361 -0
- package/dist/cjs/shared/pg-format.cjs +383 -0
- package/dist/cjs/shared/types/config-types.cjs +51 -0
- package/dist/cjs/transaction/index.cjs +6 -0
- package/dist/cjs/transaction/transaction-builder.cjs +78 -0
- package/dist/cjs/types/aggregate-types.cjs +2 -0
- package/dist/cjs/types/inference-types.cjs +18 -0
- package/dist/cjs/types/pagination-types.cjs +7 -0
- package/dist/cjs/types/result-types.cjs +2 -0
- package/dist/cjs/types/scalar-types.cjs +2 -0
- package/dist/cjs/types/schema-types.cjs +2 -0
- package/dist/cjs/types/subscription-types.cjs +2 -0
- package/dist/cjs/types.cjs +2 -0
- package/dist/cjs/update/array-update-builder.cjs +232 -0
- package/dist/cjs/update/index.cjs +16 -0
- package/dist/cjs/update/jsonb-update-builder.cjs +219 -0
- package/dist/cjs/update/update-builder.cjs +274 -0
- package/dist/cjs/utils/addon/pg/cursor.cjs +8 -0
- package/dist/cjs/utils/addon/pg/pg.cjs +23 -0
- package/dist/cjs/utils/case-converter.cjs +58 -0
- package/dist/cjs/utils/env-resolver.cjs +226 -0
- package/dist/cjs/utils/environment-detection.cjs +124 -0
- package/dist/cjs/utils/fk-resolver.cjs +186 -0
- package/dist/cjs/utils/index.cjs +25 -0
- package/dist/cjs/utils/pool-defaults.cjs +91 -0
- package/dist/cjs/utils/type-coercion.cjs +120 -0
- package/dist/cjs/window/index.cjs +5 -0
- package/dist/cjs/window/window-builder.cjs +80 -0
- package/dist/esm/__test-types.js +15 -0
- package/dist/esm/addon/cursor.js +1440 -0
- package/dist/esm/addon/pg.js +4931 -0
- package/dist/esm/cache/index.js +1 -0
- package/dist/esm/cache/query-cache.js +303 -0
- package/dist/esm/condition/array-condition-builder.js +519 -0
- package/dist/esm/condition/array-numeric-condition-builder.js +182 -0
- package/dist/esm/condition/array-specialized-condition-builder.js +200 -0
- package/dist/esm/condition/array-string-condition-builder.js +142 -0
- package/dist/esm/condition/base-condition-builder.js +1 -0
- package/dist/esm/condition/condition-collector.js +452 -0
- package/dist/esm/condition/fulltext-condition-builder.js +53 -0
- package/dist/esm/condition/geometric-condition-builder.js +220 -0
- package/dist/esm/condition/index.js +8 -0
- package/dist/esm/condition/jsonb-condition-builder.js +439 -0
- package/dist/esm/condition/network-condition-builder.js +229 -0
- package/dist/esm/condition/postgis-condition-builder.js +180 -0
- package/dist/esm/condition/range-condition-builder.js +90 -0
- package/dist/esm/core/helpers/ConnectedAggregateBuilder.js +128 -0
- package/dist/esm/core/helpers/ConnectedCTEBuilder.js +49 -0
- package/dist/esm/core/helpers/ConnectedCountBuilder.js +69 -0
- package/dist/esm/core/helpers/ConnectedDeleteBuilder.js +61 -0
- package/dist/esm/core/helpers/ConnectedInsertBuilder.js +108 -0
- package/dist/esm/core/helpers/ConnectedInsertFromSelectBuilder.js +62 -0
- package/dist/esm/core/helpers/ConnectedQueryBuilder.js +142 -0
- package/dist/esm/core/helpers/ConnectedRawQueryBuilder.js +42 -0
- package/dist/esm/core/helpers/ConnectedSelectBuilder.js +327 -0
- package/dist/esm/core/helpers/ConnectedTransactionBuilder.js +100 -0
- package/dist/esm/core/helpers/ConnectedUpdateBuilder.js +75 -0
- package/dist/esm/core/helpers/PaginateBuilder.js +174 -0
- package/dist/esm/core/helpers/ReturningExecutor.js +66 -0
- package/dist/esm/core/helpers/capability-guard.js +7 -0
- package/dist/esm/core/helpers/index.js +13 -0
- package/dist/esm/core/helpers/methods.js +6 -0
- package/dist/esm/core/helpers/query-convenience.js +194 -0
- package/dist/esm/core/helpers/select-joins.js +246 -0
- package/dist/esm/core/helpers/select-pagination.js +226 -0
- package/dist/esm/core/helpers/select-types.js +1 -0
- package/dist/esm/core/pg-family/cockroachdb-client/capabilities.js +28 -0
- package/dist/esm/core/pg-family/cockroachdb-client/index.js +2 -0
- package/dist/esm/core/pg-family/cockroachdb-client/relq-cockroach.js +12 -0
- package/dist/esm/core/pg-family/dsql-client/capabilities.js +28 -0
- package/dist/esm/core/pg-family/dsql-client/index.js +2 -0
- package/dist/esm/core/pg-family/dsql-client/relq-dsql.js +12 -0
- package/dist/esm/core/pg-family/index.js +6 -0
- package/dist/esm/core/pg-family/nile-client/capabilities.js +28 -0
- package/dist/esm/core/pg-family/nile-client/index.js +2 -0
- package/dist/esm/core/pg-family/nile-client/relq-nile.js +32 -0
- package/dist/esm/core/pg-family/nile-client/tenant-context.js +40 -0
- package/dist/esm/core/pg-family/pg-client/capabilities.js +28 -0
- package/dist/esm/core/pg-family/pg-client/index.js +2 -0
- package/dist/esm/core/pg-family/pg-client/relq-postgres.js +39 -0
- package/dist/esm/core/pg-family/shared/pg-base.js +347 -0
- package/dist/esm/core/pg-family/shared/pg-dialect.js +63 -0
- package/dist/esm/core/pg-family/shared/pg-error-parser.js +29 -0
- package/dist/esm/core/pg-family/shared/pg-type-coercion.js +6 -0
- package/dist/esm/core/relq-base.js +270 -0
- package/dist/esm/core/relq-client.js +48 -0
- package/dist/esm/core/shared/cleanup.js +27 -0
- package/dist/esm/core/shared/column-mapping.js +90 -0
- package/dist/esm/core/shared/errors.js +13 -0
- package/dist/esm/core/shared/index.js +6 -0
- package/dist/esm/core/shared/table-accessor.js +19 -0
- package/dist/esm/core/shared/transform.js +30 -0
- package/dist/esm/core/shared/types.js +1 -0
- package/dist/esm/core/shared/validation.js +136 -0
- package/dist/esm/core/types/core.types.js +1 -0
- package/dist/esm/count/count-builder.js +81 -0
- package/dist/esm/count/index.js +1 -0
- package/dist/esm/delete/delete-builder.js +169 -0
- package/dist/esm/delete/index.js +1 -0
- package/dist/esm/explain/explain-builder.js +95 -0
- package/dist/esm/explain/index.js +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/insert/conflict-builder.js +202 -0
- package/dist/esm/insert/index.js +1 -0
- package/dist/esm/insert/insert-builder.js +313 -0
- package/dist/esm/insert/insert-from-select-builder.js +79 -0
- package/dist/esm/pubsub/index.js +1 -0
- package/dist/esm/pubsub/listen-notify-builder.js +48 -0
- package/dist/esm/pubsub/listener-connection.js +173 -0
- package/dist/esm/raw/index.js +2 -0
- package/dist/esm/raw/raw-query-builder.js +20 -0
- package/dist/esm/raw/sql-template.js +66 -0
- package/dist/esm/select/aggregate-builder.js +172 -0
- package/dist/esm/select/index.js +4 -0
- package/dist/esm/select/join-builder.js +184 -0
- package/dist/esm/select/join-condition-builder.js +181 -0
- package/dist/esm/select/join-internals.js +2 -0
- package/dist/esm/select/join-many-condition-builder.js +151 -0
- package/dist/esm/select/scalar-query-builder.js +126 -0
- package/dist/esm/select/scalar-select-builder.js +70 -0
- package/dist/esm/select/select-builder.js +419 -0
- package/dist/esm/select/sql-expression.js +33 -0
- package/dist/esm/select/table-proxy.js +91 -0
- package/dist/esm/shared/aws-dsql.js +140 -0
- package/dist/esm/shared/errors/relq-errors.js +339 -0
- package/dist/esm/shared/pg-format.js +375 -0
- package/dist/esm/shared/types/config-types.js +46 -0
- package/dist/esm/transaction/index.js +1 -0
- package/dist/esm/transaction/transaction-builder.js +70 -0
- package/dist/esm/types/aggregate-types.js +1 -0
- package/dist/esm/types/inference-types.js +12 -0
- package/dist/esm/types/pagination-types.js +4 -0
- package/dist/esm/types/result-types.js +1 -0
- package/dist/esm/types/scalar-types.js +1 -0
- package/dist/esm/types/schema-types.js +1 -0
- package/dist/esm/types/subscription-types.js +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/update/array-update-builder.js +219 -0
- package/dist/esm/update/index.js +3 -0
- package/dist/esm/update/jsonb-update-builder.js +211 -0
- package/dist/esm/update/update-builder.js +267 -0
- package/dist/esm/utils/addon/pg/cursor.js +1 -0
- package/dist/esm/utils/addon/pg/pg.js +2 -0
- package/dist/esm/utils/case-converter.js +55 -0
- package/dist/esm/utils/env-resolver.js +213 -0
- package/dist/esm/utils/environment-detection.js +114 -0
- package/dist/esm/utils/fk-resolver.js +178 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/pool-defaults.js +85 -0
- package/dist/esm/utils/type-coercion.js +112 -0
- package/dist/esm/window/index.js +1 -0
- package/dist/esm/window/window-builder.js +73 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +7281 -0
- package/dist/index.js +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import format from "../shared/pg-format.js";
|
|
2
|
+
import { JsonbConditionCollector, buildJsonbConditionSQL } from "./jsonb-condition-builder.js";
|
|
3
|
+
import { ArrayConditionCollector, buildArrayConditionSQL } from "./array-condition-builder.js";
|
|
4
|
+
import { FulltextConditionCollector, buildFulltextConditionSQL } from "./fulltext-condition-builder.js";
|
|
5
|
+
import { RangeConditionCollector, buildRangeConditionSQL } from "./range-condition-builder.js";
|
|
6
|
+
import { GeometricConditionCollector, buildGeometricConditionSQL } from "./geometric-condition-builder.js";
|
|
7
|
+
import { NetworkConditionCollector, buildNetworkConditionSQL } from "./network-condition-builder.js";
|
|
8
|
+
import { PostgisConditionCollector, buildPostgisConditionSQL } from "./postgis-condition-builder.js";
|
|
9
|
+
export class ConditionCollector {
|
|
10
|
+
conditions = [];
|
|
11
|
+
_tables;
|
|
12
|
+
_jsonb;
|
|
13
|
+
_array;
|
|
14
|
+
_fulltext;
|
|
15
|
+
_range;
|
|
16
|
+
_geometric;
|
|
17
|
+
_network;
|
|
18
|
+
_postgis;
|
|
19
|
+
get jsonb() {
|
|
20
|
+
if (!this._jsonb) {
|
|
21
|
+
this._jsonb = new JsonbConditionCollector(this);
|
|
22
|
+
}
|
|
23
|
+
return this._jsonb;
|
|
24
|
+
}
|
|
25
|
+
get json() {
|
|
26
|
+
return this.jsonb;
|
|
27
|
+
}
|
|
28
|
+
get array() {
|
|
29
|
+
if (!this._array) {
|
|
30
|
+
this._array = new ArrayConditionCollector(this);
|
|
31
|
+
}
|
|
32
|
+
return this._array;
|
|
33
|
+
}
|
|
34
|
+
get fulltext() {
|
|
35
|
+
if (!this._fulltext) {
|
|
36
|
+
this._fulltext = new FulltextConditionCollector(this);
|
|
37
|
+
}
|
|
38
|
+
return this._fulltext;
|
|
39
|
+
}
|
|
40
|
+
get range() {
|
|
41
|
+
if (!this._range) {
|
|
42
|
+
this._range = new RangeConditionCollector(this);
|
|
43
|
+
}
|
|
44
|
+
return this._range;
|
|
45
|
+
}
|
|
46
|
+
get geometric() {
|
|
47
|
+
if (!this._geometric) {
|
|
48
|
+
this._geometric = new GeometricConditionCollector(this);
|
|
49
|
+
}
|
|
50
|
+
return this._geometric;
|
|
51
|
+
}
|
|
52
|
+
get network() {
|
|
53
|
+
if (!this._network) {
|
|
54
|
+
this._network = new NetworkConditionCollector(this);
|
|
55
|
+
}
|
|
56
|
+
return this._network;
|
|
57
|
+
}
|
|
58
|
+
get postgis() {
|
|
59
|
+
if (!this._postgis) {
|
|
60
|
+
this._postgis = new PostgisConditionCollector(this);
|
|
61
|
+
}
|
|
62
|
+
return this._postgis;
|
|
63
|
+
}
|
|
64
|
+
equal(column, value) {
|
|
65
|
+
this.conditions.push({ method: 'equal', column, values: value });
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
notEqual(column, value) {
|
|
69
|
+
this.conditions.push({ method: 'notEqual', column, values: value });
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
lessThan(column, value) {
|
|
73
|
+
this.conditions.push({ method: 'lessThan', column, values: value });
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
lessThanEqual(column, value) {
|
|
77
|
+
this.conditions.push({ method: 'lessThanEqual', column, values: value });
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
greaterThan(column, value) {
|
|
81
|
+
this.conditions.push({ method: 'greaterThan', column, values: value });
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
greaterThanEqual(column, value) {
|
|
85
|
+
this.conditions.push({ method: 'greaterThanEqual', column, values: value });
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
isNull(column) {
|
|
89
|
+
this.conditions.push({ method: 'isNull', column });
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
isNotNull(column) {
|
|
93
|
+
this.conditions.push({ method: 'isNotNull', column });
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
between(column, start, end) {
|
|
97
|
+
this.conditions.push({ method: 'between', column, values: [start, end] });
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
notBetween(column, start, end) {
|
|
101
|
+
this.conditions.push({ method: 'notBetween', column, values: [start, end] });
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
startsWith(column, value, caseInsensitive) {
|
|
105
|
+
this.conditions.push({
|
|
106
|
+
method: caseInsensitive ? 'startsWithI' : 'startsWith',
|
|
107
|
+
column,
|
|
108
|
+
values: value
|
|
109
|
+
});
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
notStartsWith(column, value, caseInsensitive) {
|
|
113
|
+
this.conditions.push({
|
|
114
|
+
method: caseInsensitive ? 'notStartsWithI' : 'notStartsWith',
|
|
115
|
+
column,
|
|
116
|
+
values: value
|
|
117
|
+
});
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
endsWith(column, value, caseInsensitive) {
|
|
121
|
+
this.conditions.push({
|
|
122
|
+
method: caseInsensitive ? 'endsWithI' : 'endsWith',
|
|
123
|
+
column,
|
|
124
|
+
values: value
|
|
125
|
+
});
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
notEndsWith(column, value, caseInsensitive) {
|
|
129
|
+
this.conditions.push({
|
|
130
|
+
method: caseInsensitive ? 'notEndsWithI' : 'notEndsWith',
|
|
131
|
+
column,
|
|
132
|
+
values: value
|
|
133
|
+
});
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
contains(column, value, caseInsensitive) {
|
|
137
|
+
this.conditions.push({
|
|
138
|
+
method: caseInsensitive ? 'containsI' : 'contains',
|
|
139
|
+
column,
|
|
140
|
+
values: value
|
|
141
|
+
});
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
notContains(column, value, caseInsensitive) {
|
|
145
|
+
this.conditions.push({
|
|
146
|
+
method: caseInsensitive ? 'notContainsI' : 'notContains',
|
|
147
|
+
column,
|
|
148
|
+
values: value
|
|
149
|
+
});
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
like(column, pattern) {
|
|
153
|
+
this.conditions.push({ method: 'like', column, values: pattern });
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
notLike(column, pattern) {
|
|
157
|
+
this.conditions.push({ method: 'notLike', column, values: pattern });
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
ilike(column, pattern) {
|
|
161
|
+
this.conditions.push({ method: 'ilike', column, values: pattern });
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
notIlike(column, pattern) {
|
|
165
|
+
this.conditions.push({ method: 'notIlike', column, values: pattern });
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
regex(column, pattern) {
|
|
169
|
+
this.conditions.push({ method: 'regex', column, values: pattern });
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
iregex(column, pattern) {
|
|
173
|
+
this.conditions.push({ method: 'iregex', column, values: pattern });
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
notRegex(column, pattern) {
|
|
177
|
+
this.conditions.push({ method: 'notRegex', column, values: pattern });
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
notIregex(column, pattern) {
|
|
181
|
+
this.conditions.push({ method: 'notIregex', column, values: pattern });
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
similarTo(column, pattern) {
|
|
185
|
+
this.conditions.push({ method: 'similarTo', column, values: pattern });
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
notSimilarTo(column, pattern) {
|
|
189
|
+
this.conditions.push({ method: 'notSimilarTo', column, values: pattern });
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
isTrue(column) {
|
|
193
|
+
this.conditions.push({ method: 'isTrue', column });
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
isFalse(column) {
|
|
197
|
+
this.conditions.push({ method: 'isFalse', column });
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
distinctFrom(column, value) {
|
|
201
|
+
this.conditions.push({ method: 'distinctFrom', column, values: value });
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
notDistinctFrom(column, value) {
|
|
205
|
+
this.conditions.push({ method: 'notDistinctFrom', column, values: value });
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
overlaps(start, end) {
|
|
209
|
+
this.conditions.push({
|
|
210
|
+
method: 'overlaps',
|
|
211
|
+
values: { startColumn: start[0], startValue: start[1], endColumn: end[0], endValue: end[1] }
|
|
212
|
+
});
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
greaterThanOrEqual(column, value) {
|
|
216
|
+
return this.greaterThanEqual(column, value);
|
|
217
|
+
}
|
|
218
|
+
lessThanOrEqual(column, value) {
|
|
219
|
+
return this.lessThanEqual(column, value);
|
|
220
|
+
}
|
|
221
|
+
notNull(column) {
|
|
222
|
+
return this.isNotNull(column);
|
|
223
|
+
}
|
|
224
|
+
in(column, values) {
|
|
225
|
+
if (typeof values === 'function') {
|
|
226
|
+
const subquery = values(this._tables);
|
|
227
|
+
this.conditions.push({ method: 'in', column, values: subquery.toString() });
|
|
228
|
+
}
|
|
229
|
+
else if (!Array.isArray(values) && typeof values === 'object' && values !== null && 'toString' in values) {
|
|
230
|
+
this.conditions.push({ method: 'in', column, values: values.toString() });
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this.conditions.push({ method: 'in', column, values });
|
|
234
|
+
}
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
notIn(column, values) {
|
|
238
|
+
if (typeof values === 'function') {
|
|
239
|
+
const subquery = values(this._tables);
|
|
240
|
+
this.conditions.push({ method: 'notIn', column, values: subquery.toString() });
|
|
241
|
+
}
|
|
242
|
+
else if (!Array.isArray(values) && typeof values === 'object' && values !== null && 'toString' in values) {
|
|
243
|
+
this.conditions.push({ method: 'notIn', column, values: values.toString() });
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this.conditions.push({ method: 'notIn', column, values });
|
|
247
|
+
}
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
exists(subquery) {
|
|
251
|
+
this.conditions.push({ method: 'exists', values: subquery });
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
notExists(subquery) {
|
|
255
|
+
this.conditions.push({ method: 'notExists', values: subquery });
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
search(column, value) {
|
|
259
|
+
this.conditions.push({ method: 'search', column, values: value });
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
262
|
+
notSearch(column, value) {
|
|
263
|
+
this.conditions.push({ method: 'notSearch', column, values: value });
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
or(callback) {
|
|
267
|
+
const subBuilder = new ConditionCollector();
|
|
268
|
+
callback(subBuilder);
|
|
269
|
+
this.conditions.push({ method: 'or', values: subBuilder.getConditions() });
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
and(callback) {
|
|
273
|
+
const subBuilder = new ConditionCollector();
|
|
274
|
+
callback(subBuilder);
|
|
275
|
+
this.conditions.push({ method: 'and', values: subBuilder.getConditions() });
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
not(callback) {
|
|
279
|
+
const subBuilder = new ConditionCollector();
|
|
280
|
+
callback(subBuilder);
|
|
281
|
+
this.conditions.push({ method: 'not', values: subBuilder.getConditions() });
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
getConditions() {
|
|
285
|
+
return this.conditions;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function formatColumn(column) {
|
|
289
|
+
if (column.includes('.')) {
|
|
290
|
+
const parts = column.split('.');
|
|
291
|
+
return parts.map(p => format.ident(p)).join('.');
|
|
292
|
+
}
|
|
293
|
+
return format.ident(column);
|
|
294
|
+
}
|
|
295
|
+
export function buildConditionSQL(condition) {
|
|
296
|
+
const { method, column, values } = condition;
|
|
297
|
+
if (method.startsWith('jsonb_')) {
|
|
298
|
+
return buildJsonbConditionSQL(condition);
|
|
299
|
+
}
|
|
300
|
+
if (method.startsWith('array_')) {
|
|
301
|
+
return buildArrayConditionSQL(condition);
|
|
302
|
+
}
|
|
303
|
+
if (method.startsWith('fulltext_')) {
|
|
304
|
+
return buildFulltextConditionSQL(condition);
|
|
305
|
+
}
|
|
306
|
+
if (method.startsWith('range_')) {
|
|
307
|
+
return buildRangeConditionSQL(condition);
|
|
308
|
+
}
|
|
309
|
+
if (method.startsWith('geometric_')) {
|
|
310
|
+
return buildGeometricConditionSQL(condition);
|
|
311
|
+
}
|
|
312
|
+
if (method.startsWith('network_')) {
|
|
313
|
+
return buildNetworkConditionSQL(condition);
|
|
314
|
+
}
|
|
315
|
+
if (method.startsWith('postgis_')) {
|
|
316
|
+
return buildPostgisConditionSQL(condition);
|
|
317
|
+
}
|
|
318
|
+
const col = column ? formatColumn(column) : '';
|
|
319
|
+
switch (method) {
|
|
320
|
+
case 'equal':
|
|
321
|
+
if (Array.isArray(values) && values.length > 1) {
|
|
322
|
+
return `${col} IN ${format('%L', values)}`;
|
|
323
|
+
}
|
|
324
|
+
return `${col} = ${format('%L', Array.isArray(values) ? values[0] : values)}`;
|
|
325
|
+
case 'notEqual':
|
|
326
|
+
if (Array.isArray(values) && values.length > 1) {
|
|
327
|
+
return `${col} NOT IN ${format('%L', values)}`;
|
|
328
|
+
}
|
|
329
|
+
return `${col} != ${format('%L', Array.isArray(values) ? values[0] : values)}`;
|
|
330
|
+
case 'lessThan':
|
|
331
|
+
return `${col} < ${format('%L', Array.isArray(values) ? values[0] : values)}`;
|
|
332
|
+
case 'lessThanEqual':
|
|
333
|
+
return `${col} <= ${format('%L', Array.isArray(values) ? values[0] : values)}`;
|
|
334
|
+
case 'greaterThan':
|
|
335
|
+
return `${col} > ${format('%L', Array.isArray(values) ? values[0] : values)}`;
|
|
336
|
+
case 'greaterThanEqual':
|
|
337
|
+
return `${col} >= ${format('%L', Array.isArray(values) ? values[0] : values)}`;
|
|
338
|
+
case 'isNull':
|
|
339
|
+
return `${col} IS NULL`;
|
|
340
|
+
case 'isNotNull':
|
|
341
|
+
return `${col} IS NOT NULL`;
|
|
342
|
+
case 'between': {
|
|
343
|
+
const [start, end] = values;
|
|
344
|
+
return `${col} BETWEEN ${format('%L', start)} AND ${format('%L', end)}`;
|
|
345
|
+
}
|
|
346
|
+
case 'notBetween': {
|
|
347
|
+
const [notStart, notEnd] = values;
|
|
348
|
+
return `${col} NOT BETWEEN ${format('%L', notStart)} AND ${format('%L', notEnd)}`;
|
|
349
|
+
}
|
|
350
|
+
case 'startsWith':
|
|
351
|
+
return `${col} LIKE ${format('%L', `${values}%`)}`;
|
|
352
|
+
case 'startsWithI':
|
|
353
|
+
return `${col} ILIKE ${format('%L', `${values}%`)}`;
|
|
354
|
+
case 'notStartsWith':
|
|
355
|
+
return `${col} NOT LIKE ${format('%L', `${values}%`)}`;
|
|
356
|
+
case 'notStartsWithI':
|
|
357
|
+
return `${col} NOT ILIKE ${format('%L', `${values}%`)}`;
|
|
358
|
+
case 'endsWith':
|
|
359
|
+
return `${col} LIKE ${format('%L', `%${values}`)}`;
|
|
360
|
+
case 'endsWithI':
|
|
361
|
+
return `${col} ILIKE ${format('%L', `%${values}`)}`;
|
|
362
|
+
case 'notEndsWith':
|
|
363
|
+
return `${col} NOT LIKE ${format('%L', `%${values}`)}`;
|
|
364
|
+
case 'notEndsWithI':
|
|
365
|
+
return `${col} NOT ILIKE ${format('%L', `%${values}`)}`;
|
|
366
|
+
case 'contains':
|
|
367
|
+
return `${col} LIKE ${format('%L', `%${values}%`)}`;
|
|
368
|
+
case 'containsI':
|
|
369
|
+
return `${col} ILIKE ${format('%L', `%${values}%`)}`;
|
|
370
|
+
case 'notContains':
|
|
371
|
+
return `${col} NOT LIKE ${format('%L', `%${values}%`)}`;
|
|
372
|
+
case 'notContainsI':
|
|
373
|
+
return `${col} NOT ILIKE ${format('%L', `%${values}%`)}`;
|
|
374
|
+
case 'like':
|
|
375
|
+
return `${col} LIKE ${format('%L', values)}`;
|
|
376
|
+
case 'notLike':
|
|
377
|
+
return `${col} NOT LIKE ${format('%L', values)}`;
|
|
378
|
+
case 'ilike':
|
|
379
|
+
return `${col} ILIKE ${format('%L', values)}`;
|
|
380
|
+
case 'notIlike':
|
|
381
|
+
return `${col} NOT ILIKE ${format('%L', values)}`;
|
|
382
|
+
case 'regex':
|
|
383
|
+
return `${col} ~ ${format('%L', values)}`;
|
|
384
|
+
case 'iregex':
|
|
385
|
+
return `${col} ~* ${format('%L', values)}`;
|
|
386
|
+
case 'notRegex':
|
|
387
|
+
return `${col} !~ ${format('%L', values)}`;
|
|
388
|
+
case 'notIregex':
|
|
389
|
+
return `${col} !~* ${format('%L', values)}`;
|
|
390
|
+
case 'similarTo':
|
|
391
|
+
return `${col} SIMILAR TO ${format('%L', values)}`;
|
|
392
|
+
case 'notSimilarTo':
|
|
393
|
+
return `${col} NOT SIMILAR TO ${format('%L', values)}`;
|
|
394
|
+
case 'isTrue':
|
|
395
|
+
return `${col} IS TRUE`;
|
|
396
|
+
case 'isFalse':
|
|
397
|
+
return `${col} IS FALSE`;
|
|
398
|
+
case 'distinctFrom':
|
|
399
|
+
return `${col} IS DISTINCT FROM ${format('%L', values)}`;
|
|
400
|
+
case 'notDistinctFrom':
|
|
401
|
+
return `${col} IS NOT DISTINCT FROM ${format('%L', values)}`;
|
|
402
|
+
case 'overlaps': {
|
|
403
|
+
const { startColumn, startValue, endColumn, endValue } = values;
|
|
404
|
+
const startCol = formatColumn(startColumn);
|
|
405
|
+
const endCol = formatColumn(endColumn);
|
|
406
|
+
const startVal = startValue instanceof Date ? startValue.toISOString() : startValue;
|
|
407
|
+
const endVal = endValue instanceof Date ? endValue.toISOString() : endValue;
|
|
408
|
+
return `(${startCol}, ${endCol}) OVERLAPS (${format('%L', startVal)}, ${format('%L', endVal)})`;
|
|
409
|
+
}
|
|
410
|
+
case 'in': {
|
|
411
|
+
if (typeof values === 'string') {
|
|
412
|
+
return `${col} IN (${values})`;
|
|
413
|
+
}
|
|
414
|
+
const valueList = Array.isArray(values) ? values : [values];
|
|
415
|
+
const formattedValues = valueList.map(v => format('%L', v)).join(', ');
|
|
416
|
+
return `${col} IN (${formattedValues})`;
|
|
417
|
+
}
|
|
418
|
+
case 'notIn': {
|
|
419
|
+
if (typeof values === 'string') {
|
|
420
|
+
return `${col} NOT IN (${values})`;
|
|
421
|
+
}
|
|
422
|
+
const valueList = Array.isArray(values) ? values : [values];
|
|
423
|
+
const formattedValues = valueList.map(v => format('%L', v)).join(', ');
|
|
424
|
+
return `${col} NOT IN (${formattedValues})`;
|
|
425
|
+
}
|
|
426
|
+
case 'exists':
|
|
427
|
+
return `EXISTS (${values})`;
|
|
428
|
+
case 'notExists':
|
|
429
|
+
return `NOT EXISTS (${values})`;
|
|
430
|
+
case 'search':
|
|
431
|
+
return `to_tsvector(${col}) @@ plainto_tsquery(${format('%L', values)})`;
|
|
432
|
+
case 'notSearch':
|
|
433
|
+
return `NOT (to_tsvector(${col}) @@ plainto_tsquery(${format('%L', values)}))`;
|
|
434
|
+
case 'or': {
|
|
435
|
+
const orConditions = values;
|
|
436
|
+
return `(${orConditions.map(c => buildConditionSQL(c)).join(' OR ')})`;
|
|
437
|
+
}
|
|
438
|
+
case 'and': {
|
|
439
|
+
const andConditions = values;
|
|
440
|
+
return `(${andConditions.map(c => buildConditionSQL(c)).join(' AND ')})`;
|
|
441
|
+
}
|
|
442
|
+
case 'not': {
|
|
443
|
+
const notConditions = values;
|
|
444
|
+
return `NOT (${notConditions.map(c => buildConditionSQL(c)).join(' AND ')})`;
|
|
445
|
+
}
|
|
446
|
+
default:
|
|
447
|
+
return '';
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
export function buildConditionsSQL(conditions) {
|
|
451
|
+
return conditions.map(condition => buildConditionSQL(condition)).join(' AND ');
|
|
452
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import format from "../shared/pg-format.js";
|
|
2
|
+
export class FulltextConditionCollector {
|
|
3
|
+
parent;
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
this.parent = parent;
|
|
6
|
+
}
|
|
7
|
+
search(column, query, config = 'english') {
|
|
8
|
+
this.parent.conditions.push({
|
|
9
|
+
method: 'fulltext_search',
|
|
10
|
+
column,
|
|
11
|
+
values: { query, config }
|
|
12
|
+
});
|
|
13
|
+
return this.parent;
|
|
14
|
+
}
|
|
15
|
+
match(column, query, config = 'english') {
|
|
16
|
+
return this.search(column, query, config);
|
|
17
|
+
}
|
|
18
|
+
rank(column, query, minRank = 0, config = 'english') {
|
|
19
|
+
this.parent.conditions.push({
|
|
20
|
+
method: 'fulltext_rank',
|
|
21
|
+
column,
|
|
22
|
+
values: { query, minRank, config }
|
|
23
|
+
});
|
|
24
|
+
return this.parent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function buildFulltextConditionSQL(condition) {
|
|
28
|
+
const { method, column, values } = condition;
|
|
29
|
+
switch (method) {
|
|
30
|
+
case 'fulltext_search': {
|
|
31
|
+
const { query, config } = values;
|
|
32
|
+
const isTsVector = column?.endsWith('_vector') || column?.endsWith('_tsvector');
|
|
33
|
+
if (isTsVector) {
|
|
34
|
+
return format('%I @@ plainto_tsquery(%L, %L)', column, config, query);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return format('to_tsvector(%L, %I) @@ plainto_tsquery(%L, %L)', config, column, config, query);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
case 'fulltext_rank': {
|
|
41
|
+
const { query, minRank, config } = values;
|
|
42
|
+
const isTsVector = column?.endsWith('_vector') || column?.endsWith('_tsvector');
|
|
43
|
+
if (isTsVector) {
|
|
44
|
+
return format('ts_rank(%I, plainto_tsquery(%L, %L)) > %L', column, config, query, minRank);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return format('ts_rank(to_tsvector(%L, %I), plainto_tsquery(%L, %L)) > %L', config, column, config, query, minRank);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
}
|