uql-orm 0.99.0 → 0.100.1
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.md +22 -0
- package/README.md +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +5 -5
- package/dist/bunSql/bunSql.util.js +2 -2
- package/dist/bunSql/bunSqlQuerier.js +0 -1
- package/dist/bunSql/bunSqlQuerierPool.js +1 -1
- package/dist/cockroachdb/cockroachDialect.js +1 -0
- package/dist/context/context.browser.d.ts +5 -0
- package/dist/context/context.browser.js +21 -11
- package/dist/context/context.d.ts +5 -0
- package/dist/context/context.js +8 -3
- package/dist/dialect/abstractDialect.js +4 -2
- package/dist/dialect/abstractSqlDialect.d.ts +5 -5
- package/dist/dialect/abstractSqlDialect.js +26 -18
- package/dist/dialect/aliases.d.ts +0 -2
- package/dist/dialect/aliases.js +0 -2
- package/dist/dialect/hydrateColumn.d.ts +3 -3
- package/dist/dialect/hydrateColumn.js +1 -0
- package/dist/dialect/index.js +0 -2
- package/dist/dialect/jsonSql.d.ts +2 -3
- package/dist/dialect/jsonSql.js +4 -6
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +1 -1
- package/dist/dialect/mysqlLikeSqlDialect.js +5 -3
- package/dist/dialect/operators.d.ts +2 -3
- package/dist/dialect/operators.js +3 -4
- package/dist/dialect/pgLikeSqlDialect.js +12 -12
- package/dist/entity/decorator/members.d.ts +4 -12
- package/dist/entity/metadata/definition.js +8 -5
- package/dist/http/handler.d.ts +6 -6
- package/dist/http/handler.js +20 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -5
- package/dist/{maria → mariadb}/mariadbQuerier.js +1 -1
- package/dist/migrate/builder/columnBuilder.d.ts +3 -3
- package/dist/migrate/builder/columnBuilder.js +1 -1
- package/dist/migrate/builder/index.d.ts +0 -3
- package/dist/migrate/builder/index.js +0 -3
- package/dist/migrate/builder/migrationBuilder.d.ts +6 -6
- package/dist/migrate/builder/migrationBuilder.js +7 -7
- package/dist/migrate/builder/tableBuilder.d.ts +25 -25
- package/dist/migrate/builder/tableBuilder.js +5 -5
- package/dist/migrate/builder/types.d.ts +37 -37
- package/dist/migrate/cli-config.d.ts +11 -1
- package/dist/migrate/cli-config.js +20 -6
- package/dist/migrate/cli.js +9 -18
- package/dist/migrate/codegen/entityCodeGenerator.js +1 -1
- package/dist/migrate/codegen/migrationFile.d.ts +7 -7
- package/dist/migrate/codegen/migrationFile.js +11 -12
- package/dist/migrate/ddl/indexCapabilities.d.ts +2 -0
- package/dist/migrate/ddl/indexCapabilities.js +6 -0
- package/dist/migrate/ddl/indexDdl.d.ts +8 -0
- package/dist/migrate/ddl/indexDdl.js +22 -6
- package/dist/migrate/generator/definitionToNode.d.ts +1 -1
- package/dist/migrate/generator/definitionToNode.js +1 -1
- package/dist/migrate/index.d.ts +1 -3
- package/dist/migrate/index.js +0 -3
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +11 -15
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +13 -15
- package/dist/migrate/introspection/mssqlIntrospector.d.ts +5 -5
- package/dist/migrate/introspection/mssqlIntrospector.js +24 -28
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +5 -5
- package/dist/migrate/introspection/mysqlIntrospector.js +31 -37
- package/dist/migrate/introspection/postgresIntrospector.d.ts +13 -13
- package/dist/migrate/introspection/postgresIntrospector.js +35 -39
- package/dist/migrate/introspection/registry.js +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +6 -4
- package/dist/migrate/introspection/sqliteIntrospector.js +15 -12
- package/dist/migrate/migrationLock.d.ts +38 -0
- package/dist/migrate/migrationLock.js +103 -0
- package/dist/migrate/migrationTarget.d.ts +6 -2
- package/dist/migrate/migrationTarget.js +30 -14
- package/dist/migrate/migrator.d.ts +39 -23
- package/dist/migrate/migrator.js +110 -74
- package/dist/migrate/schemaGenerator.d.ts +3 -1
- package/dist/migrate/schemaGenerator.js +14 -5
- package/dist/migrate/storage/databaseStorage.d.ts +28 -20
- package/dist/migrate/storage/databaseStorage.js +36 -54
- package/dist/migrate/storage/index.d.ts +0 -1
- package/dist/migrate/storage/index.js +0 -1
- package/dist/{mongo → mongodb}/index.d.ts +0 -1
- package/dist/{mongo → mongodb}/index.js +0 -1
- package/dist/{mongo → mongodb}/mongoCommand.d.ts +17 -1
- package/dist/{mongo → mongodb}/mongoCommand.js +15 -2
- package/dist/{mongo → mongodb}/mongoDialect.js +8 -12
- package/dist/{mongo → mongodb}/mongoIntrospector.js +12 -3
- package/dist/{mongo → mongodb}/mongoMigrationStorage.d.ts +5 -5
- package/dist/{mongo → mongodb}/mongoMigrationStorage.js +8 -12
- package/dist/{mongo → mongodb}/mongoQuerier.d.ts +3 -1
- package/dist/{mongo → mongodb}/mongoSchemaGenerator.d.ts +11 -1
- package/dist/{mongo → mongodb}/mongoSchemaGenerator.js +56 -11
- package/dist/{mongo → mongodb}/mongodbQuerier.d.ts +7 -18
- package/dist/{mongo → mongodb}/mongodbQuerier.js +44 -78
- package/dist/mssql/mssqlDialect.d.ts +6 -4
- package/dist/mssql/mssqlDialect.js +20 -10
- package/dist/mssql/mssqlQuerier.d.ts +2 -2
- package/dist/mssql/mssqlQuerier.js +3 -3
- package/dist/mssql/mssqlQuerierPool.d.ts +1 -1
- package/dist/mssql/mssqlQuerierPool.js +2 -2
- package/dist/mysql/mysql2Querier.js +1 -5
- package/dist/namingStrategy/defaultNamingStrategy.d.ts +0 -1
- package/dist/namingStrategy/defaultNamingStrategy.js +0 -3
- package/dist/pglite/pgliteDialect.d.ts +3 -0
- package/dist/pglite/pgliteDialect.js +3 -1
- package/dist/pglite/pgliteQuerier.d.ts +2 -0
- package/dist/pglite/pgliteQuerier.js +4 -0
- package/dist/postgres/postgresDialect.d.ts +3 -4
- package/dist/postgres/postgresDialect.js +5 -6
- package/dist/querier/abstractQuerier.d.ts +119 -36
- package/dist/querier/abstractQuerier.js +465 -161
- package/dist/querier/abstractQuerierPool.d.ts +5 -6
- package/dist/querier/abstractQuerierPool.js +20 -6
- package/dist/querier/abstractSqlQuerier.d.ts +15 -10
- package/dist/querier/abstractSqlQuerier.js +54 -47
- package/dist/querier/abstractSqlQuerierPool.d.ts +5 -3
- package/dist/querier/abstractSqlQuerierPool.js +7 -4
- package/dist/querier/transaction.d.ts +46 -0
- package/dist/querier/transaction.js +56 -0
- package/dist/schema/canonicalType.js +2 -2
- package/dist/schema/schemaASTDiffer.d.ts +11 -3
- package/dist/schema/schemaASTDiffer.js +20 -8
- package/dist/sqlite/nodeSqliteQuerierPool.d.ts +1 -1
- package/dist/sqlite/nodeSqliteQuerierPool.js +1 -1
- package/dist/sqlite/sqliteDialect.d.ts +1 -1
- package/dist/sqlite/sqliteDialect.js +3 -1
- package/dist/sqlite/sqliteQuerier.d.ts +2 -0
- package/dist/sqlite/sqliteQuerier.js +4 -0
- package/dist/sqlite/sqliteQuerierPool.d.ts +4 -4
- package/dist/sqlite/sqliteQuerierPool.js +1 -1
- package/dist/type/dialect.d.ts +16 -2
- package/dist/type/entity.d.ts +32 -32
- package/dist/type/migration.d.ts +10 -27
- package/dist/type/namingStrategy.d.ts +0 -4
- package/dist/type/querier.d.ts +18 -10
- package/dist/type/query.d.ts +7 -22
- package/dist/type/queryRaw.d.ts +11 -6
- package/dist/type/queryRaw.js +2 -3
- package/dist/type/universalQuerier.d.ts +26 -28
- package/dist/type/utility.d.ts +7 -2
- package/dist/util/dialect.util.d.ts +2 -2
- package/dist/util/dialect.util.js +4 -1
- package/dist/util/field.util.d.ts +12 -0
- package/dist/util/field.util.js +24 -0
- package/dist/util/hook.util.d.ts +3 -2
- package/dist/util/query.util.d.ts +5 -0
- package/dist/util/query.util.js +34 -1
- package/dist/util/raw.d.ts +8 -2
- package/dist/util/raw.js +22 -0
- package/dist/util/relationQuery.util.d.ts +2 -0
- package/dist/util/relationQuery.util.js +4 -0
- package/dist/util/sql.util.d.ts +0 -5
- package/dist/util/sql.util.js +3 -9
- package/dist/util/uqlError.d.ts +0 -6
- package/dist/util/uqlError.js +0 -5
- package/package.json +20 -26
- package/skills/uql-orm/SKILL.md +13 -10
- package/dist/migrate/storage/jsonStorage.d.ts +0 -14
- package/dist/migrate/storage/jsonStorage.js +0 -33
- /package/dist/{maria → mariadb}/index.d.ts +0 -0
- /package/dist/{maria → mariadb}/index.js +0 -0
- /package/dist/{maria → mariadb}/mariaDialect.d.ts +0 -0
- /package/dist/{maria → mariadb}/mariaDialect.js +0 -0
- /package/dist/{maria → mariadb}/mariadbQuerier.d.ts +0 -0
- /package/dist/{maria → mariadb}/mariadbQuerierPool.d.ts +0 -0
- /package/dist/{maria → mariadb}/mariadbQuerierPool.js +0 -0
- /package/dist/{mongo → mongodb}/mongoDialect.d.ts +0 -0
- /package/dist/{mongo → mongodb}/mongoIntrospector.d.ts +0 -0
- /package/dist/{mongo → mongodb}/mongoQuerier.js +0 -0
- /package/dist/{mongo → mongodb}/mongodbQuerierPool.d.ts +0 -0
- /package/dist/{mongo → mongodb}/mongodbQuerierPool.js +0 -0
- /package/dist/{mongo → mongodb}/textLanguage.d.ts +0 -0
- /package/dist/{mongo → mongodb}/textLanguage.js +0 -0
- /package/dist/{mongo → mongodb}/vectorDistance.d.ts +0 -0
- /package/dist/{mongo → mongodb}/vectorDistance.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RelationRows } from '../dialect/abstractSqlDialect.js';
|
|
2
2
|
import { type JsonAccessMode, type JsonSlot } from '../dialect/jsonSql.js';
|
|
3
3
|
import { MergeSqlDialect } from '../dialect/mergeSqlDialect.js';
|
|
4
|
-
import type { EntityMeta, FieldOptions, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryPager, SqlDialectFeatures, SqlValues, TriggerRows, Type, UpdatePayload, VectorDistance, VectorMetric } from '../type/index.js';
|
|
4
|
+
import type { EntityMeta, SavepointCommand, FieldOptions, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryPager, SqlDialectFeatures, SqlValues, TriggerRows, Type, UpdatePayload, VectorDistance, VectorMetric } from '../type/index.js';
|
|
5
5
|
/** Microsoft SQL Server 2017 and up. Identifiers are `"`-quoted, the ANSI spelling `tedious` enables. */
|
|
6
6
|
export declare class MsSqlDialect extends MergeSqlDialect {
|
|
7
7
|
#private;
|
|
@@ -11,11 +11,13 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
11
11
|
readonly beginTransactionCommand = "BEGIN TRANSACTION";
|
|
12
12
|
readonly commitTransactionCommand = "COMMIT TRANSACTION";
|
|
13
13
|
readonly rollbackTransactionCommand = "ROLLBACK TRANSACTION";
|
|
14
|
+
/** SQL Server saves a transaction under a name and rolls back to it, and releases none: the commit does. */
|
|
15
|
+
savepointStatement(command: SavepointCommand, name: string): string;
|
|
14
16
|
/**
|
|
15
17
|
* T-SQL has no inline form, so the level is set before the `BEGIN`. What a driver that sends these
|
|
16
18
|
* as statements would run; `MsSqlQuerier` opens its transactions through the driver instead.
|
|
17
19
|
*/
|
|
18
|
-
readonly isolationLevelStrategy = "
|
|
20
|
+
readonly isolationLevelStrategy = "setBefore";
|
|
19
21
|
readonly booleanLiteral = "integer";
|
|
20
22
|
/**
|
|
21
23
|
* The clock in UTC, since `CURRENT_TIMESTAMP` is local time in the server's zone. No v7: `NEWSEQUENTIALID()` is
|
|
@@ -28,7 +30,7 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
28
30
|
readonly maxBindValues = 2098;
|
|
29
31
|
readonly maxInsertRows = 1000;
|
|
30
32
|
/** `OUTPUT` has no trailing form: it sits between the target and its rows. */
|
|
31
|
-
readonly returningPosition = "
|
|
33
|
+
readonly returningPosition = "afterTarget";
|
|
32
34
|
/** `OUTPUT` reads the written row off the `INSERTED` pseudo-table. */
|
|
33
35
|
protected readonly returnedRowPrefix = "INSERTED.";
|
|
34
36
|
/** Holds the update key lock across the insert; without it two concurrent upserts of one key race. */
|
|
@@ -49,7 +51,7 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
49
51
|
insert<E>(ctx: QueryContext, entity: Type<E>, payload: E | E[], opts?: QueryOptions): void;
|
|
50
52
|
/** The table to toggle, or nothing when no record writes a key the engine would have generated. */
|
|
51
53
|
private identityInsertTarget;
|
|
52
|
-
/**
|
|
54
|
+
/** An exact decimal, converted before it crosses the wire, where `tedious` would round it. */
|
|
53
55
|
protected selectFieldExpr(escapedColumn: string, field: FieldOptions): string;
|
|
54
56
|
/**
|
|
55
57
|
* The rows read as they are, `FOR JSON PATH` making the array. It nests a dotted key and leaves a
|
|
@@ -4,11 +4,11 @@ import { BYTES_PREFIX } from '../dialect/hydrateColumn.js';
|
|
|
4
4
|
import { jsonArraySlotArgs, jsonPath, jsonSlotArgs } from '../dialect/jsonSql.js';
|
|
5
5
|
import { MergeSqlDialect } from '../dialect/mergeSqlDialect.js';
|
|
6
6
|
import { getMeta } from '../entity/index.js';
|
|
7
|
-
import { canonicalToSql,
|
|
7
|
+
import { canonicalToSql, resolveColumnCanonicalType } from '../schema/canonicalType.js';
|
|
8
8
|
import { QueryRaw } from '../type/index.js';
|
|
9
9
|
import { parseQueryLock } from '../type/index.js';
|
|
10
10
|
import { bytesToHex } from '../util/bytes.js';
|
|
11
|
-
import { isAutoIncrement } from '../util/field.util.js';
|
|
11
|
+
import { isAutoIncrement, isExactDecimal, jsonPathKeys } from '../util/field.util.js';
|
|
12
12
|
import { assertNonNegativeInteger } from '../util/index.js';
|
|
13
13
|
import { escapeSingleQuotes } from '../util/sqlLiteral.js';
|
|
14
14
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
@@ -26,6 +26,7 @@ const MSSQL_FEATURES = {
|
|
|
26
26
|
supportsTimestamptz: false,
|
|
27
27
|
stringSizing: 'varchar',
|
|
28
28
|
supportsUnsigned: false,
|
|
29
|
+
jsonArrivesDecoded: false,
|
|
29
30
|
serverSideCursors: false,
|
|
30
31
|
correlatedWrites: true,
|
|
31
32
|
rowLocks: { of: true, withWindow: true, placement: 'tableHint' },
|
|
@@ -48,6 +49,7 @@ const MSSQL_FEATURES = {
|
|
|
48
49
|
before: false,
|
|
49
50
|
deferrable: false,
|
|
50
51
|
},
|
|
52
|
+
namedLocks: 'transaction',
|
|
51
53
|
};
|
|
52
54
|
/** The `type` `OPENJSON` reports for the JSON scalar an element is compared with; anything else binds as a string. */
|
|
53
55
|
function openJsonType(value) {
|
|
@@ -78,11 +80,20 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
78
80
|
beginTransactionCommand = 'BEGIN TRANSACTION';
|
|
79
81
|
commitTransactionCommand = 'COMMIT TRANSACTION';
|
|
80
82
|
rollbackTransactionCommand = 'ROLLBACK TRANSACTION';
|
|
83
|
+
/** SQL Server saves a transaction under a name and rolls back to it, and releases none: the commit does. */
|
|
84
|
+
savepointStatement(command, name) {
|
|
85
|
+
const statements = {
|
|
86
|
+
open: `SAVE TRANSACTION ${name}`,
|
|
87
|
+
release: '',
|
|
88
|
+
rollback: `ROLLBACK TRANSACTION ${name}`,
|
|
89
|
+
};
|
|
90
|
+
return statements[command];
|
|
91
|
+
}
|
|
81
92
|
/**
|
|
82
93
|
* T-SQL has no inline form, so the level is set before the `BEGIN`. What a driver that sends these
|
|
83
94
|
* as statements would run; `MsSqlQuerier` opens its transactions through the driver instead.
|
|
84
95
|
*/
|
|
85
|
-
isolationLevelStrategy = '
|
|
96
|
+
isolationLevelStrategy = 'setBefore';
|
|
86
97
|
booleanLiteral = 'integer';
|
|
87
98
|
/**
|
|
88
99
|
* The clock in UTC, since `CURRENT_TIMESTAMP` is local time in the server's zone. No v7: `NEWSEQUENTIALID()` is
|
|
@@ -102,7 +113,7 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
102
113
|
maxBindValues = 2098;
|
|
103
114
|
maxInsertRows = 1000;
|
|
104
115
|
/** `OUTPUT` has no trailing form: it sits between the target and its rows. */
|
|
105
|
-
returningPosition = '
|
|
116
|
+
returningPosition = 'afterTarget';
|
|
106
117
|
/** `OUTPUT` reads the written row off the `INSERTED` pseudo-table. */
|
|
107
118
|
returnedRowPrefix = 'INSERTED.';
|
|
108
119
|
/** Holds the update key lock across the insert; without it two concurrent upserts of one key race. */
|
|
@@ -142,10 +153,9 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
142
153
|
const stated = records.some((record) => record[id.key] !== undefined);
|
|
143
154
|
return stated ? this.escapedTableName(meta) : undefined;
|
|
144
155
|
}
|
|
145
|
-
/**
|
|
156
|
+
/** An exact decimal, converted before it crosses the wire, where `tedious` would round it. */
|
|
146
157
|
selectFieldExpr(escapedColumn, field) {
|
|
147
|
-
|
|
148
|
-
return exactDecimal ? `CONVERT(NVARCHAR(41), ${escapedColumn})` : escapedColumn;
|
|
158
|
+
return isExactDecimal(field) ? `CONVERT(NVARCHAR(41), ${escapedColumn})` : escapedColumn;
|
|
149
159
|
}
|
|
150
160
|
/**
|
|
151
161
|
* The rows read as they are, `FOR JSON PATH` making the array. It nests a dotted key and leaves a
|
|
@@ -300,9 +310,9 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
300
310
|
if (!path) {
|
|
301
311
|
return escapedColumn;
|
|
302
312
|
}
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
const
|
|
313
|
+
const keys = jsonPathKeys(path);
|
|
314
|
+
const leaf = keys.pop();
|
|
315
|
+
const parent = ['$', ...keys].join('.');
|
|
306
316
|
return `(SELECT ${this.#elem.value} FROM OPENJSON(${escapedColumn}, '${parent}') WHERE ${this.#elem.key} = N'${leaf}')`;
|
|
307
317
|
}
|
|
308
318
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import mssql from 'mssql';
|
|
2
2
|
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
3
3
|
import type { QueryUpdateResult, RawRow, TransactionOptions } from '../type/index.js';
|
|
4
4
|
/** What `tedious` hands back for one statement, whichever shape it took. */
|
|
@@ -18,7 +18,7 @@ type MsSqlRowStream = AsyncIterable<RawRow> & {
|
|
|
18
18
|
/** The part of an `mssql` `Request` a querier drives. */
|
|
19
19
|
type MsSqlRequest = {
|
|
20
20
|
input(name: string, value: unknown): unknown;
|
|
21
|
-
input(name: string, type: typeof DateTime2, value: unknown): unknown;
|
|
21
|
+
input(name: string, type: typeof mssql.DateTime2, value: unknown): unknown;
|
|
22
22
|
query(command: string): Promise<MsSqlResult>;
|
|
23
23
|
toReadableStream(): MsSqlRowStream;
|
|
24
24
|
cancel(): unknown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import mssql from 'mssql';
|
|
2
2
|
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
3
3
|
import { decodeWireTypes } from './mssqlWireTypes.js';
|
|
4
4
|
/**
|
|
@@ -17,7 +17,7 @@ export class MsSqlQuerier extends AbstractPoolQuerier {
|
|
|
17
17
|
const request = this.#transaction ? this.#transaction.request() : this.getConn().request();
|
|
18
18
|
values?.forEach((value, index) => {
|
|
19
19
|
const name = `p${index + 1}`;
|
|
20
|
-
return value instanceof Date ? request.input(name, DateTime2, value) : request.input(name, value);
|
|
20
|
+
return value instanceof Date ? request.input(name, mssql.DateTime2, value) : request.input(name, value);
|
|
21
21
|
});
|
|
22
22
|
return request;
|
|
23
23
|
}
|
|
@@ -63,7 +63,7 @@ export class MsSqlQuerier extends AbstractPoolQuerier {
|
|
|
63
63
|
*/
|
|
64
64
|
async internalBegin(opts) {
|
|
65
65
|
const transaction = this.getConn().transaction();
|
|
66
|
-
await transaction.begin(opts?.isolationLevel && ISOLATION_LEVEL[ISOLATION[opts.isolationLevel]]);
|
|
66
|
+
await transaction.begin(opts?.isolationLevel && mssql.ISOLATION_LEVEL[ISOLATION[opts.isolationLevel]]);
|
|
67
67
|
this.#transaction = transaction;
|
|
68
68
|
}
|
|
69
69
|
async internalCommit() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConnectionPool, type config as MsSqlConfig } from 'mssql';
|
|
1
|
+
import { type ConnectionPool, type config as MsSqlConfig } from 'mssql';
|
|
2
2
|
import { AbstractSqlQuerierPool } from '../querier/index.js';
|
|
3
3
|
import type { ExtraOptions } from '../type/index.js';
|
|
4
4
|
import { MsSqlDialect } from './mssqlDialect.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import mssql, {} from 'mssql';
|
|
2
2
|
import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
|
|
3
3
|
import { AbstractSqlQuerierPool } from '../querier/index.js';
|
|
4
4
|
import { attachPoolErrorHandler } from '../util/index.js';
|
|
@@ -11,7 +11,7 @@ export class MsSqlQuerierPool extends AbstractSqlQuerierPool {
|
|
|
11
11
|
#connection;
|
|
12
12
|
constructor(opts, extra) {
|
|
13
13
|
super(new MsSqlDialect(dialectOptionsFrom(extra)), extra);
|
|
14
|
-
this.pool = new ConnectionPool(opts);
|
|
14
|
+
this.pool = new mssql.ConnectionPool(opts);
|
|
15
15
|
attachPoolErrorHandler(this.pool, 'Idle SQL Server pool connection encountered an error', extra?.logger);
|
|
16
16
|
}
|
|
17
17
|
async getQuerier() {
|
|
@@ -10,11 +10,7 @@ export class MySql2Querier extends AbstractPoolQuerier {
|
|
|
10
10
|
}
|
|
11
11
|
async internalRun(query, values) {
|
|
12
12
|
const [res] = await this.getConn().promise().query(query, values);
|
|
13
|
-
return this.buildUpdateResult({
|
|
14
|
-
changes: res.affectedRows,
|
|
15
|
-
id: res.insertId,
|
|
16
|
-
upsertStatus: res.affectedRows,
|
|
17
|
-
});
|
|
13
|
+
return this.buildUpdateResult({ changes: res.affectedRows, id: res.insertId });
|
|
18
14
|
}
|
|
19
15
|
async *internalStream(query, values) {
|
|
20
16
|
yield* this.getConn().query(query, values).stream();
|
|
@@ -5,5 +5,4 @@ import type { NamingStrategy } from '../type/index.js';
|
|
|
5
5
|
export declare class DefaultNamingStrategy implements NamingStrategy {
|
|
6
6
|
tableName(className: string): string;
|
|
7
7
|
columnName(propertyName: string): string;
|
|
8
|
-
joinTableName(source: string, target: string, _propertyName?: string): string;
|
|
9
8
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
+
import type { SqlDialectFeatures } from '../type/index.js';
|
|
2
3
|
/** Postgres as PGlite runs it, which binds fewer values per statement than a server. */
|
|
3
4
|
export declare class PgliteDialect extends PostgresDialect {
|
|
5
|
+
/** Every querier shares the one session, which an advisory lock it already holds never makes wait. */
|
|
6
|
+
readonly features: SqlDialectFeatures;
|
|
4
7
|
/** Past 32767 PGlite answers no rows, and wrong ones from then on, where a server takes 65535. */
|
|
5
8
|
readonly maxBindValues: number;
|
|
6
9
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
1
|
+
import { POSTGRES_FEATURES, PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
2
|
/** Postgres as PGlite runs it, which binds fewer values per statement than a server. */
|
|
3
3
|
export class PgliteDialect extends PostgresDialect {
|
|
4
|
+
/** Every querier shares the one session, which an advisory lock it already holds never makes wait. */
|
|
5
|
+
features = { ...POSTGRES_FEATURES, namedLocks: false };
|
|
4
6
|
/** Past 32767 PGlite answers no rows, and wrong ones from then on, where a server takes 65535. */
|
|
5
7
|
maxBindValues = 32767;
|
|
6
8
|
}
|
|
@@ -19,6 +19,8 @@ export declare class PgliteQuerier extends AbstractSqlQuerier {
|
|
|
19
19
|
readonly db: PgliteDatabase;
|
|
20
20
|
readonly extra?: ExtraOptions | undefined;
|
|
21
21
|
constructor(db: PgliteDatabase, dialect: PgliteDialect, extra?: ExtraOptions | undefined);
|
|
22
|
+
/** Every querier of the pool is this one handle's session, so they share its transaction. */
|
|
23
|
+
protected get connection(): object;
|
|
22
24
|
internalAll<T>(query: string, values?: unknown[]): Promise<T[]>;
|
|
23
25
|
internalRun(query: string, values?: unknown[]): Promise<import("../type/query.js").QueryUpdateResult>;
|
|
24
26
|
/** The handle belongs to the pool, which hands out one querier per unit of work over it. */
|
|
@@ -13,6 +13,10 @@ export class PgliteQuerier extends AbstractSqlQuerier {
|
|
|
13
13
|
this.db = db;
|
|
14
14
|
this.extra = extra;
|
|
15
15
|
}
|
|
16
|
+
/** Every querier of the pool is this one handle's session, so they share its transaction. */
|
|
17
|
+
get connection() {
|
|
18
|
+
return this.db;
|
|
19
|
+
}
|
|
16
20
|
async internalAll(query, values) {
|
|
17
21
|
const res = await this.db.query(query, values);
|
|
18
22
|
return res.rows;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { PgLikeSqlDialect } from '../dialect/pgLikeSqlDialect.js';
|
|
2
2
|
import type { QueryContext, SqlDialectFeatures, SqlDialectName, SqlValues, Type } from '../type/index.js';
|
|
3
|
-
/**
|
|
3
|
+
/** What Postgres has: pgvector, the only engine with `halfvec` and `sparsevec`. */
|
|
4
|
+
export declare const POSTGRES_FEATURES: SqlDialectFeatures;
|
|
5
|
+
/** PostgreSQL, under every driver: `pg`, Neon, PGlite, `bun:sql`. Adds pgvector. */
|
|
4
6
|
export declare class PostgresDialect extends PgLikeSqlDialect {
|
|
5
7
|
readonly dialectName: SqlDialectName;
|
|
6
8
|
readonly vectorExtension: string | undefined;
|
|
7
|
-
/** pgvector is the only engine with `halfvec` and `sparsevec`. */
|
|
8
9
|
readonly features: SqlDialectFeatures;
|
|
9
10
|
/** `uuidv7()` is Postgres 18+; an older server refuses it itself. */
|
|
10
11
|
readonly sqlValues: SqlValues;
|
|
11
|
-
/** The xmax system column is 0 for a newly inserted row and non-zero for an updated one (MVCC). */
|
|
12
|
-
protected readonly upsertCreatedReturning: string;
|
|
13
12
|
/**
|
|
14
13
|
* `to_regclass` rather than a `::regclass` cast: it answers `NULL` for a table that does not exist
|
|
15
14
|
* (mid-migration, say) where the cast throws. `GREATEST` because a table nothing has analyzed yet
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { AGGREGATE_VALUE_ALIAS
|
|
1
|
+
import { AGGREGATE_VALUE_ALIAS } from '../dialect/aliases.js';
|
|
2
2
|
import { PG_FEATURES, PG_SQL_VALUES, PgLikeSqlDialect } from '../dialect/pgLikeSqlDialect.js';
|
|
3
3
|
import { getMeta } from '../entity/index.js';
|
|
4
|
-
/**
|
|
4
|
+
/** What Postgres has: pgvector, the only engine with `halfvec` and `sparsevec`. */
|
|
5
|
+
export const POSTGRES_FEATURES = { ...PG_FEATURES, narrowVectorTypes: true };
|
|
6
|
+
/** PostgreSQL, under every driver: `pg`, Neon, PGlite, `bun:sql`. Adds pgvector. */
|
|
5
7
|
export class PostgresDialect extends PgLikeSqlDialect {
|
|
6
8
|
dialectName = 'postgres';
|
|
7
9
|
vectorExtension = 'vector';
|
|
8
|
-
|
|
9
|
-
features = { ...PG_FEATURES, narrowVectorTypes: true };
|
|
10
|
+
features = POSTGRES_FEATURES;
|
|
10
11
|
/** `uuidv7()` is Postgres 18+; an older server refuses it itself. */
|
|
11
12
|
sqlValues = { ...PG_SQL_VALUES, uuidv7: 'uuidv7()' };
|
|
12
|
-
/** The xmax system column is 0 for a newly inserted row and non-zero for an updated one (MVCC). */
|
|
13
|
-
upsertCreatedReturning = `(xmax = 0) AS ${this.escapeId(UPSERT_CREATED_ALIAS)}`;
|
|
14
13
|
/**
|
|
15
14
|
* `to_regclass` rather than a `::regclass` cast: it answers `NULL` for a table that does not exist
|
|
16
15
|
* (mid-migration, say) where the cast throws. `GREATEST` because a table nothing has analyzed yet
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
2
|
-
import type { CursorPage, EntityData, EntityId, EntityWrite, ExtraOptions, FieldKey, Querier, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryFilter, QueryFindResult, QueryGroupMap, QueryKeysetProjected, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch, PrimaryKey,
|
|
2
|
+
import type { BooleanLike, CursorPage, EntityData, EntityId, EntityWrite, ExtraOptions, FieldKey, Querier, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryFilter, QueryFindResult, QueryGroupMap, QueryKeysetProjected, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch, PrimaryKey, RelationKey, SavepointCommand, TransactionOptions, Type, UpdatePayload, UpdateWrite, ReturningResult, WriteOptions, WrittenId } from '../type/index.js';
|
|
3
3
|
import { LoggerWrapper } from '../util/index.js';
|
|
4
|
+
import { type TransactionScope } from './transaction.js';
|
|
4
5
|
/** Base class for all database queriers. */
|
|
5
6
|
export declare abstract class AbstractQuerier implements Querier {
|
|
6
7
|
#private;
|
|
@@ -19,6 +20,11 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
19
20
|
protected readonly logger: LoggerWrapper;
|
|
20
21
|
abstract readonly dialect: AbstractDialect;
|
|
21
22
|
constructor(extra?: ExtraOptions | undefined);
|
|
23
|
+
/**
|
|
24
|
+
* What the transaction this querier opens belongs to: the querier itself, its own connection, unless every
|
|
25
|
+
* querier of its pool is one session (SQLite, PGlite), whose queriers then name that handle and share it.
|
|
26
|
+
*/
|
|
27
|
+
protected get connection(): object;
|
|
22
28
|
/** What every read is checked for before it runs, whichever backend runs it. */
|
|
23
29
|
protected validateReadQuery<E extends object>(entity: Type<E>, q: Query<E>): void;
|
|
24
30
|
/**
|
|
@@ -93,19 +99,39 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
93
99
|
protected abstract internalAggregate<E extends object, G extends QueryGroupMap<E>, A extends QueryAggMap<E>>(entity: Type<E>, q: QueryAggregate<E, G, A>, opts?: QueryOptions): Promise<QueryAggregateResult<E, G, A>[]>;
|
|
94
100
|
/** Abstract outright: nothing is shared to do around it. See {@link UniversalQuerier.estimatedCount}. */
|
|
95
101
|
abstract estimatedCount<E extends object>(entity: Type<E>): Promise<number>;
|
|
96
|
-
insertOne<E extends object>(entity: Type<E>, payload: EntityWrite<E>): Promise<WrittenId<E> | undefined
|
|
102
|
+
insertOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V>): Promise<ReturningResult<S, WrittenId<E> | undefined, QueryFindResult<E, S, V>>>;
|
|
103
|
+
insertMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V>): Promise<ReturningResult<S, (WrittenId<E> | undefined)[], QueryFindResult<E, S, V>[]>>;
|
|
104
|
+
/**
|
|
105
|
+
* The ids of the rows inserted, in payload order. The `onInsert` values are filled before the write, so
|
|
106
|
+
* the after hooks and the ids read the same rows the statement wrote.
|
|
107
|
+
*/
|
|
108
|
+
private insertIds;
|
|
97
109
|
/**
|
|
98
|
-
* The `
|
|
99
|
-
*
|
|
110
|
+
* The ids `write` reports, or, where `opts` asks for `returning`, the rows they name, read back in the same
|
|
111
|
+
* transaction with only the fields it lists.
|
|
112
|
+
*/
|
|
113
|
+
private writeReturning;
|
|
114
|
+
/** The rows `q` matches with the fields `keys` names and their keys, through `afterLoad` as a read's are. */
|
|
115
|
+
private readReturning;
|
|
116
|
+
/** The rows `ids` names, in their order, each with only the fields `keys` names. */
|
|
117
|
+
private readWritten;
|
|
118
|
+
/**
|
|
119
|
+
* Writes `rows` and their relations: the to-ones they hold the keys of first, so each row inserts
|
|
120
|
+
* pointing at its own, then the rows, then their children by the keys the rows got. An insert, and the
|
|
121
|
+
* insert half of a read upsert.
|
|
100
122
|
*/
|
|
101
|
-
insertMany<E extends object>(entity: Type<E>, payload: readonly EntityWrite<E>[]): Promise<(WrittenId<E> | undefined)[]>;
|
|
102
|
-
/** Fills and guards `rows`, then writes them and their relations: an insert, and the insert half of a read upsert. */
|
|
103
123
|
private insertRows;
|
|
104
124
|
/** Writes `rows`, its columns only, and onto each one the key the database generated for it, where it can tell. */
|
|
105
125
|
protected abstract internalInsertMany<E extends object>(entity: Type<E>, rows: EntityData<E>[]): Promise<void>;
|
|
106
|
-
updateOneById<E extends object>(entity: Type<E>, id: EntityId<E>, payload: UpdateWrite<E>, opts?: QueryOptions): Promise<number
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
updateOneById<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, id: EntityId<E>, payload: UpdateWrite<E>, opts?: QueryOptions & WriteOptions<E, S, V>): Promise<ReturningResult<S, number, QueryFindResult<E, S, V> | undefined>>;
|
|
127
|
+
updateMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, q: QuerySearch<E>, payload: UpdateWrite<E>, opts?: QueryOptions & WriteOptions<E, S, V>): Promise<ReturningResult<S, number, QueryFindResult<E, S, V>[]>>;
|
|
128
|
+
/**
|
|
129
|
+
* The number of rows the update changed, or the rows `returning` reads back: their ids settled first, so a
|
|
130
|
+
* payload changing what `$where` reads still names them, and read back by those ids in the same transaction.
|
|
131
|
+
*/
|
|
132
|
+
private updateWhere;
|
|
133
|
+
/** Updates the rows `q` matches between the update hooks, atomically where the payload writes relations too. */
|
|
134
|
+
private updateMatching;
|
|
109
135
|
/**
|
|
110
136
|
* The write every update runs, matching the version `lockKey` names where one is being held. Only a
|
|
111
137
|
* restore passes none: it writes no content, so there is no update of anyone's to lose.
|
|
@@ -130,7 +156,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
130
156
|
* in one transaction where there are several, so a write split to fit the engine still lands whole.
|
|
131
157
|
*/
|
|
132
158
|
protected writeBatches<T>(rows: readonly T[], keyCount: number, write: (batch: T[]) => Promise<number>): Promise<number>;
|
|
133
|
-
/** Runs a write
|
|
159
|
+
/** Runs a write of several statements as one: in a transaction of its own, or the one already open. */
|
|
134
160
|
protected atomically<T>(write: () => Promise<T>): Promise<T>;
|
|
135
161
|
/** The ids `q` matches, in its own order and page. */
|
|
136
162
|
protected settleIds<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): Promise<EntityId<E>[]>;
|
|
@@ -143,49 +169,100 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
143
169
|
* cleared stamp, or a row pointed at the relation just inserted for it.
|
|
144
170
|
*/
|
|
145
171
|
private unversionedUpdate;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
upsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: readonly EntityWrite<E>[], update?: UpdateWrite<E>): Promise<QueryUpsertManyResult<E>>;
|
|
172
|
+
upsertOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: EntityWrite<E>, update?: UpdateWrite<E>, opts?: WriteOptions<E, S, V>): Promise<ReturningResult<S, WrittenId<E> | undefined, QueryFindResult<E, S, V>>>;
|
|
173
|
+
upsertMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: readonly EntityWrite<E>[], update?: UpdateWrite<E>, opts?: WriteOptions<E, S, V>): Promise<ReturningResult<S, (WrittenId<E> | undefined)[], QueryFindResult<E, S, V>[]>>;
|
|
149
174
|
/**
|
|
150
175
|
* An upsert as a read, then writes: the rows the conflict names are read through the filters, those found update
|
|
151
176
|
* as `updateMany` does and the rest insert, so either branch writes its relations and a guarded row stays its
|
|
152
177
|
* tenant's. A row inserted concurrently fails on its key. See architecture/security-filter-writes.md.
|
|
153
178
|
*/
|
|
154
179
|
private readThenUpsert;
|
|
155
|
-
|
|
156
|
-
protected abstract internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<
|
|
157
|
-
deleteOneById<E extends object>(entity: Type<E>, id: EntityId<E>, opts?: QueryOptions): Promise<number
|
|
180
|
+
/** Upserts `payload`, answering each row's key in payload order where the engine reports every one. */
|
|
181
|
+
protected abstract internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(PrimaryKey | undefined)[] | undefined>;
|
|
182
|
+
deleteOneById<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, id: EntityId<E>, opts?: QueryOptions & WriteOptions<E, S, V>): Promise<ReturningResult<S, number, QueryFindResult<E, S, V> | undefined>>;
|
|
158
183
|
/** Delete records matching the query, the entity passed first or as `$entity`; soft-deletes unless `opts.hardDelete`. */
|
|
159
184
|
deleteMany<E extends object>(q: QuerySearch<E> & {
|
|
160
185
|
$entity: Type<E>;
|
|
161
186
|
}, opts?: QueryOptions): Promise<number>;
|
|
162
|
-
deleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): Promise<number
|
|
187
|
+
deleteMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions & WriteOptions<E, S, V>): Promise<ReturningResult<S, number, QueryFindResult<E, S, V>[]>>;
|
|
188
|
+
/** The number of rows deleted, or the rows `returning` reads as they were, before the delete and in its transaction. */
|
|
189
|
+
private deleteWhere;
|
|
190
|
+
private deleteRows;
|
|
163
191
|
/** Runs one DELETE (or soft-delete stamp) over `q`, which names its rows by id wherever {@link deleteMany} settled them. */
|
|
164
192
|
protected abstract internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): Promise<number>;
|
|
165
|
-
saveOne<E extends object>(entity: Type<E>, payload: EntityWrite<E>): Promise<WrittenId<E> | undefined
|
|
193
|
+
saveOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V>): Promise<ReturningResult<S, WrittenId<E> | undefined, QueryFindResult<E, S, V>>>;
|
|
194
|
+
saveMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V>): Promise<ReturningResult<S, (WrittenId<E> | undefined)[], QueryFindResult<E, S, V>[]>>;
|
|
166
195
|
/**
|
|
167
196
|
* Whether a row names its key decides its statement, never whether the row exists: a named row
|
|
168
197
|
* upserts on that key, so a stale id is written rather than silently missed, and an unnamed one
|
|
169
198
|
* inserts. A composite is always named. The hooks follow the statement: a named row fires the upsert pair.
|
|
170
199
|
*/
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
200
|
+
private saveIds;
|
|
201
|
+
/**
|
|
202
|
+
* Writes the target of each to-one `rows` hold the key of, and points each row at its own: a row naming
|
|
203
|
+
* only its key is a link and writes nothing, any other saves as `saveMany` does, and `null` clears the key.
|
|
204
|
+
*/
|
|
205
|
+
private writeHeldReferences;
|
|
206
|
+
/** Writes each inserted row's children, one set of statements per relation whatever the number of rows. */
|
|
207
|
+
private insertChildren;
|
|
208
|
+
/**
|
|
209
|
+
* Makes `value` the children of each parent `ids` names, which it owns: the rows it lists are saved,
|
|
210
|
+
* keeping what each does not write, and the parent's other children (a junction's other links) go.
|
|
211
|
+
*/
|
|
212
|
+
private replaceChildren;
|
|
213
|
+
/** Writes each parent's children: rows pointed at their parent, or targets linked through the junction. */
|
|
214
|
+
private saveChildren;
|
|
215
|
+
/**
|
|
216
|
+
* Saves the rows a relation points at, each one's id what the pointer needs: a MySQL batch mixing supplied and
|
|
217
|
+
* generated keys cannot report it, so one it could not is refused rather than left pointing nowhere.
|
|
218
|
+
*/
|
|
219
|
+
private saveTargets;
|
|
176
220
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
221
|
+
* Deletes the children of the parents `ids` names, as the parents go: a hard delete takes them all, a soft
|
|
222
|
+
* delete stamps those that can be stamped and keeps the rest, junction links included, for a restore.
|
|
223
|
+
* `EntityId` because a settled composite row is an object, which {@link childrenOf} reads each foreign key column out of.
|
|
179
224
|
*/
|
|
180
|
-
private
|
|
181
|
-
/** Each parent gets its own referenced row, and its own column pointing at it. */
|
|
182
|
-
private saveManyToOne;
|
|
225
|
+
private deleteChildren;
|
|
183
226
|
abstract readonly hasOpenTransaction: boolean;
|
|
184
227
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
228
|
+
* The transaction this flow runs in on this connection, the innermost where they nest: the callback's,
|
|
229
|
+
* or a `beginTransaction` of this querier's. `undefined` outside one, or inside another flow's.
|
|
230
|
+
*/
|
|
231
|
+
protected scopeHere(): TransactionScope | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Runs `callback` in a transaction. Inside one this flow already runs, it is a savepoint: its failure undoes
|
|
234
|
+
* its own writes alone. A transaction another flow holds on this connection is waited for, never joined.
|
|
187
235
|
*/
|
|
188
236
|
transaction<T>(callback: () => Promise<T>, opts?: TransactionOptions): Promise<T>;
|
|
237
|
+
/** A transaction inside `parent`, after any other it runs: a savepoint where the engine has them. */
|
|
238
|
+
private nested;
|
|
239
|
+
/** `callback` between a savepoint and its release, rolled back to it on failure, its `onCommit` callbacks kept only where it succeeds. */
|
|
240
|
+
private savepointed;
|
|
241
|
+
/**
|
|
242
|
+
* Opens, releases or rolls back to a savepoint, which a SQL engine overrides. Elsewhere (MongoDB) there is
|
|
243
|
+
* none, so a transaction inside another is refused: it could not undo its own writes apart.
|
|
244
|
+
*/
|
|
245
|
+
protected savepoint(_kind: SavepointCommand, _name: string): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Runs `callback` once the outermost transaction this flow is in commits, and dropped if it rolls back:
|
|
248
|
+
* a mail sent for a row that never landed is not sent. With no transaction open it runs now.
|
|
249
|
+
*/
|
|
250
|
+
onCommit(callback: () => unknown): Promise<void>;
|
|
251
|
+
/** Waits for the connection's transaction, if another flow holds one, then opens `scope`'s on it. */
|
|
252
|
+
private open;
|
|
253
|
+
/** Whether the transaction its connection holds is this querier's. */
|
|
254
|
+
private holds;
|
|
255
|
+
/**
|
|
256
|
+
* Commits, or rolls back, the transaction this querier holds, in turn on its connection. With none held a
|
|
257
|
+
* rollback has nothing to do, and a commit refuses: a `release` inside the callback rolled it back.
|
|
258
|
+
*/
|
|
259
|
+
private close;
|
|
260
|
+
/**
|
|
261
|
+
* Commits, or rolls back, the transaction this querier holds. A commit that fails can leave it open (SQLite
|
|
262
|
+
* answers `SQLITE_BUSY` and keeps it) for the rollback after it; a failed rollback ends it, leaving the
|
|
263
|
+
* connection unusable.
|
|
264
|
+
*/
|
|
265
|
+
private end;
|
|
189
266
|
/** Whether anything at all - a global listener or the entity itself - handles `event`. */
|
|
190
267
|
private hasHook;
|
|
191
268
|
/** Whether an `afterLoad` listens on the entity a read returns or on any relation it populated. */
|
|
@@ -210,8 +287,12 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
210
287
|
private hooked;
|
|
211
288
|
/** Fires the global listeners first, then the entity's own hooks. */
|
|
212
289
|
private emitHook;
|
|
213
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* Runs `task` after everything already queued, one at a time, once no transaction of another flow holds the
|
|
292
|
+
* connection: a statement from outside one never lands in it. Not re-entrant: never nest `serialize` calls.
|
|
293
|
+
*/
|
|
214
294
|
protected serialize<T>(task: () => Promise<T>): Promise<T>;
|
|
295
|
+
private enqueue;
|
|
215
296
|
/** Runs `task`, logs `query` with its duration, and tags a failure with it: a method, since a decorator would lose the generics. */
|
|
216
297
|
protected timed<T>(query: string, values: readonly unknown[] | undefined, task: () => Promise<T>): Promise<T>;
|
|
217
298
|
/**
|
|
@@ -219,22 +300,24 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
219
300
|
* time after it is the loop's, and a failure tagged with `query`.
|
|
220
301
|
*/
|
|
221
302
|
protected timedStream<T>(query: string, values: readonly unknown[] | undefined, rows: AsyncIterable<T>): AsyncGenerator<T>;
|
|
303
|
+
/** Opens a transaction that holds this querier until `commitTransaction` or `rollbackTransaction`, whatever flow calls them. */
|
|
222
304
|
beginTransaction(opts?: TransactionOptions): Promise<void>;
|
|
223
305
|
/** Strict: this is the check that catches a forgotten `beginTransaction`. */
|
|
224
306
|
commitTransaction(): Promise<void>;
|
|
225
307
|
/**
|
|
226
|
-
* Rolls the
|
|
227
|
-
* `finally`, where the caller cannot know whether `beginTransaction` got far enough to open one.
|
|
308
|
+
* Rolls back the transaction this querier holds, or does nothing when there is none: it is called from `catch`
|
|
309
|
+
* and `finally`, where the caller cannot know whether `beginTransaction` got far enough to open one. A
|
|
310
|
+
* transaction another flow's callback holds is waited for, and so has ended by then.
|
|
228
311
|
*/
|
|
229
312
|
rollbackTransaction(): Promise<void>;
|
|
230
|
-
/** Opens a transaction on the engine,
|
|
313
|
+
/** Opens a transaction on the engine, once `open` has claimed the connection for it. */
|
|
231
314
|
protected abstract openTransaction(opts?: TransactionOptions): Promise<void>;
|
|
232
315
|
/** Commits the open transaction on the engine, or rolls it back when `commit` is false. */
|
|
233
316
|
protected abstract endTransaction(commit: boolean): Promise<void>;
|
|
234
317
|
/**
|
|
235
318
|
* Closes a stream left open and rolls back an unfinished transaction, then hands the connection back,
|
|
236
|
-
* discarding it
|
|
237
|
-
* since `await using` has no other way to release.
|
|
319
|
+
* discarding it where it is unusable: the pool would otherwise take one still reading, or in a state the
|
|
320
|
+
* next borrower inherits. Never throws first, since `await using` has no other way to release.
|
|
238
321
|
*/
|
|
239
322
|
release(): Promise<void>;
|
|
240
323
|
[Symbol.asyncDispose](): Promise<void>;
|