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,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelqBuilderError = exports.RelqEnvironmentError = exports.RelqPoolError = exports.RelqTimeoutError = exports.RelqConfigError = exports.RelqTransactionError = exports.RelqQueryError = exports.RelqConnectionError = exports.RelqError = void 0;
|
|
4
|
+
exports.setupErrorHandler = setupErrorHandler;
|
|
5
|
+
exports.isRelqError = isRelqError;
|
|
6
|
+
exports.isRelqConnectionError = isRelqConnectionError;
|
|
7
|
+
exports.isRelqQueryError = isRelqQueryError;
|
|
8
|
+
exports.isRelqBuilderError = isRelqBuilderError;
|
|
9
|
+
exports.wrapError = wrapError;
|
|
10
|
+
exports.parsePostgresError = parsePostgresError;
|
|
11
|
+
function setupErrorHandler() {
|
|
12
|
+
if (typeof process === 'undefined' || !process.on)
|
|
13
|
+
return;
|
|
14
|
+
process.on('uncaughtException', (error) => {
|
|
15
|
+
if (error instanceof RelqError) {
|
|
16
|
+
const inspect = error[Symbol.for('nodejs.util.inspect.custom')];
|
|
17
|
+
if (typeof inspect === 'function') {
|
|
18
|
+
console.error(inspect.call(error, 0, {}));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.error(`${error.name}: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.error(`${error.name || 'Error'}: ${error.message}`);
|
|
26
|
+
if (error.stack) {
|
|
27
|
+
const stackLines = error.stack.split('\n').filter(line => line.trim().startsWith('at '));
|
|
28
|
+
console.error(stackLines.slice(0, 5).join('\n'));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
33
|
+
process.on('unhandledRejection', (reason) => {
|
|
34
|
+
if (reason instanceof RelqError) {
|
|
35
|
+
const inspect = reason[Symbol.for('nodejs.util.inspect.custom')];
|
|
36
|
+
if (typeof inspect === 'function') {
|
|
37
|
+
console.error(inspect.call(reason, 0, {}));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.error(`${reason.name}: ${reason.message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (reason instanceof Error) {
|
|
44
|
+
console.error(`${reason.name || 'Error'}: ${reason.message}`);
|
|
45
|
+
if (reason.stack) {
|
|
46
|
+
const stackLines = reason.stack.split('\n').filter(line => line.trim().startsWith('at '));
|
|
47
|
+
console.error(stackLines.slice(0, 5).join('\n'));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.error('Unhandled rejection:', reason);
|
|
52
|
+
}
|
|
53
|
+
process.exit(1);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
class RelqError extends Error {
|
|
57
|
+
name;
|
|
58
|
+
cause;
|
|
59
|
+
timestamp;
|
|
60
|
+
constructor(message, cause) {
|
|
61
|
+
super(message);
|
|
62
|
+
this.name = 'RelqError';
|
|
63
|
+
this.cause = cause;
|
|
64
|
+
this.timestamp = new Date();
|
|
65
|
+
if (Error.captureStackTrace) {
|
|
66
|
+
Error.captureStackTrace(this, this.constructor);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
[Symbol.for('nodejs.util.inspect.custom')](_depth, _options) {
|
|
70
|
+
const lines = [
|
|
71
|
+
`${this.name}: ${this.message}`,
|
|
72
|
+
` timestamp: ${this.timestamp.toISOString()}`
|
|
73
|
+
];
|
|
74
|
+
const props = this._getInspectProps();
|
|
75
|
+
for (const [key, value] of Object.entries(props)) {
|
|
76
|
+
const strVal = value === undefined ? 'undefined' : JSON.stringify(value);
|
|
77
|
+
lines.push(`${key.padStart(10)}: ${strVal}`);
|
|
78
|
+
}
|
|
79
|
+
if (this.stack) {
|
|
80
|
+
const stackLines = this.stack.split('\n').filter(line => line.trim().startsWith('at ') || line.includes(this.name));
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push(...stackLines.slice(1, 6));
|
|
83
|
+
}
|
|
84
|
+
return lines.join('\n');
|
|
85
|
+
}
|
|
86
|
+
_getInspectProps() {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
toJSON() {
|
|
90
|
+
return {
|
|
91
|
+
name: this.name,
|
|
92
|
+
message: this.message,
|
|
93
|
+
cause: this.cause?.message,
|
|
94
|
+
timestamp: this.timestamp.toISOString(),
|
|
95
|
+
stack: this.stack
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.RelqError = RelqError;
|
|
100
|
+
class RelqConnectionError extends RelqError {
|
|
101
|
+
name = 'RelqConnectionError';
|
|
102
|
+
code;
|
|
103
|
+
host;
|
|
104
|
+
port;
|
|
105
|
+
constructor(message, options) {
|
|
106
|
+
super(message, options?.cause);
|
|
107
|
+
this.code = options?.code;
|
|
108
|
+
this.host = options?.host;
|
|
109
|
+
this.port = options?.port;
|
|
110
|
+
}
|
|
111
|
+
_getInspectProps() {
|
|
112
|
+
return { code: this.code, host: this.host, port: this.port };
|
|
113
|
+
}
|
|
114
|
+
toJSON() {
|
|
115
|
+
return {
|
|
116
|
+
...super.toJSON(),
|
|
117
|
+
code: this.code,
|
|
118
|
+
host: this.host,
|
|
119
|
+
port: this.port
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.RelqConnectionError = RelqConnectionError;
|
|
124
|
+
class RelqQueryError extends RelqError {
|
|
125
|
+
name = 'RelqQueryError';
|
|
126
|
+
sql;
|
|
127
|
+
code;
|
|
128
|
+
detail;
|
|
129
|
+
hint;
|
|
130
|
+
constructor(message, options) {
|
|
131
|
+
super(message, options?.cause);
|
|
132
|
+
this.sql = options?.sql;
|
|
133
|
+
this.code = options?.code;
|
|
134
|
+
this.detail = options?.detail;
|
|
135
|
+
this.hint = options?.hint;
|
|
136
|
+
}
|
|
137
|
+
_getInspectProps() {
|
|
138
|
+
return { sql: this.sql, detail: this.detail, hint: this.hint, code: this.code };
|
|
139
|
+
}
|
|
140
|
+
toJSON() {
|
|
141
|
+
return {
|
|
142
|
+
...super.toJSON(),
|
|
143
|
+
sql: this.sql,
|
|
144
|
+
code: this.code,
|
|
145
|
+
detail: this.detail,
|
|
146
|
+
hint: this.hint
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.RelqQueryError = RelqQueryError;
|
|
151
|
+
class RelqTransactionError extends RelqError {
|
|
152
|
+
name = 'RelqTransactionError';
|
|
153
|
+
operation;
|
|
154
|
+
transactionState;
|
|
155
|
+
constructor(message, operation, options) {
|
|
156
|
+
super(message, options?.cause);
|
|
157
|
+
this.operation = operation;
|
|
158
|
+
this.transactionState = options?.transactionState;
|
|
159
|
+
}
|
|
160
|
+
_getInspectProps() {
|
|
161
|
+
return { operation: this.operation, transactionState: this.transactionState };
|
|
162
|
+
}
|
|
163
|
+
toJSON() {
|
|
164
|
+
return {
|
|
165
|
+
...super.toJSON(),
|
|
166
|
+
operation: this.operation,
|
|
167
|
+
transactionState: this.transactionState
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.RelqTransactionError = RelqTransactionError;
|
|
172
|
+
class RelqConfigError extends RelqError {
|
|
173
|
+
name = 'RelqConfigError';
|
|
174
|
+
field;
|
|
175
|
+
value;
|
|
176
|
+
constructor(message, options) {
|
|
177
|
+
super(message);
|
|
178
|
+
this.field = options?.field;
|
|
179
|
+
this.value = options?.value;
|
|
180
|
+
}
|
|
181
|
+
_getInspectProps() {
|
|
182
|
+
return { field: this.field, value: this.value };
|
|
183
|
+
}
|
|
184
|
+
toJSON() {
|
|
185
|
+
return {
|
|
186
|
+
...super.toJSON(),
|
|
187
|
+
field: this.field,
|
|
188
|
+
value: this.value
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.RelqConfigError = RelqConfigError;
|
|
193
|
+
class RelqTimeoutError extends RelqError {
|
|
194
|
+
name = 'RelqTimeoutError';
|
|
195
|
+
timeout;
|
|
196
|
+
operation;
|
|
197
|
+
constructor(message, timeout, operation, cause) {
|
|
198
|
+
super(message, cause);
|
|
199
|
+
this.timeout = timeout;
|
|
200
|
+
this.operation = operation;
|
|
201
|
+
}
|
|
202
|
+
_getInspectProps() {
|
|
203
|
+
return { timeout: this.timeout, operation: this.operation };
|
|
204
|
+
}
|
|
205
|
+
toJSON() {
|
|
206
|
+
return {
|
|
207
|
+
...super.toJSON(),
|
|
208
|
+
timeout: this.timeout,
|
|
209
|
+
operation: this.operation
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.RelqTimeoutError = RelqTimeoutError;
|
|
214
|
+
class RelqPoolError extends RelqError {
|
|
215
|
+
name = 'RelqPoolError';
|
|
216
|
+
poolSize;
|
|
217
|
+
activeConnections;
|
|
218
|
+
waitingClients;
|
|
219
|
+
constructor(message, options) {
|
|
220
|
+
super(message, options?.cause);
|
|
221
|
+
this.poolSize = options?.poolSize;
|
|
222
|
+
this.activeConnections = options?.activeConnections;
|
|
223
|
+
this.waitingClients = options?.waitingClients;
|
|
224
|
+
}
|
|
225
|
+
_getInspectProps() {
|
|
226
|
+
return { poolSize: this.poolSize, activeConnections: this.activeConnections, waitingClients: this.waitingClients };
|
|
227
|
+
}
|
|
228
|
+
toJSON() {
|
|
229
|
+
return {
|
|
230
|
+
...super.toJSON(),
|
|
231
|
+
poolSize: this.poolSize,
|
|
232
|
+
activeConnections: this.activeConnections,
|
|
233
|
+
waitingClients: this.waitingClients
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.RelqPoolError = RelqPoolError;
|
|
238
|
+
class RelqEnvironmentError extends RelqError {
|
|
239
|
+
name = 'RelqEnvironmentError';
|
|
240
|
+
environment;
|
|
241
|
+
reason;
|
|
242
|
+
constructor(message, environment, reason) {
|
|
243
|
+
super(message);
|
|
244
|
+
this.environment = environment;
|
|
245
|
+
this.reason = reason;
|
|
246
|
+
}
|
|
247
|
+
_getInspectProps() {
|
|
248
|
+
return { environment: this.environment, reason: this.reason };
|
|
249
|
+
}
|
|
250
|
+
toJSON() {
|
|
251
|
+
return {
|
|
252
|
+
...super.toJSON(),
|
|
253
|
+
environment: this.environment,
|
|
254
|
+
reason: this.reason
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.RelqEnvironmentError = RelqEnvironmentError;
|
|
259
|
+
class RelqBuilderError extends RelqError {
|
|
260
|
+
name = 'RelqBuilderError';
|
|
261
|
+
builder;
|
|
262
|
+
missing;
|
|
263
|
+
hint;
|
|
264
|
+
constructor(message, options) {
|
|
265
|
+
super(message);
|
|
266
|
+
this.builder = options?.builder;
|
|
267
|
+
this.missing = options?.missing;
|
|
268
|
+
this.hint = options?.hint;
|
|
269
|
+
}
|
|
270
|
+
_getInspectProps() {
|
|
271
|
+
return { builder: this.builder, missing: this.missing, hint: this.hint };
|
|
272
|
+
}
|
|
273
|
+
toJSON() {
|
|
274
|
+
return {
|
|
275
|
+
...super.toJSON(),
|
|
276
|
+
builder: this.builder,
|
|
277
|
+
missing: this.missing,
|
|
278
|
+
hint: this.hint
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.RelqBuilderError = RelqBuilderError;
|
|
283
|
+
function isRelqError(error) {
|
|
284
|
+
return error instanceof RelqError;
|
|
285
|
+
}
|
|
286
|
+
function isRelqConnectionError(error) {
|
|
287
|
+
return error instanceof RelqConnectionError;
|
|
288
|
+
}
|
|
289
|
+
function isRelqQueryError(error) {
|
|
290
|
+
return error instanceof RelqQueryError;
|
|
291
|
+
}
|
|
292
|
+
function isRelqBuilderError(error) {
|
|
293
|
+
return error instanceof RelqBuilderError;
|
|
294
|
+
}
|
|
295
|
+
function wrapError(error, context) {
|
|
296
|
+
if (isRelqError(error)) {
|
|
297
|
+
return error;
|
|
298
|
+
}
|
|
299
|
+
if (error instanceof Error) {
|
|
300
|
+
const message = context ? `${context}: ${error.message}` : error.message;
|
|
301
|
+
return new RelqError(message, error);
|
|
302
|
+
}
|
|
303
|
+
const message = context
|
|
304
|
+
? `${context}: ${String(error)}`
|
|
305
|
+
: String(error);
|
|
306
|
+
return new RelqError(message);
|
|
307
|
+
}
|
|
308
|
+
function parsePostgresError(error, sql) {
|
|
309
|
+
const message = error.message || 'Database error';
|
|
310
|
+
const code = error.code;
|
|
311
|
+
if (code === 'ECONNREFUSED' || code === 'ENOTFOUND' || code === 'ETIMEDOUT') {
|
|
312
|
+
return new RelqConnectionError(message, {
|
|
313
|
+
cause: error,
|
|
314
|
+
code,
|
|
315
|
+
host: error.hostname,
|
|
316
|
+
port: error.port
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (code === '57014') {
|
|
320
|
+
return new RelqTimeoutError('Query execution timed out', error.timeout || 0, 'query', error);
|
|
321
|
+
}
|
|
322
|
+
return new RelqQueryError(message, {
|
|
323
|
+
cause: error,
|
|
324
|
+
sql,
|
|
325
|
+
code,
|
|
326
|
+
detail: error.detail,
|
|
327
|
+
hint: error.hint
|
|
328
|
+
});
|
|
329
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
const index_1 = __importDefault(require("../index.cjs"));
|
|
7
|
+
const alterTableSQL = (0, index_1.default)('results')
|
|
8
|
+
.alterTable()
|
|
9
|
+
.addColumn('search_vector', {
|
|
10
|
+
type: 'tsvector',
|
|
11
|
+
generated: {
|
|
12
|
+
always: true,
|
|
13
|
+
expression: `
|
|
14
|
+
setweight(to_tsvector('english', coalesce(email, '')), 'A') ||
|
|
15
|
+
setweight(to_tsvector('english', coalesce(ip_address, '')), 'B') ||
|
|
16
|
+
setweight(to_tsvector('english', coalesce(country, '')), 'C') ||
|
|
17
|
+
setweight(to_tsvector('english', coalesce(city, '')), 'C') ||
|
|
18
|
+
setweight(to_tsvector('english', coalesce(device, '')), 'D') ||
|
|
19
|
+
setweight(to_tsvector('english', coalesce(browser, '')), 'D')
|
|
20
|
+
`.trim()
|
|
21
|
+
}
|
|
22
|
+
}, true)
|
|
23
|
+
.toString();
|
|
24
|
+
console.log('=== ALTER TABLE ===');
|
|
25
|
+
console.log(alterTableSQL);
|
|
26
|
+
console.log('');
|
|
27
|
+
const createIndexSQL = (0, index_1.default)('results')
|
|
28
|
+
.createIndex('idx_results_search_gin')
|
|
29
|
+
.gin(['search_vector'], 'tsvector_ops')
|
|
30
|
+
.where("user_id IS NOT NULL AND is_deleted = FALSE")
|
|
31
|
+
.ifNotExists()
|
|
32
|
+
.toString();
|
|
33
|
+
console.log('=== CREATE INDEX ===');
|
|
34
|
+
console.log(createIndexSQL);
|
|
35
|
+
console.log('');
|
|
36
|
+
const searchQuery = (0, index_1.default)('results')
|
|
37
|
+
.select([
|
|
38
|
+
'id',
|
|
39
|
+
'email',
|
|
40
|
+
'ip_address',
|
|
41
|
+
'country',
|
|
42
|
+
'city',
|
|
43
|
+
'device',
|
|
44
|
+
'browser',
|
|
45
|
+
'is_pinned',
|
|
46
|
+
'updated_at'
|
|
47
|
+
])
|
|
48
|
+
.where(q => q
|
|
49
|
+
.equal('user_id', 'abc')
|
|
50
|
+
.equal('is_deleted', false)
|
|
51
|
+
.fulltext.search('search_vector', 'john@gmail'))
|
|
52
|
+
.orderBy('is_pinned', 'DESC')
|
|
53
|
+
.orderBy('updated_at', 'DESC')
|
|
54
|
+
.toString();
|
|
55
|
+
console.log('=== SELECT QUERY ===');
|
|
56
|
+
console.log(searchQuery);
|
|
57
|
+
console.log('');
|
|
58
|
+
console.log('=== ADDITIONAL EXAMPLES ===\n');
|
|
59
|
+
const sortIndexSQL = (0, index_1.default)('results')
|
|
60
|
+
.createIndex('idx_results_sort')
|
|
61
|
+
.btree([
|
|
62
|
+
{ column: 'is_pinned', order: 'DESC' },
|
|
63
|
+
{ column: 'updated_at', order: 'DESC' }
|
|
64
|
+
])
|
|
65
|
+
.where("is_deleted = FALSE")
|
|
66
|
+
.ifNotExists()
|
|
67
|
+
.toString();
|
|
68
|
+
console.log('1. Multi-column sort index:');
|
|
69
|
+
console.log(sortIndexSQL);
|
|
70
|
+
console.log('');
|
|
71
|
+
const userIndexSQL = (0, index_1.default)('results')
|
|
72
|
+
.createIndex('idx_results_user_deleted')
|
|
73
|
+
.btree(['user_id', 'is_deleted'])
|
|
74
|
+
.ifNotExists()
|
|
75
|
+
.toString();
|
|
76
|
+
console.log('2. User + deleted filter index:');
|
|
77
|
+
console.log(userIndexSQL);
|
|
78
|
+
console.log('');
|
|
79
|
+
const rankedSearchQuery = (0, index_1.default)('results')
|
|
80
|
+
.select(['id', 'email', 'country'])
|
|
81
|
+
.where(q => q
|
|
82
|
+
.equal('user_id', 'abc')
|
|
83
|
+
.equal('is_deleted', false)
|
|
84
|
+
.fulltext.rank('search_vector', 'california', 0.1))
|
|
85
|
+
.toString();
|
|
86
|
+
console.log('3. Search with minimum rank threshold:');
|
|
87
|
+
console.log(rankedSearchQuery);
|
|
88
|
+
console.log('');
|
|
89
|
+
const alterWithIdentitySQL = (0, index_1.default)('users')
|
|
90
|
+
.alterTable()
|
|
91
|
+
.addColumn('sequence_id', {
|
|
92
|
+
type: 'integer',
|
|
93
|
+
generated: {
|
|
94
|
+
always: false,
|
|
95
|
+
expression: 'nextval(\'user_seq\'::regclass)'
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
.toString();
|
|
99
|
+
console.log('4. Generated column with BY DEFAULT:');
|
|
100
|
+
console.log(alterWithIdentitySQL);
|
|
101
|
+
console.log('');
|
|
102
|
+
const multipleActionsSQL = (0, index_1.default)('results')
|
|
103
|
+
.alterTable()
|
|
104
|
+
.addColumn('search_vector', {
|
|
105
|
+
type: 'tsvector',
|
|
106
|
+
generated: {
|
|
107
|
+
always: true,
|
|
108
|
+
expression: `to_tsvector('english', coalesce(email, ''))`
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.addColumn('full_name', {
|
|
112
|
+
type: 'text',
|
|
113
|
+
generated: {
|
|
114
|
+
always: true,
|
|
115
|
+
expression: `coalesce(first_name, '') || ' ' || coalesce(last_name, '')`
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
.toString();
|
|
119
|
+
console.log('5. Multiple generated columns:');
|
|
120
|
+
console.log(multipleActionsSQL);
|
|
121
|
+
console.log('');
|
|
122
|
+
console.log('✅ All examples generated successfully!');
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExplainBuilder = void 0;
|
|
4
|
+
class ExplainBuilder {
|
|
5
|
+
query;
|
|
6
|
+
options;
|
|
7
|
+
constructor(query, options = {}) {
|
|
8
|
+
this.query = query;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
analyze(enable = true) {
|
|
12
|
+
this.options.analyze = enable;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
verbose(enable = true) {
|
|
16
|
+
this.options.verbose = enable;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
costs(enable = true) {
|
|
20
|
+
this.options.costs = enable;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
settings(enable = true) {
|
|
24
|
+
this.options.settings = enable;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
buffers(enable = true) {
|
|
28
|
+
this.options.buffers = enable;
|
|
29
|
+
if (enable) {
|
|
30
|
+
this.options.analyze = true;
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
timing(enable = true) {
|
|
35
|
+
this.options.timing = enable;
|
|
36
|
+
if (enable) {
|
|
37
|
+
this.options.analyze = true;
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
summary(enable = true) {
|
|
42
|
+
this.options.summary = enable;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
wal(enable = true) {
|
|
46
|
+
this.options.wal = enable;
|
|
47
|
+
if (enable) {
|
|
48
|
+
this.options.analyze = true;
|
|
49
|
+
}
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
format(format) {
|
|
53
|
+
this.options.format = format;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
toString() {
|
|
57
|
+
const options = [];
|
|
58
|
+
if (this.options.analyze) {
|
|
59
|
+
options.push('ANALYZE');
|
|
60
|
+
}
|
|
61
|
+
if (this.options.verbose) {
|
|
62
|
+
options.push('VERBOSE');
|
|
63
|
+
}
|
|
64
|
+
if (this.options.costs === false) {
|
|
65
|
+
options.push('COSTS FALSE');
|
|
66
|
+
}
|
|
67
|
+
else if (this.options.costs === true) {
|
|
68
|
+
options.push('COSTS TRUE');
|
|
69
|
+
}
|
|
70
|
+
if (this.options.settings) {
|
|
71
|
+
options.push('SETTINGS');
|
|
72
|
+
}
|
|
73
|
+
if (this.options.buffers) {
|
|
74
|
+
options.push('BUFFERS');
|
|
75
|
+
}
|
|
76
|
+
if (this.options.timing === false) {
|
|
77
|
+
options.push('TIMING FALSE');
|
|
78
|
+
}
|
|
79
|
+
else if (this.options.timing === true) {
|
|
80
|
+
options.push('TIMING TRUE');
|
|
81
|
+
}
|
|
82
|
+
if (this.options.summary) {
|
|
83
|
+
options.push('SUMMARY');
|
|
84
|
+
}
|
|
85
|
+
if (this.options.wal) {
|
|
86
|
+
options.push('WAL');
|
|
87
|
+
}
|
|
88
|
+
if (this.options.format) {
|
|
89
|
+
options.push(`FORMAT ${this.options.format}`);
|
|
90
|
+
}
|
|
91
|
+
let sql = 'EXPLAIN';
|
|
92
|
+
if (options.length > 0) {
|
|
93
|
+
sql += ` (${options.join(', ')})`;
|
|
94
|
+
}
|
|
95
|
+
sql += ' ' + this.query;
|
|
96
|
+
return sql;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.ExplainBuilder = ExplainBuilder;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExplainBuilder = void 0;
|
|
4
|
+
var explain_builder_1 = require("./explain-builder.cjs");
|
|
5
|
+
Object.defineProperty(exports, "ExplainBuilder", { enumerable: true, get: function () { return explain_builder_1.ExplainBuilder; } });
|