uql-orm 0.21.0 → 0.23.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/README.md +5 -4
- package/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/bunSql/bunSqlCockroachDialect.d.ts +2 -2
- package/dist/bunSql/bunSqlCockroachDialect.js +4 -10
- package/dist/bunSql/bunSqlPostgresDialect.d.ts +2 -2
- package/dist/bunSql/bunSqlPostgresDialect.js +4 -10
- package/dist/cockroachdb/cockroachDialect.d.ts +20 -4
- package/dist/cockroachdb/cockroachDialect.js +33 -18
- package/dist/d1/d1Querier.d.ts +4 -3
- package/dist/d1/d1Querier.js +0 -3
- package/dist/d1/d1SqliteDialect.d.ts +7 -0
- package/dist/d1/d1SqliteDialect.js +9 -0
- package/dist/dialect/abstractDialect.d.ts +8 -3
- package/dist/dialect/abstractDialect.js +9 -4
- package/dist/dialect/abstractSqlDialect.d.ts +49 -8
- package/dist/dialect/abstractSqlDialect.js +95 -47
- package/dist/dialect/index.d.ts +1 -0
- package/dist/dialect/index.js +1 -0
- package/dist/dialect/indexSqlDialect.d.ts +57 -0
- package/dist/dialect/indexSqlDialect.js +101 -0
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +26 -1
- package/dist/dialect/mysqlLikeSqlDialect.js +57 -1
- package/dist/dialect/pgLikeSqlDialect.d.ts +37 -22
- package/dist/dialect/pgLikeSqlDialect.js +97 -68
- package/dist/dialect/vectorCast.d.ts +21 -0
- package/dist/dialect/vectorCast.js +28 -0
- package/dist/dialect/vectorSqlDialect.d.ts +10 -3
- package/dist/dialect/vectorSqlDialect.js +19 -8
- package/dist/entity/decorator/bag.d.ts +35 -0
- package/dist/entity/decorator/bag.js +54 -0
- package/dist/entity/decorator/entity.d.ts +28 -2
- package/dist/entity/decorator/entity.js +40 -2
- package/dist/entity/decorator/members.d.ts +51 -0
- package/dist/entity/decorator/members.js +51 -0
- package/dist/entity/index.d.ts +3 -1
- package/dist/entity/index.js +3 -1
- package/dist/entity/metadata/definition.d.ts +23 -8
- package/dist/entity/metadata/definition.js +56 -100
- package/dist/http/contract.js +1 -2
- package/dist/http/handler.js +5 -26
- package/dist/http/query.js +1 -1
- package/dist/libsql/libsqlDialect.d.ts +12 -2
- package/dist/libsql/libsqlDialect.js +14 -2
- package/dist/libsql/libsqlQuerier.d.ts +9 -22
- package/dist/libsql/libsqlQuerier.js +9 -85
- package/dist/libsql/libsqlQuerierPool.d.ts +10 -8
- package/dist/libsql/libsqlQuerierPool.js +17 -15
- package/dist/maria/mariaDialect.d.ts +26 -4
- package/dist/maria/mariaDialect.js +54 -15
- package/dist/migrate/acquireQuerierForMigrations.d.ts +13 -1
- package/dist/migrate/acquireQuerierForMigrations.js +28 -0
- package/dist/migrate/builder/migrationBuilder.d.ts +9 -29
- package/dist/migrate/builder/migrationBuilder.js +58 -76
- package/dist/migrate/builder/splitSqlStatements.d.ts +0 -2
- package/dist/migrate/builder/splitSqlStatements.js +0 -2
- package/dist/migrate/builder/tableBuilder.d.ts +12 -2
- package/dist/migrate/builder/tableBuilder.js +71 -119
- package/dist/migrate/builder/types.d.ts +30 -41
- package/dist/migrate/cli-config.js +24 -8
- package/dist/migrate/cli.d.ts +3 -2
- package/dist/migrate/cli.js +26 -49
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +0 -4
- package/dist/migrate/codegen/entityCodeGenerator.js +8 -67
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +10 -0
- package/dist/migrate/codegen/fieldOptionsSource.js +55 -0
- package/dist/migrate/codegen/index.d.ts +0 -3
- package/dist/migrate/codegen/index.js +0 -6
- package/dist/migrate/drift/driftDetector.d.ts +10 -1
- package/dist/migrate/drift/driftDetector.js +22 -5
- package/dist/migrate/generator/indexNodeToSchema.d.ts +9 -0
- package/dist/migrate/generator/indexNodeToSchema.js +14 -0
- package/dist/migrate/generator/mongoCommand.d.ts +57 -0
- package/dist/migrate/generator/mongoCommand.js +26 -0
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +9 -20
- package/dist/migrate/generator/mongoSchemaGenerator.js +40 -82
- package/dist/migrate/index.d.ts +0 -1
- package/dist/migrate/index.js +0 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +30 -11
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +61 -57
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +3 -12
- package/dist/migrate/introspection/mongoIntrospector.js +9 -15
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +5 -8
- package/dist/migrate/introspection/mysqlIntrospector.js +4 -10
- package/dist/migrate/introspection/postgresIntrospector.d.ts +5 -8
- package/dist/migrate/introspection/postgresIntrospector.js +4 -10
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +6 -5
- package/dist/migrate/introspection/sqliteIntrospector.js +26 -18
- package/dist/migrate/migrator.d.ts +23 -3
- package/dist/migrate/migrator.js +101 -150
- package/dist/migrate/schemaGenerator.d.ts +26 -37
- package/dist/migrate/schemaGenerator.js +69 -174
- package/dist/migrate/schemaGeneratorAsync.d.ts +2 -2
- package/dist/migrate/schemaGeneratorAsync.js +3 -3
- package/dist/migrate/storage/databaseStorage.d.ts +2 -0
- package/dist/migrate/storage/databaseStorage.js +12 -27
- package/dist/mongo/mongoDialect.d.ts +2 -0
- package/dist/mongo/mongoDialect.js +14 -3
- package/dist/mongo/mongodbQuerier.js +171 -229
- package/dist/mysql/mysqlDialect.d.ts +8 -0
- package/dist/mysql/mysqlDialect.js +13 -0
- package/dist/nestjs/uqlContextInterceptor.js +58 -22
- package/dist/nestjs/uqlModule.d.ts +2 -11
- package/dist/nestjs/uqlModule.js +93 -44
- package/dist/postgres/postgresDialect.js +2 -2
- package/dist/querier/abstractQuerier.d.ts +28 -0
- package/dist/querier/abstractQuerier.js +47 -22
- package/dist/querier/abstractQuerierPool.d.ts +3 -0
- package/dist/querier/abstractQuerierPool.js +5 -3
- package/dist/querier/abstractSqlQuerier.d.ts +1 -3
- package/dist/querier/abstractSqlQuerier.js +48 -96
- package/dist/querier/index.d.ts +3 -1
- package/dist/querier/index.js +3 -1
- package/dist/querier/querierContext.browser.d.ts +12 -0
- package/dist/querier/querierContext.browser.js +18 -0
- package/dist/querier/querierContext.d.ts +22 -0
- package/dist/querier/querierContext.js +42 -0
- package/dist/querier/queryError.d.ts +22 -0
- package/dist/querier/queryError.js +20 -0
- package/dist/querier/transactional.d.ts +26 -0
- package/dist/querier/transactional.js +43 -0
- package/dist/schema/canonicalType.d.ts +14 -2
- package/dist/schema/canonicalType.js +41 -31
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/schemaASTBuilder.d.ts +9 -2
- package/dist/schema/schemaASTBuilder.js +58 -49
- package/dist/schema/types.d.ts +10 -58
- package/dist/sqlite/abstractSqliteQuerier.d.ts +46 -0
- package/dist/sqlite/abstractSqliteQuerier.js +44 -0
- package/dist/sqlite/bunSqliteAdapter.bun.d.ts +26 -0
- package/dist/sqlite/bunSqliteAdapter.bun.js +25 -0
- package/dist/sqlite/hranaQuerier.d.ts +54 -0
- package/dist/sqlite/hranaQuerier.js +68 -0
- package/dist/sqlite/hranaQuerierPool.d.ts +21 -0
- package/dist/sqlite/hranaQuerierPool.js +25 -0
- package/dist/sqlite/index.d.ts +3 -1
- package/dist/sqlite/index.js +3 -1
- package/dist/sqlite/localSqliteQuerierPool.d.ts +31 -0
- package/dist/sqlite/localSqliteQuerierPool.js +34 -0
- package/dist/sqlite/nodeSqliteAdapter.d.ts +35 -0
- package/dist/sqlite/nodeSqliteAdapter.js +28 -0
- package/dist/sqlite/nodeSqliteQuerierPool.d.ts +28 -0
- package/dist/sqlite/nodeSqliteQuerierPool.js +29 -0
- package/dist/sqlite/sqliteDialect.d.ts +18 -5
- package/dist/sqlite/sqliteDialect.js +23 -36
- package/dist/sqlite/sqliteQuerier.d.ts +16 -9
- package/dist/sqlite/sqliteQuerier.js +4 -27
- package/dist/sqlite/sqliteQuerierPool.d.ts +11 -14
- package/dist/sqlite/sqliteQuerierPool.js +16 -24
- package/dist/turso/index.d.ts +3 -0
- package/dist/turso/index.js +3 -0
- package/dist/turso/local.d.ts +3 -0
- package/dist/turso/local.js +3 -0
- package/dist/turso/tursoDialect.d.ts +15 -0
- package/dist/turso/tursoDialect.js +18 -0
- package/dist/turso/tursoLocalQuerier.d.ts +25 -0
- package/dist/turso/tursoLocalQuerier.js +20 -0
- package/dist/turso/tursoLocalQuerierPool.d.ts +32 -0
- package/dist/turso/tursoLocalQuerierPool.js +39 -0
- package/dist/turso/tursoQuerier.d.ts +10 -0
- package/dist/turso/tursoQuerier.js +10 -0
- package/dist/turso/tursoQuerierPool.d.ts +39 -0
- package/dist/turso/tursoQuerierPool.js +38 -0
- package/dist/type/config.d.ts +0 -6
- package/dist/type/dialect.d.ts +12 -4
- package/dist/type/dialect.js +7 -1
- package/dist/type/entity.d.ts +154 -26
- package/dist/type/migration.d.ts +32 -23
- package/dist/type/querier.d.ts +6 -0
- package/dist/type/vector.d.ts +5 -2
- package/dist/util/hook.util.js +1 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/indexColumn.util.d.ts +6 -0
- package/dist/util/indexColumn.util.js +26 -0
- package/package.json +21 -16
- package/dist/entity/decorator/field.d.ts +0 -2
- package/dist/entity/decorator/field.js +0 -7
- package/dist/entity/decorator/filter.d.ts +0 -7
- package/dist/entity/decorator/filter.js +0 -11
- package/dist/entity/decorator/hook.d.ts +0 -7
- package/dist/entity/decorator/hook.js +0 -14
- package/dist/entity/decorator/id.d.ts +0 -2
- package/dist/entity/decorator/id.js +0 -7
- package/dist/entity/decorator/index-decorator.d.ts +0 -29
- package/dist/entity/decorator/index-decorator.js +0 -26
- package/dist/entity/decorator/index.d.ts +0 -8
- package/dist/entity/decorator/index.js +0 -8
- package/dist/entity/decorator/relation.d.ts +0 -8
- package/dist/entity/decorator/relation.js +0 -19
- package/dist/migrate/codegen/entityMerger.d.ts +0 -114
- package/dist/migrate/codegen/entityMerger.js +0 -293
- package/dist/migrate/codegen/migrationCodeGenerator.d.ts +0 -61
- package/dist/migrate/codegen/migrationCodeGenerator.js +0 -355
- package/dist/migrate/codegen/smartRelationDetector.d.ts +0 -47
- package/dist/migrate/codegen/smartRelationDetector.js +0 -134
- package/dist/migrate/generator/index.d.ts +0 -2
- package/dist/migrate/generator/index.js +0 -2
- package/dist/migrate/sync/index.d.ts +0 -6
- package/dist/migrate/sync/index.js +0 -6
- package/dist/migrate/sync/schemaSync.d.ts +0 -131
- package/dist/migrate/sync/schemaSync.js +0 -259
- package/dist/querier/decorator/index.d.ts +0 -4
- package/dist/querier/decorator/index.js +0 -4
- package/dist/querier/decorator/injectQuerier.d.ts +0 -3
- package/dist/querier/decorator/injectQuerier.js +0 -33
- package/dist/querier/decorator/log.d.ts +0 -32
- package/dist/querier/decorator/log.js +0 -52
- package/dist/querier/decorator/serialized.d.ts +0 -6
- package/dist/querier/decorator/serialized.js +0 -13
- package/dist/querier/decorator/transactional.d.ts +0 -6
- package/dist/querier/decorator/transactional.js +0 -48
- package/dist/sqlite/betterSqlite3Dialect.d.ts +0 -9
- package/dist/sqlite/betterSqlite3Dialect.js +0 -9
package/dist/nestjs/uqlModule.js
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
9
27
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
12
34
|
};
|
|
13
|
-
|
|
14
|
-
import { Inject, Module, } from '@nestjs/common';
|
|
35
|
+
import { Module, } from '@nestjs/common';
|
|
15
36
|
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
16
37
|
import { setQuerierPool } from '../options.js';
|
|
17
38
|
import { UqlContextInterceptor } from './uqlContextInterceptor.js';
|
|
@@ -28,7 +49,16 @@ export const UQL_QUERIER_POOL = Symbol('UQL_QUERIER_POOL');
|
|
|
28
49
|
* optionally scopes every request to a {@link UqlContext} (multi-tenancy), and ends the pool on
|
|
29
50
|
* application shutdown.
|
|
30
51
|
*/
|
|
31
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Ends the pool when Nest shuts down.
|
|
54
|
+
*
|
|
55
|
+
* @remarks A provider rather than a hook on the module class, and built through `useFactory` with an
|
|
56
|
+
* `inject` list rather than constructor injection: Nest injects constructor parameters with a parameter
|
|
57
|
+
* decorator, and the TC39 decorator spec has none, so `@Inject()` cannot appear in a file compiled
|
|
58
|
+
* against it. Nest runs lifecycle hooks on providers too, so this keeps the pool that *this* module was
|
|
59
|
+
* configured with instead of reaching for the global default.
|
|
60
|
+
*/
|
|
61
|
+
class UqlPoolLifecycle {
|
|
32
62
|
pool;
|
|
33
63
|
constructor(pool) {
|
|
34
64
|
this.pool = pool;
|
|
@@ -36,36 +66,55 @@ let UqlModule = UqlModule_1 = class UqlModule {
|
|
|
36
66
|
onApplicationShutdown() {
|
|
37
67
|
return this.pool.end();
|
|
38
68
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
inject,
|
|
54
|
-
};
|
|
55
|
-
return UqlModule_1.build(global, poolProvider, getContext, imports);
|
|
56
|
-
}
|
|
57
|
-
static build(global, poolProvider, getContext, imports) {
|
|
58
|
-
const providers = [poolProvider];
|
|
59
|
-
if (getContext) {
|
|
60
|
-
// Scope every request to its context so multi-tenancy / security filters apply automatically.
|
|
61
|
-
providers.push({ provide: APP_INTERCEPTOR, useValue: new UqlContextInterceptor(getContext) });
|
|
69
|
+
}
|
|
70
|
+
let UqlModule = (() => {
|
|
71
|
+
let _classDecorators = [Module({})];
|
|
72
|
+
let _classDescriptor;
|
|
73
|
+
let _classExtraInitializers = [];
|
|
74
|
+
let _classThis;
|
|
75
|
+
var UqlModule = class {
|
|
76
|
+
static { _classThis = this; }
|
|
77
|
+
static {
|
|
78
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
79
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
80
|
+
UqlModule = _classThis = _classDescriptor.value;
|
|
81
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
82
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
62
83
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
UqlModule
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
/** Configure with an already-built pool. */
|
|
85
|
+
static forRoot({ pool, global = true, getContext }) {
|
|
86
|
+
setQuerierPool(pool);
|
|
87
|
+
return UqlModule.build(global, { provide: UQL_QUERIER_POOL, useValue: pool }, getContext);
|
|
88
|
+
}
|
|
89
|
+
/** Configure with a pool built asynchronously from injected providers (e.g. `ConfigService`). */
|
|
90
|
+
static forRootAsync({ imports, useFactory, inject = [], global = true, getContext, }) {
|
|
91
|
+
const poolProvider = {
|
|
92
|
+
provide: UQL_QUERIER_POOL,
|
|
93
|
+
useFactory: async (...args) => {
|
|
94
|
+
const pool = await useFactory(...args);
|
|
95
|
+
setQuerierPool(pool); // register as UQL's default once the pool is resolved
|
|
96
|
+
return pool;
|
|
97
|
+
},
|
|
98
|
+
inject,
|
|
99
|
+
};
|
|
100
|
+
return UqlModule.build(global, poolProvider, getContext, imports);
|
|
101
|
+
}
|
|
102
|
+
static build(global, poolProvider, getContext, imports) {
|
|
103
|
+
const providers = [
|
|
104
|
+
poolProvider,
|
|
105
|
+
{
|
|
106
|
+
provide: UqlPoolLifecycle,
|
|
107
|
+
useFactory: (pool) => new UqlPoolLifecycle(pool),
|
|
108
|
+
inject: [UQL_QUERIER_POOL],
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
if (getContext) {
|
|
112
|
+
// Scope every request to its context so multi-tenancy / security filters apply automatically.
|
|
113
|
+
providers.push({ provide: APP_INTERCEPTOR, useValue: new UqlContextInterceptor(getContext) });
|
|
114
|
+
}
|
|
115
|
+
return { module: UqlModule, global, imports, providers, exports: [UQL_QUERIER_POOL] };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return UqlModule = _classThis;
|
|
119
|
+
})();
|
|
71
120
|
export { UqlModule };
|
|
@@ -10,7 +10,7 @@ export class PostgresDialect extends PgLikeSqlDialect {
|
|
|
10
10
|
dialectName = 'postgres';
|
|
11
11
|
vectorExtension = 'vector';
|
|
12
12
|
upsert(ctx, entity, conflictPaths, payload) {
|
|
13
|
-
// xmax system column is 0 for newly inserted
|
|
14
|
-
|
|
13
|
+
// The xmax system column is 0 for a newly inserted row and non-zero for an updated one (MVCC).
|
|
14
|
+
super.upsert(ctx, entity, conflictPaths, payload, `, (xmax = 0) AS ${this.escapeId('_created')}`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -117,6 +117,23 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
117
117
|
private saveOneToOne;
|
|
118
118
|
private saveManyToOne;
|
|
119
119
|
abstract readonly hasOpenTransaction: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Runs `callback` in a transaction: begin, commit on success, roll back on failure.
|
|
122
|
+
*
|
|
123
|
+
* The single place that sequence is written; everything else delegates here, because both subtleties
|
|
124
|
+
* below were got wrong by code that hand-rolled it:
|
|
125
|
+
*
|
|
126
|
+
* - `beginTransaction` connects before it begins, so a refused connection lands in the catch with no
|
|
127
|
+
* transaction open. Rolling back regardless threw `not a pending transaction`, and that replaced the
|
|
128
|
+
* real cause: a wrong password surfaced as a transaction-state error.
|
|
129
|
+
* - A rollback that fails too is a consequence of the original failure, not news, so it must not
|
|
130
|
+
* replace it either.
|
|
131
|
+
*
|
|
132
|
+
* The connection is **not** released here: whoever took it from the pool gives it back, through
|
|
133
|
+
* {@link QuerierPool.transaction}, {@link QuerierPool.withQuerier} or `await using`. Releasing a
|
|
134
|
+
* connection this method never acquired is what forced every caller to know whether it still owned
|
|
135
|
+
* one afterwards.
|
|
136
|
+
*/
|
|
120
137
|
transaction<T>(callback: () => Promise<T>, opts?: TransactionOptions): Promise<T>;
|
|
121
138
|
/**
|
|
122
139
|
* Emit a lifecycle hook event for the given entity.
|
|
@@ -132,9 +149,20 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
132
149
|
* @returns A promise that resolves with the task's result.
|
|
133
150
|
*/
|
|
134
151
|
protected serialize<T>(task: () => Promise<T>): Promise<T>;
|
|
152
|
+
/**
|
|
153
|
+
* Runs `task`, logs `query` with how long it took, and tags any error it throws with that query.
|
|
154
|
+
*
|
|
155
|
+
* A method rather than the `@Log()` decorator it replaces. A standard-spec method decorator works by
|
|
156
|
+
* returning a replacement function, and a replacement cannot carry the original's type parameters, so
|
|
157
|
+
* decorating `internalFindMany<E extends Document>` made its signature unresolvable. Most of the query
|
|
158
|
+
* surface is generic like that, and wrapping at the call site costs one line while keeping the
|
|
159
|
+
* signature intact.
|
|
160
|
+
*/
|
|
161
|
+
protected timed<T>(query: string, values: unknown[] | undefined, task: () => Promise<T>): Promise<T>;
|
|
135
162
|
abstract beginTransaction(opts?: TransactionOptions): Promise<void>;
|
|
136
163
|
abstract commitTransaction(): Promise<void>;
|
|
137
164
|
abstract rollbackTransaction(): Promise<void>;
|
|
138
165
|
protected abstract internalRelease(): Promise<void>;
|
|
139
166
|
release(): Promise<void>;
|
|
167
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
140
168
|
}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { getMeta } from '../entity/decorator/index.js';
|
|
1
|
+
import { getMeta } from '../entity/index.js';
|
|
11
2
|
import { asSelectMap, augmentWhere, clone, filterPersistableRelationKeys, forEachRequestedRelation, getKeys, getRelationRequestSummary, LoggerWrapper, parseRelationAtKey, parseRelationQueryValue, runHooks, } from '../util/index.js';
|
|
12
|
-
import {
|
|
3
|
+
import { enrichError } from './queryError.js';
|
|
13
4
|
/**
|
|
14
5
|
* Base class for all database queriers.
|
|
15
6
|
* It provides a standardized way to execute tasks serially to prevent race conditions on database connections.
|
|
@@ -366,6 +357,23 @@ export class AbstractQuerier {
|
|
|
366
357
|
const referenceId = await this.insertOne(relEntity, relPayload);
|
|
367
358
|
await this.updateOneById(entity, id, { [localField]: referenceId });
|
|
368
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Runs `callback` in a transaction: begin, commit on success, roll back on failure.
|
|
362
|
+
*
|
|
363
|
+
* The single place that sequence is written; everything else delegates here, because both subtleties
|
|
364
|
+
* below were got wrong by code that hand-rolled it:
|
|
365
|
+
*
|
|
366
|
+
* - `beginTransaction` connects before it begins, so a refused connection lands in the catch with no
|
|
367
|
+
* transaction open. Rolling back regardless threw `not a pending transaction`, and that replaced the
|
|
368
|
+
* real cause: a wrong password surfaced as a transaction-state error.
|
|
369
|
+
* - A rollback that fails too is a consequence of the original failure, not news, so it must not
|
|
370
|
+
* replace it either.
|
|
371
|
+
*
|
|
372
|
+
* The connection is **not** released here: whoever took it from the pool gives it back, through
|
|
373
|
+
* {@link QuerierPool.transaction}, {@link QuerierPool.withQuerier} or `await using`. Releasing a
|
|
374
|
+
* connection this method never acquired is what forced every caller to know whether it still owned
|
|
375
|
+
* one afterwards.
|
|
376
|
+
*/
|
|
369
377
|
async transaction(callback, opts) {
|
|
370
378
|
if (this.hasOpenTransaction) {
|
|
371
379
|
return callback();
|
|
@@ -377,12 +385,11 @@ export class AbstractQuerier {
|
|
|
377
385
|
return res;
|
|
378
386
|
}
|
|
379
387
|
catch (err) {
|
|
380
|
-
|
|
388
|
+
if (this.hasOpenTransaction) {
|
|
389
|
+
await this.rollbackTransaction().catch(() => { });
|
|
390
|
+
}
|
|
381
391
|
throw err;
|
|
382
392
|
}
|
|
383
|
-
finally {
|
|
384
|
-
await this.release();
|
|
385
|
-
}
|
|
386
393
|
}
|
|
387
394
|
/**
|
|
388
395
|
* Emit a lifecycle hook event for the given entity.
|
|
@@ -428,13 +435,31 @@ export class AbstractQuerier {
|
|
|
428
435
|
this.taskQueue = res.catch(() => { });
|
|
429
436
|
return res;
|
|
430
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Runs `task`, logs `query` with how long it took, and tags any error it throws with that query.
|
|
440
|
+
*
|
|
441
|
+
* A method rather than the `@Log()` decorator it replaces. A standard-spec method decorator works by
|
|
442
|
+
* returning a replacement function, and a replacement cannot carry the original's type parameters, so
|
|
443
|
+
* decorating `internalFindMany<E extends Document>` made its signature unresolvable. Most of the query
|
|
444
|
+
* surface is generic like that, and wrapping at the call site costs one line while keeping the
|
|
445
|
+
* signature intact.
|
|
446
|
+
*/
|
|
447
|
+
async timed(query, values, task) {
|
|
448
|
+
const startTime = performance.now();
|
|
449
|
+
try {
|
|
450
|
+
return await task();
|
|
451
|
+
}
|
|
452
|
+
catch (err) {
|
|
453
|
+
throw enrichError(err, this.logger, query, values);
|
|
454
|
+
}
|
|
455
|
+
finally {
|
|
456
|
+
this.logger.logQuery(query, values, Math.round(performance.now() - startTime));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
431
459
|
async release() {
|
|
432
|
-
return this.internalRelease();
|
|
460
|
+
return this.serialize(() => this.internalRelease());
|
|
461
|
+
}
|
|
462
|
+
async [Symbol.asyncDispose]() {
|
|
463
|
+
return this.release();
|
|
433
464
|
}
|
|
434
465
|
}
|
|
435
|
-
__decorate([
|
|
436
|
-
Serialized(),
|
|
437
|
-
__metadata("design:type", Function),
|
|
438
|
-
__metadata("design:paramtypes", []),
|
|
439
|
-
__metadata("design:returntype", Promise)
|
|
440
|
-
], AbstractQuerier.prototype, "release", null);
|
|
@@ -13,6 +13,9 @@ export declare abstract class AbstractQuerierPool<Q extends Querier, D extends A
|
|
|
13
13
|
abstract getQuerier(): Promise<Q>;
|
|
14
14
|
/**
|
|
15
15
|
* get a querier from the pool and run the given callback inside a transaction.
|
|
16
|
+
*
|
|
17
|
+
* The pool acquired the connection, so the pool releases it: `withQuerier` owns that half and
|
|
18
|
+
* `querier.transaction` owns begin/commit/rollback. Neither knows about the other's job.
|
|
16
19
|
*/
|
|
17
20
|
transaction<T>(callback: (querier: Q) => Promise<T>, opts?: TransactionOptions & PoolRunOptions): Promise<T>;
|
|
18
21
|
/**
|
|
@@ -11,10 +11,12 @@ export class AbstractQuerierPool {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* get a querier from the pool and run the given callback inside a transaction.
|
|
14
|
+
*
|
|
15
|
+
* The pool acquired the connection, so the pool releases it: `withQuerier` owns that half and
|
|
16
|
+
* `querier.transaction` owns begin/commit/rollback. Neither knows about the other's job.
|
|
14
17
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return this.runScoped(opts?.context, () => querier.transaction(() => callback(querier), opts));
|
|
18
|
+
transaction(callback, opts) {
|
|
19
|
+
return this.withQuerier((querier) => querier.transaction(() => callback(querier), opts), opts);
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* get a querier from the pool, run the given callback, and release the querier.
|
|
@@ -28,13 +28,11 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
28
28
|
protected loadInsertIdIncrement(): Promise<number>;
|
|
29
29
|
/**
|
|
30
30
|
* Hook for subclasses (e.g. pool queriers) to establish a connection.
|
|
31
|
-
* Called before every query but outside the
|
|
31
|
+
* Called before every query but outside the timing window.
|
|
32
32
|
*/
|
|
33
33
|
protected lazyConnect(): Promise<void>;
|
|
34
34
|
all<T>(query: string, values?: unknown[]): Promise<T[]>;
|
|
35
|
-
private timedAll;
|
|
36
35
|
run(query: string, values?: unknown[]): Promise<QueryUpdateResult>;
|
|
37
|
-
private timedRun;
|
|
38
36
|
protected internalFindMany<E extends object>(entity: Type<E>, q: Query<E>, opts?: QueryOptions): Promise<E[]>;
|
|
39
37
|
protected internalFindManyStream<E extends object>(entity: Type<E>, q: Query<E>, opts?: QueryOptions): AsyncGenerator<Awaited<E>, void, unknown>;
|
|
40
38
|
/**
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
1
|
import { getMeta } from '../entity/index.js';
|
|
11
2
|
import { buildUpdateResult, clone, getInsertFieldKeys, getRelationRequestSummary, isAutoIncrement, obtainAttrsPaths, throwNoPendingTransaction, throwPendingTransaction, unflatObject, unflatObjects, withoutSoftDeleteFilter, } from '../util/index.js';
|
|
12
3
|
import { AbstractQuerier } from './abstractQuerier.js';
|
|
13
|
-
import { enrichError
|
|
4
|
+
import { enrichError } from './queryError.js';
|
|
14
5
|
export class AbstractSqlQuerier extends AbstractQuerier {
|
|
15
6
|
dialect;
|
|
16
7
|
extra;
|
|
@@ -44,22 +35,20 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
44
35
|
}
|
|
45
36
|
/**
|
|
46
37
|
* Hook for subclasses (e.g. pool queriers) to establish a connection.
|
|
47
|
-
* Called before every query but outside the
|
|
38
|
+
* Called before every query but outside the timing window.
|
|
48
39
|
*/
|
|
49
40
|
async lazyConnect() { }
|
|
50
41
|
async all(query, values) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return this.internalAll(query, this.dialect.normalizeValues(values));
|
|
42
|
+
return this.serialize(async () => {
|
|
43
|
+
await this.lazyConnect();
|
|
44
|
+
return this.timed(query, values, () => this.internalAll(query, this.dialect.normalizeValues(values)));
|
|
45
|
+
});
|
|
56
46
|
}
|
|
57
47
|
async run(query, values) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return this.internalRun(query, this.dialect.normalizeValues(values));
|
|
48
|
+
return this.serialize(async () => {
|
|
49
|
+
await this.lazyConnect();
|
|
50
|
+
return this.timed(query, values, () => this.internalRun(query, this.dialect.normalizeValues(values)));
|
|
51
|
+
});
|
|
63
52
|
}
|
|
64
53
|
async internalFindMany(entity, q, opts) {
|
|
65
54
|
const ctx = this.dialect.createContext();
|
|
@@ -86,7 +75,7 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
86
75
|
}
|
|
87
76
|
}
|
|
88
77
|
catch (err) {
|
|
89
|
-
enrichError(err, this.logger, ctx.sql, normalizedParams);
|
|
78
|
+
throw enrichError(err, this.logger, ctx.sql, normalizedParams);
|
|
90
79
|
}
|
|
91
80
|
}
|
|
92
81
|
/**
|
|
@@ -243,85 +232,48 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
243
232
|
return !!this.hasPendingTransaction;
|
|
244
233
|
}
|
|
245
234
|
async beginTransaction(opts) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
await this.lazyConnect();
|
|
250
|
-
const statements = this.dialect.getBeginTransactionStatements(opts?.isolationLevel);
|
|
251
|
-
for (const sql of statements) {
|
|
252
|
-
try {
|
|
253
|
-
await this.internalRun(sql);
|
|
235
|
+
return this.serialize(async () => {
|
|
236
|
+
if (this.hasPendingTransaction) {
|
|
237
|
+
throwPendingTransaction();
|
|
254
238
|
}
|
|
255
|
-
|
|
256
|
-
|
|
239
|
+
await this.lazyConnect();
|
|
240
|
+
for (const sql of this.dialect.getBeginTransactionStatements(opts?.isolationLevel)) {
|
|
241
|
+
try {
|
|
242
|
+
await this.internalRun(sql);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
throw enrichError(err, this.logger, sql);
|
|
246
|
+
}
|
|
257
247
|
}
|
|
258
|
-
|
|
259
|
-
|
|
248
|
+
this.hasPendingTransaction = true;
|
|
249
|
+
});
|
|
260
250
|
}
|
|
261
251
|
async commitTransaction() {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
252
|
+
return this.serialize(async () => {
|
|
253
|
+
if (!this.hasPendingTransaction) {
|
|
254
|
+
throwNoPendingTransaction();
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
await this.internalRun(this.dialect.commitTransactionCommand);
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
throw enrichError(err, this.logger, this.dialect.commitTransactionCommand);
|
|
261
|
+
}
|
|
262
|
+
this.hasPendingTransaction = false;
|
|
263
|
+
});
|
|
272
264
|
}
|
|
273
265
|
async rollbackTransaction() {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
266
|
+
return this.serialize(async () => {
|
|
267
|
+
if (!this.hasPendingTransaction) {
|
|
268
|
+
throwNoPendingTransaction();
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
await this.internalRun(this.dialect.rollbackTransactionCommand);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
throw enrichError(err, this.logger, this.dialect.rollbackTransactionCommand);
|
|
275
|
+
}
|
|
276
|
+
this.hasPendingTransaction = false;
|
|
277
|
+
});
|
|
284
278
|
}
|
|
285
279
|
}
|
|
286
|
-
__decorate([
|
|
287
|
-
Serialized(),
|
|
288
|
-
__metadata("design:type", Function),
|
|
289
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
290
|
-
__metadata("design:returntype", Promise)
|
|
291
|
-
], AbstractSqlQuerier.prototype, "all", null);
|
|
292
|
-
__decorate([
|
|
293
|
-
Log(),
|
|
294
|
-
__metadata("design:type", Function),
|
|
295
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
296
|
-
__metadata("design:returntype", Promise)
|
|
297
|
-
], AbstractSqlQuerier.prototype, "timedAll", null);
|
|
298
|
-
__decorate([
|
|
299
|
-
Serialized(),
|
|
300
|
-
__metadata("design:type", Function),
|
|
301
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
302
|
-
__metadata("design:returntype", Promise)
|
|
303
|
-
], AbstractSqlQuerier.prototype, "run", null);
|
|
304
|
-
__decorate([
|
|
305
|
-
Log(),
|
|
306
|
-
__metadata("design:type", Function),
|
|
307
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
308
|
-
__metadata("design:returntype", Promise)
|
|
309
|
-
], AbstractSqlQuerier.prototype, "timedRun", null);
|
|
310
|
-
__decorate([
|
|
311
|
-
Serialized(),
|
|
312
|
-
__metadata("design:type", Function),
|
|
313
|
-
__metadata("design:paramtypes", [Object]),
|
|
314
|
-
__metadata("design:returntype", Promise)
|
|
315
|
-
], AbstractSqlQuerier.prototype, "beginTransaction", null);
|
|
316
|
-
__decorate([
|
|
317
|
-
Serialized(),
|
|
318
|
-
__metadata("design:type", Function),
|
|
319
|
-
__metadata("design:paramtypes", []),
|
|
320
|
-
__metadata("design:returntype", Promise)
|
|
321
|
-
], AbstractSqlQuerier.prototype, "commitTransaction", null);
|
|
322
|
-
__decorate([
|
|
323
|
-
Serialized(),
|
|
324
|
-
__metadata("design:type", Function),
|
|
325
|
-
__metadata("design:paramtypes", []),
|
|
326
|
-
__metadata("design:returntype", Promise)
|
|
327
|
-
], AbstractSqlQuerier.prototype, "rollbackTransaction", null);
|
package/dist/querier/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export * from './abstractQuerier.js';
|
|
|
2
2
|
export * from './abstractQuerierPool.js';
|
|
3
3
|
export * from './abstractSqlQuerier.js';
|
|
4
4
|
export * from './abstractSqlQuerierPool.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './querierContext.js';
|
|
6
|
+
export * from './queryError.js';
|
|
7
|
+
export * from './transactional.js';
|
package/dist/querier/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export * from './abstractQuerier.js';
|
|
|
2
2
|
export * from './abstractQuerierPool.js';
|
|
3
3
|
export * from './abstractSqlQuerier.js';
|
|
4
4
|
export * from './abstractSqlQuerierPool.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './querierContext.js';
|
|
6
|
+
export * from './queryError.js';
|
|
7
|
+
export * from './transactional.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Querier } from '../type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Browser build of the transactional querier context: bundlers targeting the browser resolve
|
|
4
|
+
* `querierContext.ts` to this file (see the `browser` map in package.json), keeping the root entrypoint
|
|
5
|
+
* free of `node:async_hooks`.
|
|
6
|
+
*
|
|
7
|
+
* Nothing in a browser bundle opens a transaction. The browser querier serializes queries over HTTP and
|
|
8
|
+
* the server owns the transaction, so there is no ambient querier to hand out and no flow to track.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withQuerierContext<T>(_querier: Querier, callback: () => T): T;
|
|
11
|
+
export declare function currentQuerier(): Querier;
|
|
12
|
+
export declare function currentQuerierIfAny(): Querier | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser build of the transactional querier context: bundlers targeting the browser resolve
|
|
3
|
+
* `querierContext.ts` to this file (see the `browser` map in package.json), keeping the root entrypoint
|
|
4
|
+
* free of `node:async_hooks`.
|
|
5
|
+
*
|
|
6
|
+
* Nothing in a browser bundle opens a transaction. The browser querier serializes queries over HTTP and
|
|
7
|
+
* the server owns the transaction, so there is no ambient querier to hand out and no flow to track.
|
|
8
|
+
*/
|
|
9
|
+
export function withQuerierContext(_querier, callback) {
|
|
10
|
+
return callback();
|
|
11
|
+
}
|
|
12
|
+
export function currentQuerier() {
|
|
13
|
+
throw new TypeError('currentQuerier() is server-only: transactions run on the server, and the browser querier sends each ' +
|
|
14
|
+
'request over HTTP. Call it from server code, or use the querier you already have.');
|
|
15
|
+
}
|
|
16
|
+
export function currentQuerierIfAny() {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Querier } from '../type/index.js';
|
|
2
|
+
/** Runs `callback` with `querier` as the ambient one, for the whole async flow beneath it. */
|
|
3
|
+
export declare function withQuerierContext<T>(querier: Querier, callback: () => T): T;
|
|
4
|
+
/**
|
|
5
|
+
* The querier of the enclosing `@Transactional()` method.
|
|
6
|
+
*
|
|
7
|
+
* This is what replaced `@InjectQuerier()`: the standard decorator spec has no parameter decorators, so
|
|
8
|
+
* the querier can no longer be injected into an argument and is read from the ambient flow instead.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class UserService {
|
|
13
|
+
* @Transactional()
|
|
14
|
+
* async register(data: Partial<User>) {
|
|
15
|
+
* await currentQuerier().insertOne(User, data);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function currentQuerier(): Querier;
|
|
21
|
+
/** The ambient querier, or `undefined` outside a transaction. For callers that can work without one. */
|
|
22
|
+
export declare function currentQuerierIfAny(): Querier | undefined;
|