relq 1.0.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 +862 -0
- package/dist/addons/buffer.js +1869 -0
- package/dist/addons/pg-cursor.js +1425 -0
- package/dist/addons/pg-format.js +2248 -0
- package/dist/addons/pg.js +4790 -0
- package/dist/bin/relq.js +2 -0
- package/dist/cjs/cache/index.cjs +9 -0
- package/dist/cjs/cache/query-cache.cjs +311 -0
- package/dist/cjs/cli/commands/add.cjs +82 -0
- package/dist/cjs/cli/commands/commit.cjs +145 -0
- package/dist/cjs/cli/commands/diff.cjs +84 -0
- package/dist/cjs/cli/commands/export.cjs +333 -0
- package/dist/cjs/cli/commands/fetch.cjs +59 -0
- package/dist/cjs/cli/commands/generate.cjs +242 -0
- package/dist/cjs/cli/commands/history.cjs +165 -0
- package/dist/cjs/cli/commands/import.cjs +524 -0
- package/dist/cjs/cli/commands/init.cjs +437 -0
- package/dist/cjs/cli/commands/introspect.cjs +142 -0
- package/dist/cjs/cli/commands/log.cjs +62 -0
- package/dist/cjs/cli/commands/migrate.cjs +167 -0
- package/dist/cjs/cli/commands/pull.cjs +410 -0
- package/dist/cjs/cli/commands/push.cjs +165 -0
- package/dist/cjs/cli/commands/rollback.cjs +169 -0
- package/dist/cjs/cli/commands/status.cjs +110 -0
- package/dist/cjs/cli/commands/sync.cjs +79 -0
- package/dist/cjs/cli/index.cjs +275 -0
- package/dist/cjs/cli/utils/change-tracker.cjs +446 -0
- package/dist/cjs/cli/utils/commit-manager.cjs +239 -0
- package/dist/cjs/cli/utils/config-loader.cjs +127 -0
- package/dist/cjs/cli/utils/env-loader.cjs +62 -0
- package/dist/cjs/cli/utils/fast-introspect.cjs +398 -0
- package/dist/cjs/cli/utils/git-utils.cjs +404 -0
- package/dist/cjs/cli/utils/migration-generator.cjs +269 -0
- package/dist/cjs/cli/utils/relqignore.cjs +114 -0
- package/dist/cjs/cli/utils/repo-manager.cjs +515 -0
- package/dist/cjs/cli/utils/schema-comparator.cjs +313 -0
- package/dist/cjs/cli/utils/schema-diff.cjs +284 -0
- package/dist/cjs/cli/utils/schema-hash.cjs +108 -0
- package/dist/cjs/cli/utils/schema-introspect.cjs +455 -0
- package/dist/cjs/cli/utils/snapshot-manager.cjs +223 -0
- package/dist/cjs/cli/utils/spinner.cjs +108 -0
- package/dist/cjs/cli/utils/sql-generator.cjs +520 -0
- package/dist/cjs/cli/utils/sql-parser.cjs +999 -0
- package/dist/cjs/cli/utils/type-generator.cjs +2061 -0
- package/dist/cjs/condition/array-condition-builder.cjs +503 -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 +284 -0
- package/dist/cjs/condition/fulltext-condition-builder.cjs +61 -0
- package/dist/cjs/condition/geometric-condition-builder.cjs +208 -0
- package/dist/cjs/condition/index.cjs +25 -0
- package/dist/cjs/condition/jsonb-condition-builder.cjs +160 -0
- package/dist/cjs/condition/network-condition-builder.cjs +230 -0
- package/dist/cjs/condition/range-condition-builder.cjs +82 -0
- package/dist/cjs/config/config.cjs +190 -0
- package/dist/cjs/config/index.cjs +9 -0
- package/dist/cjs/constants/pg-values.cjs +68 -0
- package/dist/cjs/copy/copy-builder.cjs +316 -0
- package/dist/cjs/copy/index.cjs +6 -0
- package/dist/cjs/core/query-builder.cjs +440 -0
- package/dist/cjs/core/relq-client.cjs +1831 -0
- package/dist/cjs/core/typed-kuery-client.cjs +2 -0
- package/dist/cjs/count/count-builder.cjs +88 -0
- package/dist/cjs/count/index.cjs +5 -0
- package/dist/cjs/cte/cte-builder.cjs +89 -0
- package/dist/cjs/cte/index.cjs +5 -0
- package/dist/cjs/ddl/function.cjs +48 -0
- package/dist/cjs/ddl/index.cjs +7 -0
- package/dist/cjs/ddl/sql.cjs +54 -0
- package/dist/cjs/delete/delete-builder.cjs +135 -0
- package/dist/cjs/delete/index.cjs +5 -0
- package/dist/cjs/errors/relq-errors.cjs +329 -0
- package/dist/cjs/examples/fulltext-search-test.cjs +122 -0
- package/dist/cjs/explain/explain-builder.cjs +99 -0
- package/dist/cjs/explain/index.cjs +5 -0
- package/dist/cjs/function/create-function-builder.cjs +196 -0
- package/dist/cjs/function/index.cjs +6 -0
- package/dist/cjs/functions/advanced-functions.cjs +241 -0
- package/dist/cjs/functions/case-builder.cjs +66 -0
- package/dist/cjs/functions/geometric-functions.cjs +104 -0
- package/dist/cjs/functions/index.cjs +184 -0
- package/dist/cjs/functions/network-functions.cjs +86 -0
- package/dist/cjs/functions/sql-functions.cjs +431 -0
- package/dist/cjs/index.cjs +164 -0
- package/dist/cjs/indexing/create-index-builder.cjs +187 -0
- package/dist/cjs/indexing/drop-index-builder.cjs +89 -0
- package/dist/cjs/indexing/index-types.cjs +2 -0
- package/dist/cjs/indexing/index.cjs +8 -0
- package/dist/cjs/insert/conflict-builder.cjs +173 -0
- package/dist/cjs/insert/index.cjs +5 -0
- package/dist/cjs/insert/insert-builder.cjs +254 -0
- package/dist/cjs/introspect/index.cjs +229 -0
- package/dist/cjs/maintenance/index.cjs +6 -0
- package/dist/cjs/maintenance/vacuum-builder.cjs +166 -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 +5 -0
- package/dist/cjs/raw/raw-query-builder.cjs +27 -0
- package/dist/cjs/schema/index.cjs +15 -0
- package/dist/cjs/schema/schema-builder.cjs +1167 -0
- package/dist/cjs/schema-builder.cjs +21 -0
- package/dist/cjs/schema-definition/column-types.cjs +829 -0
- package/dist/cjs/schema-definition/index.cjs +62 -0
- package/dist/cjs/schema-definition/introspection.cjs +620 -0
- package/dist/cjs/schema-definition/partitions.cjs +129 -0
- package/dist/cjs/schema-definition/pg-enum.cjs +76 -0
- package/dist/cjs/schema-definition/pg-function.cjs +91 -0
- package/dist/cjs/schema-definition/pg-sequence.cjs +56 -0
- package/dist/cjs/schema-definition/pg-trigger.cjs +108 -0
- package/dist/cjs/schema-definition/relations.cjs +98 -0
- package/dist/cjs/schema-definition/sql-expressions.cjs +202 -0
- package/dist/cjs/schema-definition/table-definition.cjs +636 -0
- package/dist/cjs/select/aggregate-builder.cjs +179 -0
- package/dist/cjs/select/index.cjs +5 -0
- package/dist/cjs/select/select-builder.cjs +233 -0
- package/dist/cjs/sequence/index.cjs +7 -0
- package/dist/cjs/sequence/sequence-builder.cjs +264 -0
- package/dist/cjs/table/alter-table-builder.cjs +146 -0
- package/dist/cjs/table/constraint-builder.cjs +102 -0
- package/dist/cjs/table/create-table-builder.cjs +248 -0
- package/dist/cjs/table/index.cjs +17 -0
- package/dist/cjs/table/partition-builder.cjs +131 -0
- package/dist/cjs/table/truncate-builder.cjs +70 -0
- package/dist/cjs/transaction/index.cjs +6 -0
- package/dist/cjs/transaction/transaction-builder.cjs +78 -0
- package/dist/cjs/trigger/create-trigger-builder.cjs +174 -0
- package/dist/cjs/trigger/index.cjs +6 -0
- package/dist/cjs/types/aggregate-types.cjs +2 -0
- package/dist/cjs/types/config-types.cjs +40 -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/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 +205 -0
- package/dist/cjs/update/index.cjs +13 -0
- package/dist/cjs/update/update-builder.cjs +195 -0
- package/dist/cjs/utils/case-converter.cjs +58 -0
- package/dist/cjs/utils/environment-detection.cjs +120 -0
- package/dist/cjs/utils/index.cjs +10 -0
- package/dist/cjs/utils/pool-defaults.cjs +106 -0
- package/dist/cjs/utils/type-coercion.cjs +118 -0
- package/dist/cjs/view/create-view-builder.cjs +180 -0
- package/dist/cjs/view/index.cjs +7 -0
- package/dist/cjs/window/index.cjs +5 -0
- package/dist/cjs/window/window-builder.cjs +80 -0
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +655 -0
- package/dist/config.js +1 -0
- package/dist/esm/cache/index.js +1 -0
- package/dist/esm/cache/query-cache.js +303 -0
- package/dist/esm/cli/commands/add.js +78 -0
- package/dist/esm/cli/commands/commit.js +109 -0
- package/dist/esm/cli/commands/diff.js +81 -0
- package/dist/esm/cli/commands/export.js +297 -0
- package/dist/esm/cli/commands/fetch.js +56 -0
- package/dist/esm/cli/commands/generate.js +206 -0
- package/dist/esm/cli/commands/history.js +129 -0
- package/dist/esm/cli/commands/import.js +488 -0
- package/dist/esm/cli/commands/init.js +401 -0
- package/dist/esm/cli/commands/introspect.js +106 -0
- package/dist/esm/cli/commands/log.js +59 -0
- package/dist/esm/cli/commands/migrate.js +131 -0
- package/dist/esm/cli/commands/pull.js +374 -0
- package/dist/esm/cli/commands/push.js +129 -0
- package/dist/esm/cli/commands/rollback.js +133 -0
- package/dist/esm/cli/commands/status.js +107 -0
- package/dist/esm/cli/commands/sync.js +76 -0
- package/dist/esm/cli/index.js +240 -0
- package/dist/esm/cli/utils/change-tracker.js +405 -0
- package/dist/esm/cli/utils/commit-manager.js +191 -0
- package/dist/esm/cli/utils/config-loader.js +86 -0
- package/dist/esm/cli/utils/env-loader.js +57 -0
- package/dist/esm/cli/utils/fast-introspect.js +362 -0
- package/dist/esm/cli/utils/git-utils.js +347 -0
- package/dist/esm/cli/utils/migration-generator.js +263 -0
- package/dist/esm/cli/utils/relqignore.js +74 -0
- package/dist/esm/cli/utils/repo-manager.js +444 -0
- package/dist/esm/cli/utils/schema-comparator.js +307 -0
- package/dist/esm/cli/utils/schema-diff.js +276 -0
- package/dist/esm/cli/utils/schema-hash.js +69 -0
- package/dist/esm/cli/utils/schema-introspect.js +418 -0
- package/dist/esm/cli/utils/snapshot-manager.js +179 -0
- package/dist/esm/cli/utils/spinner.js +101 -0
- package/dist/esm/cli/utils/sql-generator.js +504 -0
- package/dist/esm/cli/utils/sql-parser.js +992 -0
- package/dist/esm/cli/utils/type-generator.js +2058 -0
- package/dist/esm/condition/array-condition-builder.js +495 -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 +275 -0
- package/dist/esm/condition/fulltext-condition-builder.js +53 -0
- package/dist/esm/condition/geometric-condition-builder.js +200 -0
- package/dist/esm/condition/index.js +7 -0
- package/dist/esm/condition/jsonb-condition-builder.js +152 -0
- package/dist/esm/condition/network-condition-builder.js +222 -0
- package/dist/esm/condition/range-condition-builder.js +74 -0
- package/dist/esm/config/config.js +150 -0
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/constants/pg-values.js +63 -0
- package/dist/esm/copy/copy-builder.js +308 -0
- package/dist/esm/copy/index.js +1 -0
- package/dist/esm/core/query-builder.js +426 -0
- package/dist/esm/core/relq-client.js +1791 -0
- package/dist/esm/core/typed-kuery-client.js +1 -0
- package/dist/esm/count/count-builder.js +81 -0
- package/dist/esm/count/index.js +1 -0
- package/dist/esm/cte/cte-builder.js +82 -0
- package/dist/esm/cte/index.js +1 -0
- package/dist/esm/ddl/function.js +45 -0
- package/dist/esm/ddl/index.js +2 -0
- package/dist/esm/ddl/sql.js +51 -0
- package/dist/esm/delete/delete-builder.js +128 -0
- package/dist/esm/delete/index.js +1 -0
- package/dist/esm/errors/relq-errors.js +310 -0
- package/dist/esm/examples/fulltext-search-test.js +117 -0
- package/dist/esm/explain/explain-builder.js +95 -0
- package/dist/esm/explain/index.js +1 -0
- package/dist/esm/function/create-function-builder.js +188 -0
- package/dist/esm/function/index.js +1 -0
- package/dist/esm/functions/advanced-functions.js +231 -0
- package/dist/esm/functions/case-builder.js +58 -0
- package/dist/esm/functions/geometric-functions.js +97 -0
- package/dist/esm/functions/index.js +171 -0
- package/dist/esm/functions/network-functions.js +79 -0
- package/dist/esm/functions/sql-functions.js +421 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/indexing/create-index-builder.js +180 -0
- package/dist/esm/indexing/drop-index-builder.js +81 -0
- package/dist/esm/indexing/index-types.js +1 -0
- package/dist/esm/indexing/index.js +2 -0
- package/dist/esm/insert/conflict-builder.js +162 -0
- package/dist/esm/insert/index.js +1 -0
- package/dist/esm/insert/insert-builder.js +247 -0
- package/dist/esm/introspect/index.js +224 -0
- package/dist/esm/maintenance/index.js +1 -0
- package/dist/esm/maintenance/vacuum-builder.js +158 -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 +1 -0
- package/dist/esm/raw/raw-query-builder.js +20 -0
- package/dist/esm/schema/index.js +1 -0
- package/dist/esm/schema/schema-builder.js +1150 -0
- package/dist/esm/schema-builder.js +2 -0
- package/dist/esm/schema-definition/column-types.js +738 -0
- package/dist/esm/schema-definition/index.js +10 -0
- package/dist/esm/schema-definition/introspection.js +614 -0
- package/dist/esm/schema-definition/partitions.js +123 -0
- package/dist/esm/schema-definition/pg-enum.js +70 -0
- package/dist/esm/schema-definition/pg-function.js +85 -0
- package/dist/esm/schema-definition/pg-sequence.js +50 -0
- package/dist/esm/schema-definition/pg-trigger.js +102 -0
- package/dist/esm/schema-definition/relations.js +90 -0
- package/dist/esm/schema-definition/sql-expressions.js +193 -0
- package/dist/esm/schema-definition/table-definition.js +630 -0
- package/dist/esm/select/aggregate-builder.js +172 -0
- package/dist/esm/select/index.js +1 -0
- package/dist/esm/select/select-builder.js +226 -0
- package/dist/esm/sequence/index.js +1 -0
- package/dist/esm/sequence/sequence-builder.js +255 -0
- package/dist/esm/table/alter-table-builder.js +138 -0
- package/dist/esm/table/constraint-builder.js +95 -0
- package/dist/esm/table/create-table-builder.js +241 -0
- package/dist/esm/table/index.js +5 -0
- package/dist/esm/table/partition-builder.js +121 -0
- package/dist/esm/table/truncate-builder.js +63 -0
- package/dist/esm/transaction/index.js +1 -0
- package/dist/esm/transaction/transaction-builder.js +70 -0
- package/dist/esm/trigger/create-trigger-builder.js +166 -0
- package/dist/esm/trigger/index.js +1 -0
- package/dist/esm/types/aggregate-types.js +1 -0
- package/dist/esm/types/config-types.js +36 -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/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 +192 -0
- package/dist/esm/update/index.js +2 -0
- package/dist/esm/update/update-builder.js +188 -0
- package/dist/esm/utils/case-converter.js +55 -0
- package/dist/esm/utils/environment-detection.js +113 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/pool-defaults.js +100 -0
- package/dist/esm/utils/type-coercion.js +110 -0
- package/dist/esm/view/create-view-builder.js +171 -0
- package/dist/esm/view/index.js +1 -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 +10341 -0
- package/dist/index.js +1 -0
- package/dist/schema-builder.cjs +1 -0
- package/dist/schema-builder.d.ts +2272 -0
- package/dist/schema-builder.js +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,196 @@
|
|
|
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.DropFunctionBuilder = exports.CreateFunctionBuilder = void 0;
|
|
7
|
+
const pg_format_1 = __importDefault(require("../../addons/pg-format.js"));
|
|
8
|
+
const relq_errors_1 = require("../errors/relq-errors.cjs");
|
|
9
|
+
class CreateFunctionBuilder {
|
|
10
|
+
functionName;
|
|
11
|
+
__parameters = [];
|
|
12
|
+
returnType;
|
|
13
|
+
__returnsTable;
|
|
14
|
+
__returnsSetOf;
|
|
15
|
+
__language = 'plpgsql';
|
|
16
|
+
functionBody;
|
|
17
|
+
volatility = 'VOLATILE';
|
|
18
|
+
security = 'INVOKER';
|
|
19
|
+
__parallel = 'UNSAFE';
|
|
20
|
+
costValue;
|
|
21
|
+
rowsValue;
|
|
22
|
+
strictFlag = false;
|
|
23
|
+
leakproofFlag = false;
|
|
24
|
+
orReplaceFlag = false;
|
|
25
|
+
constructor(functionName) {
|
|
26
|
+
this.functionName = functionName;
|
|
27
|
+
}
|
|
28
|
+
parameter(name, type, defaultValue, mode = 'IN') {
|
|
29
|
+
this.__parameters.push({ name, type, default: defaultValue, mode });
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
parameters(params) {
|
|
33
|
+
Object.entries(params).forEach(([name, type]) => {
|
|
34
|
+
this.__parameters.push({ name, type });
|
|
35
|
+
});
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
returns(type) {
|
|
39
|
+
this.returnType = type;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
returnsTable(columns) {
|
|
43
|
+
this.__returnsTable = columns;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
returnsSetOf(type) {
|
|
47
|
+
this.__returnsSetOf = type;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
language(lang) {
|
|
51
|
+
this.__language = lang;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
body(sql) {
|
|
55
|
+
this.functionBody = sql.trim();
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
immutable() {
|
|
59
|
+
this.volatility = 'IMMUTABLE';
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
stable() {
|
|
63
|
+
this.volatility = 'STABLE';
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
volatile() {
|
|
67
|
+
this.volatility = 'VOLATILE';
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
securityDefiner() {
|
|
71
|
+
this.security = 'DEFINER';
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
securityInvoker() {
|
|
75
|
+
this.security = 'INVOKER';
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
parallel(safety) {
|
|
79
|
+
this.__parallel = safety;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
strict() {
|
|
83
|
+
this.strictFlag = true;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
leakproof() {
|
|
87
|
+
this.leakproofFlag = true;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
cost(estimatedCost) {
|
|
91
|
+
this.costValue = estimatedCost;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
rows(estimatedRows) {
|
|
95
|
+
this.rowsValue = estimatedRows;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
orReplace() {
|
|
99
|
+
this.orReplaceFlag = true;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
toString() {
|
|
103
|
+
if (!this.returnType && !this.__returnsTable && !this.__returnsSetOf) {
|
|
104
|
+
throw new relq_errors_1.RelqBuilderError('Return type is required', { builder: 'CreateFunctionBuilder', missing: 'returnType', hint: 'Use .returns(), .returnsTable(), or .returnsSetOf()' });
|
|
105
|
+
}
|
|
106
|
+
if (!this.functionBody) {
|
|
107
|
+
throw new relq_errors_1.RelqBuilderError('Function body is required', { builder: 'CreateFunctionBuilder', missing: 'body', hint: 'Use .body()' });
|
|
108
|
+
}
|
|
109
|
+
let sql = 'CREATE';
|
|
110
|
+
if (this.orReplaceFlag) {
|
|
111
|
+
sql += ' OR REPLACE';
|
|
112
|
+
}
|
|
113
|
+
sql += ` FUNCTION ${pg_format_1.default.ident(this.functionName)}`;
|
|
114
|
+
if (this.__parameters.length > 0) {
|
|
115
|
+
const params = this.__parameters.map(p => {
|
|
116
|
+
let paramSQL = '';
|
|
117
|
+
if (p.mode && p.mode !== 'IN') {
|
|
118
|
+
paramSQL += `${p.mode} `;
|
|
119
|
+
}
|
|
120
|
+
paramSQL += `${pg_format_1.default.ident(p.name)} ${p.type}`;
|
|
121
|
+
if (p.default !== undefined) {
|
|
122
|
+
paramSQL += ` DEFAULT ${(0, pg_format_1.default)('%L', p.default)}`;
|
|
123
|
+
}
|
|
124
|
+
return paramSQL;
|
|
125
|
+
});
|
|
126
|
+
sql += `(${params.join(', ')})`;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
sql += '()';
|
|
130
|
+
}
|
|
131
|
+
if (this.__returnsTable) {
|
|
132
|
+
const tableCols = Object.entries(this.__returnsTable)
|
|
133
|
+
.map(([name, type]) => `${pg_format_1.default.ident(name)} ${type}`)
|
|
134
|
+
.join(', ');
|
|
135
|
+
sql += ` RETURNS TABLE(${tableCols})`;
|
|
136
|
+
}
|
|
137
|
+
else if (this.__returnsSetOf) {
|
|
138
|
+
sql += ` RETURNS SETOF ${this.__returnsSetOf}`;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
sql += ` RETURNS ${this.returnType}`;
|
|
142
|
+
}
|
|
143
|
+
sql += ` LANGUAGE ${this.language}`;
|
|
144
|
+
sql += ` ${this.volatility}`;
|
|
145
|
+
if (this.strictFlag) {
|
|
146
|
+
sql += ' STRICT';
|
|
147
|
+
}
|
|
148
|
+
sql += ` SECURITY ${this.security}`;
|
|
149
|
+
sql += ` PARALLEL ${this.__parallel}`;
|
|
150
|
+
if (this.leakproofFlag) {
|
|
151
|
+
sql += ' LEAKPROOF';
|
|
152
|
+
}
|
|
153
|
+
if (this.costValue !== undefined) {
|
|
154
|
+
sql += ` COST ${this.costValue}`;
|
|
155
|
+
}
|
|
156
|
+
if (this.rowsValue !== undefined) {
|
|
157
|
+
sql += ` ROWS ${this.rowsValue}`;
|
|
158
|
+
}
|
|
159
|
+
sql += ` AS $$${this.functionBody}$$`;
|
|
160
|
+
return sql;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.CreateFunctionBuilder = CreateFunctionBuilder;
|
|
164
|
+
class DropFunctionBuilder {
|
|
165
|
+
functionName;
|
|
166
|
+
parameterTypes;
|
|
167
|
+
ifExistsFlag = false;
|
|
168
|
+
cascadeFlag = false;
|
|
169
|
+
constructor(functionName, parameterTypes) {
|
|
170
|
+
this.functionName = functionName;
|
|
171
|
+
this.parameterTypes = parameterTypes;
|
|
172
|
+
}
|
|
173
|
+
ifExists() {
|
|
174
|
+
this.ifExistsFlag = true;
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
cascade() {
|
|
178
|
+
this.cascadeFlag = true;
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
toString() {
|
|
182
|
+
let sql = 'DROP FUNCTION';
|
|
183
|
+
if (this.ifExistsFlag) {
|
|
184
|
+
sql += ' IF EXISTS';
|
|
185
|
+
}
|
|
186
|
+
sql += ` ${pg_format_1.default.ident(this.functionName)}`;
|
|
187
|
+
if (this.parameterTypes && this.parameterTypes.length > 0) {
|
|
188
|
+
sql += `(${this.parameterTypes.join(', ')})`;
|
|
189
|
+
}
|
|
190
|
+
if (this.cascadeFlag) {
|
|
191
|
+
sql += ' CASCADE';
|
|
192
|
+
}
|
|
193
|
+
return sql;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.DropFunctionBuilder = DropFunctionBuilder;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DropFunctionBuilder = exports.CreateFunctionBuilder = void 0;
|
|
4
|
+
var create_function_builder_1 = require("./create-function-builder.cjs");
|
|
5
|
+
Object.defineProperty(exports, "CreateFunctionBuilder", { enumerable: true, get: function () { return create_function_builder_1.CreateFunctionBuilder; } });
|
|
6
|
+
Object.defineProperty(exports, "DropFunctionBuilder", { enumerable: true, get: function () { return create_function_builder_1.DropFunctionBuilder; } });
|
|
@@ -0,0 +1,241 @@
|
|
|
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.Conditional = exports.Aggregate = exports.Jsonb = exports.Array = exports.ConditionalFunctions = exports.AggregateFunctions = exports.JsonbFunctions = exports.ArrayFunctions = void 0;
|
|
7
|
+
const pg_format_1 = __importDefault(require("../../addons/pg-format.js"));
|
|
8
|
+
const sql_functions_1 = require("./sql-functions.cjs");
|
|
9
|
+
class ArrayFunctions {
|
|
10
|
+
static array_length(array, dimension = 1) {
|
|
11
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_length(%I, %s)', array, dimension));
|
|
12
|
+
}
|
|
13
|
+
static array_append(array, element) {
|
|
14
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_append(%I, %L)', array, element));
|
|
15
|
+
}
|
|
16
|
+
static array_prepend(element, array) {
|
|
17
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_prepend(%L, %I)', element, array));
|
|
18
|
+
}
|
|
19
|
+
static array_cat(array1, array2) {
|
|
20
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_cat(%I, %I)', array1, array2));
|
|
21
|
+
}
|
|
22
|
+
static array_remove(array, element) {
|
|
23
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_remove(%I, %L)', array, element));
|
|
24
|
+
}
|
|
25
|
+
static array_replace(array, from, to) {
|
|
26
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_replace(%I, %L, %L)', array, from, to));
|
|
27
|
+
}
|
|
28
|
+
static array_position(array, element) {
|
|
29
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_position(%I, %L)', array, element));
|
|
30
|
+
}
|
|
31
|
+
static array_positions(array, element) {
|
|
32
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_positions(%I, %L)', array, element));
|
|
33
|
+
}
|
|
34
|
+
static array_dims(array) {
|
|
35
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_dims(%I)', array));
|
|
36
|
+
}
|
|
37
|
+
static array_lower(array, dimension) {
|
|
38
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_lower(%I, %s)', array, dimension));
|
|
39
|
+
}
|
|
40
|
+
static array_upper(array, dimension) {
|
|
41
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_upper(%I, %s)', array, dimension));
|
|
42
|
+
}
|
|
43
|
+
static cardinality(array) {
|
|
44
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('cardinality(%I)', array));
|
|
45
|
+
}
|
|
46
|
+
static array_to_string(array, delimiter, nullString) {
|
|
47
|
+
if (nullString !== undefined) {
|
|
48
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_to_string(%I, %L, %L)', array, delimiter, nullString));
|
|
49
|
+
}
|
|
50
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_to_string(%I, %L)', array, delimiter));
|
|
51
|
+
}
|
|
52
|
+
static string_to_array(str, delimiter, nullString) {
|
|
53
|
+
if (nullString !== undefined) {
|
|
54
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('string_to_array(%I, %L, %L)', str, delimiter, nullString));
|
|
55
|
+
}
|
|
56
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('string_to_array(%I, %L)', str, delimiter));
|
|
57
|
+
}
|
|
58
|
+
static unnest(array) {
|
|
59
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('unnest(%I)', array));
|
|
60
|
+
}
|
|
61
|
+
static array_fill(value, dimensions) {
|
|
62
|
+
const dims = (0, pg_format_1.default)('%L', dimensions);
|
|
63
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_fill(%L, %s)', value, dims));
|
|
64
|
+
}
|
|
65
|
+
static array_agg(expression) {
|
|
66
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_agg(%I)', expression));
|
|
67
|
+
}
|
|
68
|
+
static array_agg_order(expression, orderBy, direction = 'ASC') {
|
|
69
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('array_agg(%I ORDER BY %I %s)', expression, orderBy, direction));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ArrayFunctions = ArrayFunctions;
|
|
73
|
+
exports.Array = ArrayFunctions;
|
|
74
|
+
class JsonbFunctions {
|
|
75
|
+
static jsonb_array_length(jsonb) {
|
|
76
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_array_length(%I)', jsonb));
|
|
77
|
+
}
|
|
78
|
+
static jsonb_each(jsonb) {
|
|
79
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_each(%I)', jsonb));
|
|
80
|
+
}
|
|
81
|
+
static jsonb_each_text(jsonb) {
|
|
82
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_each_text(%I)', jsonb));
|
|
83
|
+
}
|
|
84
|
+
static jsonb_object_keys(jsonb) {
|
|
85
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_object_keys(%I)', jsonb));
|
|
86
|
+
}
|
|
87
|
+
static jsonb_array_elements(jsonb) {
|
|
88
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_array_elements(%I)', jsonb));
|
|
89
|
+
}
|
|
90
|
+
static jsonb_array_elements_text(jsonb) {
|
|
91
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_array_elements_text(%I)', jsonb));
|
|
92
|
+
}
|
|
93
|
+
static jsonb_typeof(jsonb) {
|
|
94
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_typeof(%I)', jsonb));
|
|
95
|
+
}
|
|
96
|
+
static jsonb_strip_nulls(jsonb) {
|
|
97
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_strip_nulls(%I)', jsonb));
|
|
98
|
+
}
|
|
99
|
+
static jsonb_pretty(jsonb) {
|
|
100
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_pretty(%I)', jsonb));
|
|
101
|
+
}
|
|
102
|
+
static jsonb_set(target, path, newValue, createMissing = true) {
|
|
103
|
+
const pathStr = (0, pg_format_1.default)('%L', `{${path.join(',')}}`);
|
|
104
|
+
const valueStr = (0, pg_format_1.default)('%L', JSON.stringify(newValue));
|
|
105
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_set(%I, %s, %s, %s)', target, pathStr, valueStr, createMissing));
|
|
106
|
+
}
|
|
107
|
+
static jsonb_insert(target, path, newValue, insertAfter = false) {
|
|
108
|
+
const pathStr = (0, pg_format_1.default)('%L', `{${path.join(',')}}`);
|
|
109
|
+
const valueStr = (0, pg_format_1.default)('%L', JSON.stringify(newValue));
|
|
110
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_insert(%I, %s, %s, %s)', target, pathStr, valueStr, insertAfter));
|
|
111
|
+
}
|
|
112
|
+
static jsonb_build_object(...keyValuePairs) {
|
|
113
|
+
const args = keyValuePairs.map((v, idx) => idx % 2 === 0
|
|
114
|
+
? (0, pg_format_1.default)('%L', v)
|
|
115
|
+
: (typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v))
|
|
116
|
+
? pg_format_1.default.ident(v)
|
|
117
|
+
: (0, pg_format_1.default)('%L', v)).join(', ');
|
|
118
|
+
return new sql_functions_1.SqlFunction(`jsonb_build_object(${args})`);
|
|
119
|
+
}
|
|
120
|
+
static jsonb_build_array(...values) {
|
|
121
|
+
const args = values.map(v => typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
|
|
122
|
+
? pg_format_1.default.ident(v)
|
|
123
|
+
: (0, pg_format_1.default)('%L', v)).join(', ');
|
|
124
|
+
return new sql_functions_1.SqlFunction(`jsonb_build_array(${args})`);
|
|
125
|
+
}
|
|
126
|
+
static jsonb_to_text(jsonb) {
|
|
127
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I::text', jsonb));
|
|
128
|
+
}
|
|
129
|
+
static text_to_jsonb(text) {
|
|
130
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I::jsonb', text));
|
|
131
|
+
}
|
|
132
|
+
static jsonb_agg(expression) {
|
|
133
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_agg(%I)', expression));
|
|
134
|
+
}
|
|
135
|
+
static jsonb_object_agg(keys, values) {
|
|
136
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('jsonb_object_agg(%I, %I)', keys, values));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.JsonbFunctions = JsonbFunctions;
|
|
140
|
+
exports.Jsonb = JsonbFunctions;
|
|
141
|
+
class AggregateFunctions {
|
|
142
|
+
static count(expression = '*') {
|
|
143
|
+
if (expression === '*') {
|
|
144
|
+
return new sql_functions_1.SqlFunction('COUNT(*)');
|
|
145
|
+
}
|
|
146
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('COUNT(%I)', expression));
|
|
147
|
+
}
|
|
148
|
+
static count_distinct(expression) {
|
|
149
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('COUNT(DISTINCT %I)', expression));
|
|
150
|
+
}
|
|
151
|
+
static sum(expression) {
|
|
152
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('SUM(%I)', expression));
|
|
153
|
+
}
|
|
154
|
+
static avg(expression) {
|
|
155
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('AVG(%I)', expression));
|
|
156
|
+
}
|
|
157
|
+
static min(expression) {
|
|
158
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('MIN(%I)', expression));
|
|
159
|
+
}
|
|
160
|
+
static max(expression) {
|
|
161
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('MAX(%I)', expression));
|
|
162
|
+
}
|
|
163
|
+
static string_agg(expression, delimiter) {
|
|
164
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('string_agg(%I, %L)', expression, delimiter));
|
|
165
|
+
}
|
|
166
|
+
static string_agg_order(expression, delimiter, orderBy, direction = 'ASC') {
|
|
167
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('string_agg(%I, %L ORDER BY %I %s)', expression, delimiter, orderBy, direction));
|
|
168
|
+
}
|
|
169
|
+
static bool_and(expression) {
|
|
170
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('bool_and(%I)', expression));
|
|
171
|
+
}
|
|
172
|
+
static bool_or(expression) {
|
|
173
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('bool_or(%I)', expression));
|
|
174
|
+
}
|
|
175
|
+
static every(expression) {
|
|
176
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('every(%I)', expression));
|
|
177
|
+
}
|
|
178
|
+
static bit_and(expression) {
|
|
179
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('bit_and(%I)', expression));
|
|
180
|
+
}
|
|
181
|
+
static bit_or(expression) {
|
|
182
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('bit_or(%I)', expression));
|
|
183
|
+
}
|
|
184
|
+
static stddev_pop(expression) {
|
|
185
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('stddev_pop(%I)', expression));
|
|
186
|
+
}
|
|
187
|
+
static stddev_samp(expression) {
|
|
188
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('stddev_samp(%I)', expression));
|
|
189
|
+
}
|
|
190
|
+
static stddev(expression) {
|
|
191
|
+
return this.stddev_samp(expression);
|
|
192
|
+
}
|
|
193
|
+
static var_pop(expression) {
|
|
194
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('var_pop(%I)', expression));
|
|
195
|
+
}
|
|
196
|
+
static var_samp(expression) {
|
|
197
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('var_samp(%I)', expression));
|
|
198
|
+
}
|
|
199
|
+
static variance(expression) {
|
|
200
|
+
return this.var_samp(expression);
|
|
201
|
+
}
|
|
202
|
+
static corr(y, x) {
|
|
203
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('corr(%I, %I)', y, x));
|
|
204
|
+
}
|
|
205
|
+
static covar_pop(y, x) {
|
|
206
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('covar_pop(%I, %I)', y, x));
|
|
207
|
+
}
|
|
208
|
+
static covar_samp(y, x) {
|
|
209
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('covar_samp(%I, %I)', y, x));
|
|
210
|
+
}
|
|
211
|
+
static percentile_cont(percentile, expression) {
|
|
212
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('percentile_cont(%s) WITHIN GROUP (ORDER BY %I)', percentile, expression));
|
|
213
|
+
}
|
|
214
|
+
static percentile_disc(percentile, expression) {
|
|
215
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('percentile_disc(%s) WITHIN GROUP (ORDER BY %I)', percentile, expression));
|
|
216
|
+
}
|
|
217
|
+
static mode(expression) {
|
|
218
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('mode() WITHIN GROUP (ORDER BY %I)', expression));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.AggregateFunctions = AggregateFunctions;
|
|
222
|
+
exports.Aggregate = AggregateFunctions;
|
|
223
|
+
class ConditionalFunctions {
|
|
224
|
+
static coalesce(...values) {
|
|
225
|
+
const args = values.map(v => typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
|
|
226
|
+
? pg_format_1.default.ident(v)
|
|
227
|
+
: (0, pg_format_1.default)('%L', v)).join(', ');
|
|
228
|
+
return new sql_functions_1.SqlFunction(`COALESCE(${args})`);
|
|
229
|
+
}
|
|
230
|
+
static nullif(value1, value2) {
|
|
231
|
+
const arg1 = typeof value1 === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(value1)
|
|
232
|
+
? pg_format_1.default.ident(value1)
|
|
233
|
+
: (0, pg_format_1.default)('%L', value1);
|
|
234
|
+
const arg2 = typeof value2 === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(value2)
|
|
235
|
+
? pg_format_1.default.ident(value2)
|
|
236
|
+
: (0, pg_format_1.default)('%L', value2);
|
|
237
|
+
return new sql_functions_1.SqlFunction(`NULLIF(${arg1}, ${arg2})`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.ConditionalFunctions = ConditionalFunctions;
|
|
241
|
+
exports.Conditional = ConditionalFunctions;
|
|
@@ -0,0 +1,66 @@
|
|
|
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.CaseBuilder = void 0;
|
|
7
|
+
exports.Case = Case;
|
|
8
|
+
const pg_format_1 = __importDefault(require("../../addons/pg-format.js"));
|
|
9
|
+
class CaseBuilder {
|
|
10
|
+
expression;
|
|
11
|
+
whenClauses = [];
|
|
12
|
+
elseResult;
|
|
13
|
+
constructor(expression) {
|
|
14
|
+
this.expression = expression;
|
|
15
|
+
}
|
|
16
|
+
when(condition, result) {
|
|
17
|
+
this.whenClauses.push({
|
|
18
|
+
condition: String(condition),
|
|
19
|
+
result
|
|
20
|
+
});
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
else(result) {
|
|
24
|
+
this.elseResult = result;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
build() {
|
|
28
|
+
let sql = 'CASE';
|
|
29
|
+
if (this.expression) {
|
|
30
|
+
sql += ` ${pg_format_1.default.ident(this.expression)}`;
|
|
31
|
+
}
|
|
32
|
+
for (const clause of this.whenClauses) {
|
|
33
|
+
if (this.expression) {
|
|
34
|
+
sql += ` WHEN ${(0, pg_format_1.default)('%L', clause.condition)} THEN ${this.formatValue(clause.result)}`;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
sql += ` WHEN ${clause.condition} THEN ${this.formatValue(clause.result)}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (this.elseResult !== undefined) {
|
|
41
|
+
sql += ` ELSE ${this.formatValue(this.elseResult)}`;
|
|
42
|
+
}
|
|
43
|
+
sql += ' END';
|
|
44
|
+
return sql;
|
|
45
|
+
}
|
|
46
|
+
as(alias) {
|
|
47
|
+
return `${this.build()} AS ${pg_format_1.default.ident(alias)}`;
|
|
48
|
+
}
|
|
49
|
+
toString() {
|
|
50
|
+
return this.build();
|
|
51
|
+
}
|
|
52
|
+
formatValue(value) {
|
|
53
|
+
if (value === null) {
|
|
54
|
+
return 'NULL';
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(value)) {
|
|
57
|
+
return pg_format_1.default.ident(value);
|
|
58
|
+
}
|
|
59
|
+
return (0, pg_format_1.default)('%L', value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.CaseBuilder = CaseBuilder;
|
|
63
|
+
function Case(expression) {
|
|
64
|
+
return new CaseBuilder(expression);
|
|
65
|
+
}
|
|
66
|
+
exports.default = Case;
|
|
@@ -0,0 +1,104 @@
|
|
|
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.GeometricFunctions = void 0;
|
|
7
|
+
const pg_format_1 = __importDefault(require("../../addons/pg-format.js"));
|
|
8
|
+
const sql_functions_1 = require("./sql-functions.cjs");
|
|
9
|
+
class GeometricFunctions {
|
|
10
|
+
static area(column) {
|
|
11
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('area(%I)', column));
|
|
12
|
+
}
|
|
13
|
+
static center(column) {
|
|
14
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('center(%I)', column));
|
|
15
|
+
}
|
|
16
|
+
static diameter(column) {
|
|
17
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('diameter(%I)', column));
|
|
18
|
+
}
|
|
19
|
+
static height(column) {
|
|
20
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('height(%I)', column));
|
|
21
|
+
}
|
|
22
|
+
static width(column) {
|
|
23
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('width(%I)', column));
|
|
24
|
+
}
|
|
25
|
+
static geoLength(column) {
|
|
26
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('length(%I)', column));
|
|
27
|
+
}
|
|
28
|
+
static npoints(column) {
|
|
29
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('npoints(%I)', column));
|
|
30
|
+
}
|
|
31
|
+
static isclosed(column) {
|
|
32
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('isclosed(%I)', column));
|
|
33
|
+
}
|
|
34
|
+
static isopen(column) {
|
|
35
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('isopen(%I)', column));
|
|
36
|
+
}
|
|
37
|
+
static pclose(column) {
|
|
38
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('pclose(%I)', column));
|
|
39
|
+
}
|
|
40
|
+
static popen(column) {
|
|
41
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('popen(%I)', column));
|
|
42
|
+
}
|
|
43
|
+
static radius(column) {
|
|
44
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('radius(%I)', column));
|
|
45
|
+
}
|
|
46
|
+
static slope(point1, point2) {
|
|
47
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('slope(%I, %I)', point1, point2));
|
|
48
|
+
}
|
|
49
|
+
static distance(column, value) {
|
|
50
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I <-> %L', column, value));
|
|
51
|
+
}
|
|
52
|
+
static toBox(column) {
|
|
53
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('box(%I)', column));
|
|
54
|
+
}
|
|
55
|
+
static toCircle(column) {
|
|
56
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('circle(%I)', column));
|
|
57
|
+
}
|
|
58
|
+
static toLine(point1, point2) {
|
|
59
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('line(%I, %I)', point1, point2));
|
|
60
|
+
}
|
|
61
|
+
static toLseg(point1, point2) {
|
|
62
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('lseg(%I, %I)', point1, point2));
|
|
63
|
+
}
|
|
64
|
+
static toPath(column) {
|
|
65
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('path(%I)', column));
|
|
66
|
+
}
|
|
67
|
+
static toPoint(column) {
|
|
68
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('point(%I)', column));
|
|
69
|
+
}
|
|
70
|
+
static toPolygon(column) {
|
|
71
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('polygon(%I)', column));
|
|
72
|
+
}
|
|
73
|
+
static point(x, y) {
|
|
74
|
+
if (typeof x === 'string' && typeof y === 'string') {
|
|
75
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('point(%I, %I)', x, y));
|
|
76
|
+
}
|
|
77
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('point(%s, %s)', x, y));
|
|
78
|
+
}
|
|
79
|
+
static box(point1, point2) {
|
|
80
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('box(%I, %I)', point1, point2));
|
|
81
|
+
}
|
|
82
|
+
static circle(center, radius) {
|
|
83
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('circle(%I, %s)', center, radius));
|
|
84
|
+
}
|
|
85
|
+
static translate(column, offset) {
|
|
86
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I + point %L', column, offset));
|
|
87
|
+
}
|
|
88
|
+
static scale(column, factor) {
|
|
89
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I * point %L', column, factor));
|
|
90
|
+
}
|
|
91
|
+
static rotate(column, rotation) {
|
|
92
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I / point %L', column, rotation));
|
|
93
|
+
}
|
|
94
|
+
static intersection(line1, line2) {
|
|
95
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I # %I', line1, line2));
|
|
96
|
+
}
|
|
97
|
+
static closestPoint(lseg, point) {
|
|
98
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('%I ## %I', lseg, point));
|
|
99
|
+
}
|
|
100
|
+
static boundingBox(column) {
|
|
101
|
+
return new sql_functions_1.SqlFunction((0, pg_format_1.default)('box(%I)', column));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.GeometricFunctions = GeometricFunctions;
|