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
|
@@ -11,12 +11,11 @@ export declare abstract class AbstractQuerierPool<Q extends Querier, D extends A
|
|
|
11
11
|
* get a querier from the pool.
|
|
12
12
|
*/
|
|
13
13
|
abstract getQuerier(): Promise<Q>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
14
|
+
/** The querier of the transaction this flow runs in, where this pool handed it out. */
|
|
15
|
+
private ambientQuerier;
|
|
16
|
+
/** Whether this pool handed `querier` out: each pool builds a dialect of its own, which its queriers carry. */
|
|
17
|
+
private isOwn;
|
|
18
|
+
/** Runs `callback` in a transaction on a querier of the pool, or as a savepoint of the one this flow runs in. */
|
|
20
19
|
transaction<T>(callback: (querier: Q) => Promise<T>, opts?: TransactionOptions & PoolRunOptions): Promise<T>;
|
|
21
20
|
/**
|
|
22
21
|
* get a querier from the pool, run the given callback, and release the querier.
|
|
@@ -51,6 +51,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
53
|
import { withContext } from '../context/context.js';
|
|
54
|
+
import { currentTransaction } from './transaction.js';
|
|
54
55
|
/**
|
|
55
56
|
* Base pool: dialect id and behavior come only from the `dialect` instance (see {@link QuerierPool}).
|
|
56
57
|
*/
|
|
@@ -61,12 +62,16 @@ export class AbstractQuerierPool {
|
|
|
61
62
|
this.dialect = dialect;
|
|
62
63
|
this.extra = extra;
|
|
63
64
|
}
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
/** The querier of the transaction this flow runs in, where this pool handed it out. */
|
|
66
|
+
ambientQuerier() {
|
|
67
|
+
const querier = currentTransaction()?.querier;
|
|
68
|
+
return querier && this.isOwn(querier) ? querier : undefined;
|
|
69
|
+
}
|
|
70
|
+
/** Whether this pool handed `querier` out: each pool builds a dialect of its own, which its queriers carry. */
|
|
71
|
+
isOwn(querier) {
|
|
72
|
+
return 'dialect' in querier && querier.dialect === this.dialect;
|
|
73
|
+
}
|
|
74
|
+
/** Runs `callback` in a transaction on a querier of the pool, or as a savepoint of the one this flow runs in. */
|
|
70
75
|
transaction(callback, opts) {
|
|
71
76
|
return this.withQuerier((querier) => querier.transaction(() => callback(querier), opts), opts);
|
|
72
77
|
}
|
|
@@ -74,6 +79,10 @@ export class AbstractQuerierPool {
|
|
|
74
79
|
* get a querier from the pool, run the given callback, and release the querier.
|
|
75
80
|
*/
|
|
76
81
|
async withQuerier(callback, opts) {
|
|
82
|
+
const ambient = this.ambientQuerier();
|
|
83
|
+
if (ambient) {
|
|
84
|
+
return this.runScoped(opts?.context, () => callback(ambient));
|
|
85
|
+
}
|
|
77
86
|
const querier = await this.getQuerier();
|
|
78
87
|
try {
|
|
79
88
|
return await this.runScoped(opts?.context, () => callback(querier));
|
|
@@ -97,6 +106,11 @@ export class AbstractQuerierPool {
|
|
|
97
106
|
async *streamWithQuerier(read) {
|
|
98
107
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
99
108
|
try {
|
|
109
|
+
const ambient = this.ambientQuerier();
|
|
110
|
+
if (ambient) {
|
|
111
|
+
yield* read(ambient);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
100
114
|
const querier = __addDisposableResource(env_1, await this.getQuerier(), true);
|
|
101
115
|
yield* read(querier);
|
|
102
116
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
2
|
-
import type { EntityData, ExtraOptions, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryPage, QueryGroupMap, QueryOptions, QuerySearch, QueryUpdateResult, RawRow, SqlQuerier, TransactionOptions, Type, UpdatePayload } from '../type/index.js';
|
|
2
|
+
import type { EntityData, ExtraOptions, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryPage, QueryGroupMap, PrimaryKey, QueryOptions, QuerySearch, QueryUpdateResult, RawRow, RawValue, SavepointCommand, SqlQuerier, TransactionOptions, Type, UpdatePayload, QueryRaw } from '../type/index.js';
|
|
3
3
|
import type { BuildUpdateResultPayload } from '../util/sql.util.js';
|
|
4
4
|
import { AbstractQuerier } from './abstractQuerier.js';
|
|
5
5
|
export declare abstract class AbstractSqlQuerier extends AbstractQuerier implements SqlQuerier {
|
|
6
6
|
#private;
|
|
7
7
|
readonly dialect: AbstractSqlDialect;
|
|
8
8
|
readonly extra?: ExtraOptions | undefined;
|
|
9
|
-
|
|
9
|
+
hasOpenTransaction: boolean;
|
|
10
10
|
constructor(dialect: AbstractSqlDialect, extra?: ExtraOptions | undefined);
|
|
11
11
|
/**
|
|
12
12
|
* internal read query.
|
|
@@ -33,14 +33,20 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
33
33
|
* caught for every SQL backend.
|
|
34
34
|
*/
|
|
35
35
|
protected lazyConnect(): Promise<void>;
|
|
36
|
-
all<T>(
|
|
37
|
-
|
|
36
|
+
all<T extends object = RawRow>(strings: TemplateStringsArray, ...values: RawValue[]): Promise<T[]>;
|
|
37
|
+
all<T extends object = RawRow>(sql: QueryRaw): Promise<T[]>;
|
|
38
|
+
run(strings: TemplateStringsArray, ...values: RawValue[]): Promise<QueryUpdateResult>;
|
|
39
|
+
run(sql: QueryRaw): Promise<QueryUpdateResult>;
|
|
40
|
+
/** How a statement handed to `all` or `run` writes itself into a context. */
|
|
41
|
+
private rendering;
|
|
38
42
|
/** Refused before the driver fails it, or PGlite answers it and every read after it wrong. */
|
|
39
43
|
private assertBindBudget;
|
|
40
44
|
/** The rows of a statement the dialect builds. */
|
|
41
45
|
private query;
|
|
42
46
|
/** Runs a statement the dialect builds. */
|
|
43
47
|
private exec;
|
|
48
|
+
/** Builds a statement and sends it on the connection, in turn, timed and its failure tagged with it. */
|
|
49
|
+
private send;
|
|
44
50
|
/**
|
|
45
51
|
* Runs the `SET`s tuning an ANN index for the query on its connection, refusing where they would apply to
|
|
46
52
|
* nothing: a `SET LOCAL` outside a transaction.
|
|
@@ -91,18 +97,17 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
91
97
|
protected 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>[]>;
|
|
92
98
|
internalInsertMany<E extends object>(entity: Type<E>, rows: EntityData<E>[]): Promise<void>;
|
|
93
99
|
internalUpdateMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?: QueryOptions): Promise<number>;
|
|
94
|
-
protected
|
|
95
|
-
protected internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<QueryUpdateResult>;
|
|
100
|
+
protected internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(PrimaryKey | undefined)[] | undefined>;
|
|
96
101
|
private runUpsert;
|
|
97
102
|
protected internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): Promise<number>;
|
|
98
|
-
get hasOpenTransaction(): boolean;
|
|
99
103
|
protected openTransaction(opts?: TransactionOptions): Promise<void>;
|
|
100
104
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
105
|
+
* A `COMMIT` that fails can leave the transaction open (SQLite answers `SQLITE_BUSY` and keeps it), so the
|
|
106
|
+
* flag stays for the rollback after it. A `ROLLBACK` always ends it: one the server refuses, a deadlock
|
|
107
|
+
* victim's on SQL Server, left nothing open to roll back.
|
|
104
108
|
*/
|
|
105
109
|
protected endTransaction(commit: boolean): Promise<void>;
|
|
110
|
+
protected savepoint(command: SavepointCommand, name: string): Promise<void>;
|
|
106
111
|
/**
|
|
107
112
|
* How this driver opens, commits and rolls back: the dialect's statements, unless its transactions
|
|
108
113
|
* are objects rather than statements - Hrana's session handle, `mssql`'s `Transaction` - in which
|
|
@@ -3,6 +3,7 @@ import { decodeColumn } from '../dialect/hydrateColumn.js';
|
|
|
3
3
|
import { getMeta, namesKey } from '../entity/index.js';
|
|
4
4
|
import { COUNT_RESULT_KEY } from '../type/index.js';
|
|
5
5
|
import { buildUpdateResult, chunk, clone, getInsertFieldKeys, insertShapeOf, isAutoIncrement, isRecord, obtainAttrsPaths, unflatObject, } from '../util/index.js';
|
|
6
|
+
import { statementOf } from '../util/raw.js';
|
|
6
7
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
7
8
|
import { AbstractQuerier } from './abstractQuerier.js';
|
|
8
9
|
import { streamViaCursor } from './cursorStream.js';
|
|
@@ -52,7 +53,7 @@ function chunkWithinLimits(meta, payload, group, maxBindValues, maxRows = Infini
|
|
|
52
53
|
export class AbstractSqlQuerier extends AbstractQuerier {
|
|
53
54
|
dialect;
|
|
54
55
|
extra;
|
|
55
|
-
|
|
56
|
+
hasOpenTransaction = false;
|
|
56
57
|
/** Cached `auto_increment_increment` stride; see {@link loadInsertIdIncrement}. */
|
|
57
58
|
#insertIdIncrement;
|
|
58
59
|
constructor(dialect, extra) {
|
|
@@ -77,7 +78,7 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
77
78
|
* Only called for `firstId` dialects.
|
|
78
79
|
*/
|
|
79
80
|
async loadInsertIdIncrement() {
|
|
80
|
-
const [row] = await this.all
|
|
81
|
+
const [row] = await this.all `SELECT @@auto_increment_increment AS v`;
|
|
81
82
|
return Number(row.v);
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
@@ -90,19 +91,16 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
90
91
|
throw new UqlUsageError('querier already released');
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
return this.serialize(async () => {
|
|
96
|
-
await this.lazyConnect();
|
|
97
|
-
return this.timed(query, values, () => this.internalAll(query, this.dialect.normalizeValues(values)));
|
|
98
|
-
});
|
|
94
|
+
all(...statement) {
|
|
95
|
+
return this.query(this.rendering(statement));
|
|
99
96
|
}
|
|
100
|
-
|
|
101
|
-
this.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
run(...statement) {
|
|
98
|
+
return this.exec(this.rendering(statement));
|
|
99
|
+
}
|
|
100
|
+
/** How a statement handed to `all` or `run` writes itself into a context. */
|
|
101
|
+
rendering(statement) {
|
|
102
|
+
const sql = statementOf(statement);
|
|
103
|
+
return (ctx) => this.dialect.getRawValue(ctx, { value: sql });
|
|
106
104
|
}
|
|
107
105
|
/** Refused before the driver fails it, or PGlite answers it and every read after it wrong. */
|
|
108
106
|
assertBindBudget(values) {
|
|
@@ -113,15 +111,22 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
113
111
|
}
|
|
114
112
|
/** The rows of a statement the dialect builds. */
|
|
115
113
|
query(build) {
|
|
116
|
-
|
|
117
|
-
build(ctx);
|
|
118
|
-
return this.all(ctx.sql, ctx.values);
|
|
114
|
+
return this.send(build, (sql, values) => this.internalAll(sql, values));
|
|
119
115
|
}
|
|
120
116
|
/** Runs a statement the dialect builds. */
|
|
121
117
|
exec(build) {
|
|
118
|
+
return this.send(build, (sql, values) => this.internalRun(sql, values));
|
|
119
|
+
}
|
|
120
|
+
/** Builds a statement and sends it on the connection, in turn, timed and its failure tagged with it. */
|
|
121
|
+
async send(build, task) {
|
|
122
122
|
const ctx = this.dialect.createContext();
|
|
123
123
|
build(ctx);
|
|
124
|
-
|
|
124
|
+
const { sql, values } = ctx;
|
|
125
|
+
this.assertBindBudget(values);
|
|
126
|
+
return this.serialize(async () => {
|
|
127
|
+
await this.lazyConnect();
|
|
128
|
+
return this.timed(sql, values, () => task(sql, this.dialect.normalizeValues(values)));
|
|
129
|
+
});
|
|
125
130
|
}
|
|
126
131
|
/**
|
|
127
132
|
* Runs the `SET`s tuning an ANN index for the query on its connection, refusing where they would apply to
|
|
@@ -135,7 +140,7 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
135
140
|
if (!statements.length) {
|
|
136
141
|
return;
|
|
137
142
|
}
|
|
138
|
-
if (this.dialect.features.vectorTuningNeedsTransaction && !this.
|
|
143
|
+
if (this.dialect.features.vectorTuningNeedsTransaction && !this.scopeHere()) {
|
|
139
144
|
throw new UqlUsageError(`$candidates requires an open transaction on ${this.dialect.dialectName}; run the query inside pool.transaction(...)`);
|
|
140
145
|
}
|
|
141
146
|
for (const statement of statements) {
|
|
@@ -204,7 +209,7 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
204
209
|
yield* await this.internalAll(query, values);
|
|
205
210
|
return;
|
|
206
211
|
}
|
|
207
|
-
yield* streamViaCursor((sql, params) => this.internalAll(sql, params), query, values, this.
|
|
212
|
+
yield* streamViaCursor((sql, params) => this.internalAll(sql, params), query, values, !!this.scopeHere());
|
|
208
213
|
}
|
|
209
214
|
/**
|
|
210
215
|
* How each row of one statement becomes the entity's, for a read, a stream and a to-many alike: its dotted
|
|
@@ -340,12 +345,9 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
340
345
|
const { changes = 0 } = await this.exec((ctx) => this.dialect.update(ctx, entity, q, payload, opts));
|
|
341
346
|
return changes;
|
|
342
347
|
}
|
|
343
|
-
async internalUpsertOne(entity, conflictPaths, payload, update) {
|
|
344
|
-
return this.internalUpsertMany(entity, conflictPaths, [payload], update);
|
|
345
|
-
}
|
|
346
348
|
async internalUpsertMany(entity, conflictPaths, payload, update) {
|
|
347
|
-
if (!payload
|
|
348
|
-
return
|
|
349
|
+
if (!payload.length) {
|
|
350
|
+
return [];
|
|
349
351
|
}
|
|
350
352
|
payload = clone(payload);
|
|
351
353
|
const meta = getMeta(entity);
|
|
@@ -361,62 +363,67 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
361
363
|
}
|
|
362
364
|
// An upsert's assignment list is the statement's, so rows of different shapes go in statements of their own.
|
|
363
365
|
return this.atomically(async () => {
|
|
364
|
-
let changes = 0;
|
|
365
366
|
// Placed by index, since grouping by shape reorders the rows. A statement reporting fewer ids
|
|
366
367
|
// than it wrote places none.
|
|
367
368
|
const ids = new Array(payload.length);
|
|
368
369
|
for (const indexes of statements) {
|
|
369
|
-
const
|
|
370
|
-
changes += written;
|
|
370
|
+
const reported = await this.runUpsert(entity, conflictPaths, indexes.map((index) => payload[index]), update);
|
|
371
371
|
if (reported?.length === indexes.length) {
|
|
372
372
|
for (let position = 0; position < indexes.length; position++) {
|
|
373
373
|
ids[indexes[position]] = reported[position];
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
|
|
378
|
-
return { changes, ids };
|
|
377
|
+
return ids;
|
|
379
378
|
});
|
|
380
379
|
}
|
|
381
380
|
async runUpsert(entity, conflictPaths, payload, update) {
|
|
382
381
|
const meta = getMeta(entity);
|
|
383
382
|
// Asked first: the statement fills an `onInsert` key into these rows whether it inserts them or not.
|
|
384
383
|
const unnamed = meta.ids.length === 1 && payload.some((row) => !namesKey(meta, row));
|
|
385
|
-
const
|
|
384
|
+
const { ids } = await this.exec((ctx) => this.dialect.upsert(ctx, entity, conflictPaths, payload, update));
|
|
386
385
|
const ordered = payload.length === 1 ||
|
|
387
386
|
(this.dialect.insertIdSource === 'returning' && this.dialect.features.orderedUpsertReturning);
|
|
388
|
-
if (ordered &&
|
|
389
|
-
return
|
|
387
|
+
if (ordered && ids?.length === payload.length) {
|
|
388
|
+
return ids;
|
|
390
389
|
}
|
|
391
390
|
// The statement's ids name its rows only in order and for every one. A MySQL batch reports a
|
|
392
391
|
// weighted count (1=insert, 2=update) instead, CockroachDB and SQL Server answer out of order, and
|
|
393
392
|
// `DO NOTHING` skips rows, so there the ids are read back by the conflict columns.
|
|
394
|
-
|
|
395
|
-
const created = payload.length === 1 ? result.created : undefined;
|
|
396
|
-
return unnamed
|
|
397
|
-
? { changes, created, ids: await this.idsByConflict(entity, conflictPaths, payload) }
|
|
398
|
-
: { changes, created };
|
|
393
|
+
return unnamed ? this.idsByConflict(entity, conflictPaths, payload) : undefined;
|
|
399
394
|
}
|
|
400
395
|
async internalDeleteMany(entity, q, opts) {
|
|
401
396
|
const { changes = 0 } = await this.exec((ctx) => this.dialect.delete(ctx, entity, q, opts));
|
|
402
397
|
return changes;
|
|
403
398
|
}
|
|
404
|
-
get hasOpenTransaction() {
|
|
405
|
-
return !!this.hasPendingTransaction;
|
|
406
|
-
}
|
|
407
399
|
async openTransaction(opts) {
|
|
408
400
|
await this.lazyConnect();
|
|
409
401
|
await this.internalBegin(opts);
|
|
410
|
-
this.
|
|
402
|
+
this.hasOpenTransaction = true;
|
|
411
403
|
}
|
|
412
404
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
405
|
+
* A `COMMIT` that fails can leave the transaction open (SQLite answers `SQLITE_BUSY` and keeps it), so the
|
|
406
|
+
* flag stays for the rollback after it. A `ROLLBACK` always ends it: one the server refuses, a deadlock
|
|
407
|
+
* victim's on SQL Server, left nothing open to roll back.
|
|
416
408
|
*/
|
|
417
409
|
async endTransaction(commit) {
|
|
418
|
-
|
|
419
|
-
|
|
410
|
+
if (commit) {
|
|
411
|
+
await this.internalCommit();
|
|
412
|
+
this.hasOpenTransaction = false;
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
try {
|
|
416
|
+
await this.internalRollback();
|
|
417
|
+
}
|
|
418
|
+
finally {
|
|
419
|
+
this.hasOpenTransaction = false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
async savepoint(command, name) {
|
|
423
|
+
const sql = this.dialect.savepointStatement(command, name);
|
|
424
|
+
if (sql) {
|
|
425
|
+
await this.runTransactionCommand(sql);
|
|
426
|
+
}
|
|
420
427
|
}
|
|
421
428
|
/**
|
|
422
429
|
* How this driver opens, commits and rolls back: the dialect's statements, unless its transactions
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
2
|
-
import type { QueryUpdateResult, SqlQuerier, SqlQuerierPool } from '../type/index.js';
|
|
2
|
+
import type { QueryRaw, QueryUpdateResult, RawRow, RawValue, SqlQuerier, SqlQuerierPool } from '../type/index.js';
|
|
3
3
|
import { AbstractQuerierPool } from './abstractQuerierPool.js';
|
|
4
4
|
/**
|
|
5
5
|
* Base pool for SQL dialects; implements the raw-SQL surface of {@link SqlQuerierPool}, which owns
|
|
6
6
|
* the connection-per-call semantics.
|
|
7
7
|
*/
|
|
8
8
|
export declare abstract class AbstractSqlQuerierPool<Q extends SqlQuerier, D extends AbstractSqlDialect> extends AbstractQuerierPool<Q, D> implements SqlQuerierPool<Q, D> {
|
|
9
|
-
all<T>(
|
|
10
|
-
|
|
9
|
+
all<T extends object = RawRow>(strings: TemplateStringsArray, ...values: RawValue[]): Promise<T[]>;
|
|
10
|
+
all<T extends object = RawRow>(sql: QueryRaw): Promise<T[]>;
|
|
11
|
+
run(strings: TemplateStringsArray, ...values: RawValue[]): Promise<QueryUpdateResult>;
|
|
12
|
+
run(sql: QueryRaw): Promise<QueryUpdateResult>;
|
|
11
13
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { statementOf } from '../util/raw.js';
|
|
1
2
|
import { AbstractQuerierPool } from './abstractQuerierPool.js';
|
|
2
3
|
/**
|
|
3
4
|
* Base pool for SQL dialects; implements the raw-SQL surface of {@link SqlQuerierPool}, which owns
|
|
4
5
|
* the connection-per-call semantics.
|
|
5
6
|
*/
|
|
6
7
|
export class AbstractSqlQuerierPool extends AbstractQuerierPool {
|
|
7
|
-
all(
|
|
8
|
-
|
|
8
|
+
all(...statement) {
|
|
9
|
+
const sql = statementOf(statement);
|
|
10
|
+
return this.withQuerier((querier) => querier.all(sql));
|
|
9
11
|
}
|
|
10
|
-
run(
|
|
11
|
-
|
|
12
|
+
run(...statement) {
|
|
13
|
+
const sql = statementOf(statement);
|
|
14
|
+
return this.withQuerier((querier) => querier.run(sql));
|
|
12
15
|
}
|
|
13
16
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Querier } from '../type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A transaction as the flow running its callback holds it: the querier it runs on, the slot of that querier's
|
|
4
|
+
* connection, the one it is nested in, the callbacks to run once the outermost commits, and its own nested
|
|
5
|
+
* transactions, run one at a time.
|
|
6
|
+
*/
|
|
7
|
+
export type TransactionScope = {
|
|
8
|
+
readonly querier: Querier;
|
|
9
|
+
readonly slot: TransactionSlot;
|
|
10
|
+
readonly parent: TransactionScope | undefined;
|
|
11
|
+
readonly onCommit: (() => unknown)[];
|
|
12
|
+
nested: Promise<unknown>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The transaction a connection holds, shared by every querier on it. `manual` is a `beginTransaction` with no
|
|
16
|
+
* callback, so every statement of its querier is inside it, whatever flow sends it.
|
|
17
|
+
*/
|
|
18
|
+
export type TransactionSlot = {
|
|
19
|
+
held?: {
|
|
20
|
+
readonly scope: TransactionScope;
|
|
21
|
+
readonly manual: boolean;
|
|
22
|
+
readonly ended: Promise<void>;
|
|
23
|
+
end(): void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** The slot of `connection`, whichever querier on it asks. */
|
|
27
|
+
export declare function slotOf(connection: object): TransactionSlot;
|
|
28
|
+
/**
|
|
29
|
+
* Waits until `slot` holds no transaction, then holds it for `scope`, the root of its own, until {@link free}:
|
|
30
|
+
* in the turn it found it free, so two waiting never both take it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function claim(slot: TransactionSlot, scope: TransactionScope, manual: boolean): Promise<void>;
|
|
33
|
+
/** Ends the transaction `slot` holds, waking whoever waits for it. */
|
|
34
|
+
export declare function free(slot: TransactionSlot): void;
|
|
35
|
+
/** Waits until `slot` holds no transaction, or one `isMine` says the waiting flow runs in. */
|
|
36
|
+
export declare function awaitTurn(slot: TransactionSlot, isMine: () => boolean): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* The scope of the transaction callback the active flow runs in, the innermost where they nest, while its
|
|
39
|
+
* connection still holds it: a timer or promise the callback left running outlives it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function currentTransaction(): TransactionScope | undefined;
|
|
42
|
+
/** Runs `callback` inside `scope`, which statements, nested transactions and pool calls read as theirs. */
|
|
43
|
+
export declare function inTransaction<T>(scope: TransactionScope, callback: () => T): T;
|
|
44
|
+
export declare function newScope(querier: Querier, slot: TransactionSlot, parent?: TransactionScope): TransactionScope;
|
|
45
|
+
export declare function rootOf(scope: TransactionScope): TransactionScope;
|
|
46
|
+
export declare function depthOf(scope: TransactionScope): number;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { asyncScope } from '../context/context.js';
|
|
2
|
+
const slots = new WeakMap();
|
|
3
|
+
/** The slot of `connection`, whichever querier on it asks. */
|
|
4
|
+
export function slotOf(connection) {
|
|
5
|
+
let slot = slots.get(connection);
|
|
6
|
+
if (!slot) {
|
|
7
|
+
slot = {};
|
|
8
|
+
slots.set(connection, slot);
|
|
9
|
+
}
|
|
10
|
+
return slot;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Waits until `slot` holds no transaction, then holds it for `scope`, the root of its own, until {@link free}:
|
|
14
|
+
* in the turn it found it free, so two waiting never both take it.
|
|
15
|
+
*/
|
|
16
|
+
export async function claim(slot, scope, manual) {
|
|
17
|
+
while (slot.held) {
|
|
18
|
+
await slot.held.ended;
|
|
19
|
+
}
|
|
20
|
+
const { promise: ended, resolve: end } = Promise.withResolvers();
|
|
21
|
+
slot.held = { scope, manual, ended, end };
|
|
22
|
+
}
|
|
23
|
+
/** Ends the transaction `slot` holds, waking whoever waits for it. */
|
|
24
|
+
export function free(slot) {
|
|
25
|
+
const { held } = slot;
|
|
26
|
+
slot.held = undefined;
|
|
27
|
+
held?.end();
|
|
28
|
+
}
|
|
29
|
+
/** Waits until `slot` holds no transaction, or one `isMine` says the waiting flow runs in. */
|
|
30
|
+
export async function awaitTurn(slot, isMine) {
|
|
31
|
+
while (slot.held && !isMine()) {
|
|
32
|
+
await slot.held.ended;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const transactions = asyncScope();
|
|
36
|
+
/**
|
|
37
|
+
* The scope of the transaction callback the active flow runs in, the innermost where they nest, while its
|
|
38
|
+
* connection still holds it: a timer or promise the callback left running outlives it.
|
|
39
|
+
*/
|
|
40
|
+
export function currentTransaction() {
|
|
41
|
+
const scope = transactions.get();
|
|
42
|
+
return scope && scope.slot.held?.scope === rootOf(scope) ? scope : undefined;
|
|
43
|
+
}
|
|
44
|
+
/** Runs `callback` inside `scope`, which statements, nested transactions and pool calls read as theirs. */
|
|
45
|
+
export function inTransaction(scope, callback) {
|
|
46
|
+
return transactions.run(scope, callback);
|
|
47
|
+
}
|
|
48
|
+
export function newScope(querier, slot, parent) {
|
|
49
|
+
return { querier, slot, parent, onCommit: [], nested: Promise.resolve() };
|
|
50
|
+
}
|
|
51
|
+
export function rootOf(scope) {
|
|
52
|
+
return scope.parent ? rootOf(scope.parent) : scope;
|
|
53
|
+
}
|
|
54
|
+
export function depthOf(scope) {
|
|
55
|
+
return scope.parent ? depthOf(scope.parent) + 1 : 0;
|
|
56
|
+
}
|
|
@@ -214,7 +214,7 @@ const ENGINE_TYPES = {
|
|
|
214
214
|
const CANONICAL_TO_TS = {
|
|
215
215
|
integer: 'number',
|
|
216
216
|
float: 'number',
|
|
217
|
-
decimal: '
|
|
217
|
+
decimal: 'string',
|
|
218
218
|
string: 'string',
|
|
219
219
|
boolean: 'boolean',
|
|
220
220
|
date: 'Date',
|
|
@@ -315,7 +315,7 @@ function formatStringSqlType(type, base, sizing) {
|
|
|
315
315
|
if (type.length) {
|
|
316
316
|
return `${base}(${type.length})`;
|
|
317
317
|
}
|
|
318
|
-
return sizing === '
|
|
318
|
+
return sizing === 'boundedText' ? 'TEXT' : `${base}(255)`;
|
|
319
319
|
}
|
|
320
320
|
function formatDecimalSqlType(type, fallback, baseType) {
|
|
321
321
|
const p = type.precision ?? fallback?.precision;
|
|
@@ -24,11 +24,19 @@ export declare function diffSchemas(source: SchemaAST, target: SchemaAST, option
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function diffTable(source: TableNode, target: TableNode, options?: DiffOptions): TableDiff | undefined;
|
|
26
26
|
/**
|
|
27
|
-
* The columns renamed in the tables both sides name, by qualified table:
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* The columns renamed in the tables both sides name, by qualified table: a new column whose name is one the
|
|
28
|
+
* entity no longer names spelled by another naming strategy, the two alike but for case and underscores
|
|
29
|
+
* (`firstName`, `first_name`), each the one such on both sides. The name is the evidence, so the rest of the
|
|
30
|
+
* diff alters the renamed column as it would any other.
|
|
30
31
|
*/
|
|
31
32
|
export declare function columnRenames(desired: SchemaAST, actual: SchemaAST, options?: DiffOptions): ColumnRenames;
|
|
33
|
+
/**
|
|
34
|
+
* Each column a new one is identical to but for its name, the one such on both sides, with its qualified
|
|
35
|
+
* table. Suggested, never applied: a column dropped while an unrelated one of its type is added is no rename.
|
|
36
|
+
*/
|
|
37
|
+
export declare function columnRenameCandidates(desired: SchemaAST, actual: SchemaAST, options?: DiffOptions): (Rename & {
|
|
38
|
+
readonly table: string;
|
|
39
|
+
})[];
|
|
32
40
|
/**
|
|
33
41
|
* Tables the database holds that a new one is identical to but for its name, each only where it is the one
|
|
34
42
|
* match on both sides. Suggested, never applied: the database's side is a table no entity names, which may
|
|
@@ -83,18 +83,30 @@ function diffTableColumns(source, target, opts) {
|
|
|
83
83
|
];
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
* The columns renamed in the tables both sides name, by qualified table:
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* The columns renamed in the tables both sides name, by qualified table: a new column whose name is one the
|
|
87
|
+
* entity no longer names spelled by another naming strategy, the two alike but for case and underscores
|
|
88
|
+
* (`firstName`, `first_name`), each the one such on both sides. The name is the evidence, so the rest of the
|
|
89
|
+
* diff alters the renamed column as it would any other.
|
|
89
90
|
*/
|
|
90
91
|
export function columnRenames(desired, actual, options = {}) {
|
|
92
|
+
const spelling = (name) => name.replaceAll('_', '').toLowerCase();
|
|
93
|
+
return new Map(pairedColumns(desired, actual, options, (to, from) => spelling(to.name) === spelling(from.name)).map(({ table, renames }) => [table, renames]));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Each column a new one is identical to but for its name, the one such on both sides, with its qualified
|
|
97
|
+
* table. Suggested, never applied: a column dropped while an unrelated one of its type is added is no rename.
|
|
98
|
+
*/
|
|
99
|
+
export function columnRenameCandidates(desired, actual, options = {}) {
|
|
91
100
|
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
92
|
-
return
|
|
101
|
+
return pairedColumns(desired, actual, opts, (to, from) => !diffColumn(to.table.name, to, from, opts)).flatMap(({ table, renames }) => renames.map((rename) => ({ table, ...rename })));
|
|
102
|
+
}
|
|
103
|
+
/** The columns `same` pairs among those only one side names, per table both sides name, keyed by its qualified name. */
|
|
104
|
+
function pairedColumns(desired, actual, options, same) {
|
|
105
|
+
return matchTables(desired, actual, { ...DEFAULT_OPTIONS, ...options }).matched.flatMap(([expected, current]) => {
|
|
93
106
|
const { created, dropped } = matchByKey(expected.columns.values(), current.columns.values(), (column) => column.name);
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}));
|
|
107
|
+
const renames = pairUnique(created, dropped, same).matched.map(([to, from]) => ({ from: from.name, to: to.name }));
|
|
108
|
+
return renames.length ? [{ table: qualifyName(current.name, current.schema), renames }] : [];
|
|
109
|
+
});
|
|
98
110
|
}
|
|
99
111
|
/**
|
|
100
112
|
* Tables the database holds that a new one is identical to but for its name, each only where it is the one
|
|
@@ -13,7 +13,7 @@ export type NodeSqlitePoolOptions = LocalSqlitePoolOptions & {
|
|
|
13
13
|
readonly timeout?: number;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* A pool over Node's built-in `node:sqlite`, needing no dependency at all. {@link
|
|
16
|
+
* A pool over Node's built-in `node:sqlite`, needing no dependency at all. {@link SqliteQuerierPool} is the
|
|
17
17
|
* faster choice for read-heavy work, and the one on Bun.
|
|
18
18
|
*/
|
|
19
19
|
export declare class NodeSqliteQuerierPool extends AbstractLocalSqliteQuerierPool<LocalSqliteDatabase, SqliteDialect> {
|
|
@@ -2,7 +2,7 @@ import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
|
|
|
2
2
|
import { AbstractLocalSqliteQuerierPool, adaptSqlite, extendSqlite, } from './localSqliteQuerierPool.js';
|
|
3
3
|
import { SqliteDialect } from './sqliteDialect.js';
|
|
4
4
|
/**
|
|
5
|
-
* A pool over Node's built-in `node:sqlite`, needing no dependency at all. {@link
|
|
5
|
+
* A pool over Node's built-in `node:sqlite`, needing no dependency at all. {@link SqliteQuerierPool} is the
|
|
6
6
|
* faster choice for read-heavy work, and the one on Bun.
|
|
7
7
|
*/
|
|
8
8
|
export class NodeSqliteQuerierPool extends AbstractLocalSqliteQuerierPool {
|
|
@@ -22,7 +22,7 @@ export declare class SqliteDialect extends AbstractSqlDialect {
|
|
|
22
22
|
readonly maxBindValues: number;
|
|
23
23
|
/**
|
|
24
24
|
* The [sqlite-vec](https://github.com/asg017/sqlite-vec) functions, which need that extension
|
|
25
|
-
* loaded on the connection (see `
|
|
25
|
+
* loaded on the connection (see `SqliteQuerierPool`'s `extensions` option). libSQL and Turso ship
|
|
26
26
|
* their own vector functions instead, so `LibsqlDialect` overrides this.
|
|
27
27
|
*/
|
|
28
28
|
readonly vectorMetrics: ReadonlyMap<VectorDistance, VectorMetric>;
|
|
@@ -27,6 +27,7 @@ export const SQLITE_FEATURES = {
|
|
|
27
27
|
supportsTimestamptz: false,
|
|
28
28
|
stringSizing: 'text',
|
|
29
29
|
supportsUnsigned: false,
|
|
30
|
+
jsonArrivesDecoded: false,
|
|
30
31
|
serverSideCursors: false,
|
|
31
32
|
correlatedWrites: true,
|
|
32
33
|
rowLocks: false,
|
|
@@ -47,6 +48,7 @@ export const SQLITE_FEATURES = {
|
|
|
47
48
|
before: true,
|
|
48
49
|
deferrable: false,
|
|
49
50
|
},
|
|
51
|
+
namedLocks: false,
|
|
50
52
|
};
|
|
51
53
|
export class SqliteDialect extends AbstractSqlDialect {
|
|
52
54
|
features = SQLITE_FEATURES;
|
|
@@ -73,7 +75,7 @@ export class SqliteDialect extends AbstractSqlDialect {
|
|
|
73
75
|
maxBindValues = 32766;
|
|
74
76
|
/**
|
|
75
77
|
* The [sqlite-vec](https://github.com/asg017/sqlite-vec) functions, which need that extension
|
|
76
|
-
* loaded on the connection (see `
|
|
78
|
+
* loaded on the connection (see `SqliteQuerierPool`'s `extensions` option). libSQL and Turso ship
|
|
77
79
|
* their own vector functions instead, so `LibsqlDialect` overrides this.
|
|
78
80
|
*/
|
|
79
81
|
vectorMetrics = new Map([
|
|
@@ -33,6 +33,8 @@ export declare class SqliteQuerier extends AbstractSqliteQuerier {
|
|
|
33
33
|
readonly db: SqliteDatabase;
|
|
34
34
|
readonly extra?: ExtraOptions | undefined;
|
|
35
35
|
constructor(db: SqliteDatabase, dialect: SqliteDialect, extra?: ExtraOptions | undefined);
|
|
36
|
+
/** Every querier of the pool is this one handle's session, so they share its transaction. */
|
|
37
|
+
protected get connection(): object;
|
|
36
38
|
/** `reader` picks the call: `run()` would discard the rows of a statement that reads, RETURNING included. */
|
|
37
39
|
protected execute(query: string, values: SqliteBindValue[]): Promise<{
|
|
38
40
|
rows: RawRow[];
|