uql-orm 0.102.6 → 0.102.7
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 +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/bunSql/bunSqlQuerier.d.ts +9 -3
- package/dist/bunSql/bunSqlQuerier.js +7 -15
- package/dist/d1/d1Querier.d.ts +18 -14
- package/dist/d1/d1Querier.js +21 -8
- package/dist/d1/d1SqliteDialect.d.ts +2 -0
- package/dist/d1/d1SqliteDialect.js +3 -0
- package/dist/dialect/abstractDialect.d.ts +3 -0
- package/dist/dialect/abstractDialect.js +6 -2
- package/dist/dialect/abstractSqlDialect.d.ts +24 -5
- package/dist/dialect/abstractSqlDialect.js +86 -57
- package/dist/dialect/mysqlLikeSqlDialect.js +6 -1
- package/dist/dialect/operators.d.ts +9 -3
- package/dist/dialect/operators.js +32 -9
- package/dist/dialect/vectorSqlDialect.js +2 -2
- package/dist/entity/metadata/definition.d.ts +11 -1
- package/dist/entity/metadata/definition.js +18 -0
- package/dist/mariadb/mariadbQuerier.d.ts +5 -2
- package/dist/mariadb/mariadbQuerier.js +5 -10
- package/dist/migrate/ddl/defaultSql.js +1 -1
- package/dist/migrate/ddl/indexDdl.d.ts +3 -3
- package/dist/migrate/ddl/indexDdl.js +7 -7
- package/dist/migrate/ddl/mysqlIndexDdl.js +2 -2
- package/dist/migrate/ddl/tableDdl.js +2 -2
- package/dist/migrate/indexPredicate.d.ts +4 -3
- package/dist/migrate/indexPredicate.js +5 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +2 -6
- package/dist/migrate/schemaGenerator.js +1 -1
- package/dist/migrate/triggerSql.js +7 -5
- package/dist/mongodb/mongoDialect.js +17 -41
- package/dist/mongodb/mongoSchemaGenerator.js +12 -12
- package/dist/mongodb/mongodbQuerier.d.ts +4 -3
- package/dist/mongodb/mongodbQuerier.js +75 -102
- package/dist/mssql/mssqlDialect.js +2 -7
- package/dist/mssql/mssqlQuerier.d.ts +9 -3
- package/dist/mssql/mssqlQuerier.js +9 -11
- package/dist/mysql/mysql2Querier.d.ts +11 -2
- package/dist/mysql/mysql2Querier.js +4 -7
- package/dist/neon/index.d.ts +2 -0
- package/dist/neon/index.js +2 -0
- package/dist/neon/neonDialect.d.ts +7 -0
- package/dist/neon/neonDialect.js +8 -0
- package/dist/neon/neonQuerier.d.ts +26 -0
- package/dist/neon/neonQuerier.js +47 -0
- package/dist/neon/neonQuerierPool.d.ts +12 -2
- package/dist/neon/neonQuerierPool.js +22 -3
- package/dist/pglite/pgliteQuerier.d.ts +9 -5
- package/dist/pglite/pgliteQuerier.js +7 -11
- package/dist/postgres/pgExecution.d.ts +8 -0
- package/dist/postgres/pgExecution.js +3 -0
- package/dist/postgres/pgQuerier.d.ts +3 -6
- package/dist/postgres/pgQuerier.js +3 -7
- package/dist/querier/abstractQuerier.d.ts +24 -20
- package/dist/querier/abstractQuerier.js +79 -58
- package/dist/querier/abstractSqlQuerier.d.ts +42 -28
- package/dist/querier/abstractSqlQuerier.js +134 -116
- package/dist/querier/queryError.d.ts +2 -0
- package/dist/querier/queryError.js +9 -0
- package/dist/querier/transaction.js +2 -6
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +4 -10
- package/dist/sqlite/bindValues.d.ts +10 -0
- package/dist/sqlite/bindValues.js +8 -0
- package/dist/sqlite/hranaQuerier.d.ts +17 -11
- package/dist/sqlite/hranaQuerier.js +16 -5
- package/dist/sqlite/index.d.ts +1 -1
- package/dist/sqlite/index.js +0 -1
- package/dist/sqlite/localSqliteQuerierPool.js +19 -9
- package/dist/sqlite/sqliteQuerier.d.ts +9 -4
- package/dist/sqlite/sqliteQuerier.js +14 -8
- package/dist/turso/tursoSessionQuerier.d.ts +19 -7
- package/dist/turso/tursoSessionQuerier.js +31 -20
- package/dist/type/dialect.d.ts +3 -0
- package/dist/type/querier.d.ts +12 -0
- package/dist/type/querier.js +10 -0
- package/dist/type/vector.d.ts +2 -1
- package/dist/type/vector.js +2 -2
- package/dist/util/dialect.util.d.ts +21 -6
- package/dist/util/dialect.util.js +34 -9
- package/dist/util/filters.util.d.ts +5 -4
- package/dist/util/filters.util.js +4 -7
- package/dist/util/logger.js +2 -6
- package/dist/util/object.util.d.ts +7 -0
- package/dist/util/object.util.js +17 -0
- package/dist/util/query.util.d.ts +3 -2
- package/dist/util/sql.js +1 -1
- package/dist/util/sql.util.d.ts +15 -15
- package/dist/util/sql.util.js +5 -5
- package/package.json +5 -5
- package/skills/uql-orm/SKILL.md +4 -2
- package/dist/sqlite/abstractSqliteQuerier.d.ts +0 -28
- package/dist/sqlite/abstractSqliteQuerier.js +0 -36
|
@@ -4,6 +4,7 @@ import { BYTES_PREFIX } from '../dialect/hydrateColumn.js';
|
|
|
4
4
|
import { skippablePath, 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 { soleId } from '../entity/metadata/definition.js';
|
|
7
8
|
import { canonicalToSql, resolveColumnCanonicalType } from '../schema/canonicalType.js';
|
|
8
9
|
import { QuerySql } from '../type/index.js';
|
|
9
10
|
import { parseQueryLock } from '../type/index.js';
|
|
@@ -67,12 +68,6 @@ function openJsonType(value) {
|
|
|
67
68
|
}
|
|
68
69
|
return typeof value === 'boolean' ? OPENJSON_TYPE.boolean : OPENJSON_TYPE.string;
|
|
69
70
|
}
|
|
70
|
-
/** The one key column and its field, or nothing on a composite key. */
|
|
71
|
-
function soleId(meta) {
|
|
72
|
-
const [key] = meta.ids;
|
|
73
|
-
const field = meta.ids.length === 1 ? meta.fields[key] : undefined;
|
|
74
|
-
return field && { key, field };
|
|
75
|
-
}
|
|
76
71
|
/** Microsoft SQL Server 2017 and up. Identifiers are `"`-quoted, the ANSI spelling `tedious` enables. */
|
|
77
72
|
export class MsSqlDialect extends MergeSqlDialect {
|
|
78
73
|
features = MSSQL_FEATURES;
|
|
@@ -403,7 +398,7 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
403
398
|
jsonSet(ctx, expr, set) {
|
|
404
399
|
for (const [key, value] of Object.entries(set)) {
|
|
405
400
|
if (value === null) {
|
|
406
|
-
throw new UqlUsageError(`
|
|
401
|
+
throw new UqlUsageError(`SQL Server cannot $set '${key}' to null: JSON_MODIFY deletes the key instead. Use $unset, or store a JSON null through a whole-column write.`);
|
|
407
402
|
}
|
|
408
403
|
}
|
|
409
404
|
return Object.entries(set).reduce((acc, [key, value]) => `JSON_MODIFY(${acc}, ${jsonPath(key)}, ${this.jsonWriteParam(ctx, value)})`, expr);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import mssql from 'mssql';
|
|
2
2
|
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { RawRow, TransactionOptions } from '../type/index.js';
|
|
4
4
|
/** What `tedious` hands back for one statement, whichever shape it took. */
|
|
5
5
|
type MsSqlResult = {
|
|
6
6
|
recordset?: RawRow[] & {
|
|
@@ -42,8 +42,14 @@ export type MsSqlConnection = {
|
|
|
42
42
|
*/
|
|
43
43
|
export declare class MsSqlQuerier extends AbstractPoolQuerier<MsSqlConnection> {
|
|
44
44
|
#private;
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* `rowsAffected` carries one entry per statement, and a write runs in a batch of several - the table variable
|
|
47
|
+
* its ids go through, the read handing them back uncounted - so the counts are summed.
|
|
48
|
+
*/
|
|
49
|
+
protected execute(sql: string, values?: unknown[]): Promise<{
|
|
50
|
+
rows: RawRow[];
|
|
51
|
+
changes: number;
|
|
52
|
+
}>;
|
|
47
53
|
/**
|
|
48
54
|
* The driver's own stream over the request, which pauses the request while the loop is behind, so
|
|
49
55
|
* rows arrive only as fast as they are read. A failure the driver reports through the promise alone
|
|
@@ -21,18 +21,16 @@ export class MsSqlQuerier extends AbstractPoolQuerier {
|
|
|
21
21
|
});
|
|
22
22
|
return request;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
async
|
|
29
|
-
const res = await this.#request(values).query(
|
|
30
|
-
return
|
|
31
|
-
// `rowsAffected` carries one entry per statement, and a write runs in a batch of several - the table
|
|
32
|
-
// variable its ids go through, the read handing them back uncounted - so the counts are summed.
|
|
33
|
-
changes: res.rowsAffected.reduce((total, count) => total + count, 0),
|
|
24
|
+
/**
|
|
25
|
+
* `rowsAffected` carries one entry per statement, and a write runs in a batch of several - the table variable
|
|
26
|
+
* its ids go through, the read handing them back uncounted - so the counts are summed.
|
|
27
|
+
*/
|
|
28
|
+
async execute(sql, values) {
|
|
29
|
+
const res = await this.#request(values).query(sql);
|
|
30
|
+
return {
|
|
34
31
|
rows: decodeWireTypes(res.recordset, res.recordset?.columns),
|
|
35
|
-
|
|
32
|
+
changes: res.rowsAffected.reduce((total, count) => total + count, 0),
|
|
33
|
+
};
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
36
|
* The driver's own stream over the request, which pauses the request while the loop is behind, so
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { PoolConnection } from 'mysql2';
|
|
2
|
+
import type { RowDataPacket } from 'mysql2/promise';
|
|
2
3
|
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
3
4
|
/**
|
|
4
5
|
* Holds the driver's own connection rather than its promise wrapper, whose types name the connection
|
|
5
6
|
* inside it a promise one too: streaming is the own connection's alone.
|
|
6
7
|
*/
|
|
7
8
|
export declare class MySql2Querier extends AbstractPoolQuerier<PoolConnection> {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/** A read answers its rows; a write, the header naming how many rows it changed and the first id it generated. */
|
|
10
|
+
protected execute(sql: string, values?: unknown[]): Promise<{
|
|
11
|
+
rows: RowDataPacket[];
|
|
12
|
+
changes?: undefined;
|
|
13
|
+
id?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
rows: never[];
|
|
16
|
+
changes: number;
|
|
17
|
+
id: number;
|
|
18
|
+
}>;
|
|
10
19
|
internalStream(query: string, values?: unknown[]): AsyncGenerator<any, void, any>;
|
|
11
20
|
protected releaseConn(conn: PoolConnection, discard: boolean): Promise<void>;
|
|
12
21
|
}
|
|
@@ -4,13 +4,10 @@ import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
|
4
4
|
* inside it a promise one too: streaming is the own connection's alone.
|
|
5
5
|
*/
|
|
6
6
|
export class MySql2Querier extends AbstractPoolQuerier {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async internalRun(query, values) {
|
|
12
|
-
const [res] = await this.getConn().promise().query(query, values);
|
|
13
|
-
return this.buildUpdateResult({ changes: res.affectedRows, id: res.insertId });
|
|
7
|
+
/** A read answers its rows; a write, the header naming how many rows it changed and the first id it generated. */
|
|
8
|
+
async execute(sql, values) {
|
|
9
|
+
const [res] = await this.getConn().promise().query(sql, values);
|
|
10
|
+
return Array.isArray(res) ? { rows: res } : { rows: [], changes: res.affectedRows, id: res.insertId };
|
|
14
11
|
}
|
|
15
12
|
async *internalStream(query, values) {
|
|
16
13
|
yield* this.getConn().query(query, values).stream();
|
package/dist/neon/index.d.ts
CHANGED
package/dist/neon/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
+
import type { EngineName } from '../type/querier.js';
|
|
3
|
+
/** Postgres as Neon serves it: its proxy binds at most 32,767 values a statement over HTTP, half what Postgres takes. */
|
|
4
|
+
export declare class NeonDialect extends PostgresDialect {
|
|
5
|
+
get engineName(): EngineName;
|
|
6
|
+
readonly maxBindValues: number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
+
/** Postgres as Neon serves it: its proxy binds at most 32,767 values a statement over HTTP, half what Postgres takes. */
|
|
3
|
+
export class NeonDialect extends PostgresDialect {
|
|
4
|
+
get engineName() {
|
|
5
|
+
return 'Neon';
|
|
6
|
+
}
|
|
7
|
+
maxBindValues = 32_767;
|
|
8
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CustomTypesConfig, NeonQueryFunction, PoolClient } from '@neondatabase/serverless';
|
|
2
|
+
import { PgQuerier } from '../postgres/pgQuerier.js';
|
|
3
|
+
import type { BoundStatement } from '../querier/index.js';
|
|
4
|
+
import type { ExtraOptions, TransactionOptions } from '../type/index.js';
|
|
5
|
+
import type { SqlExecution } from '../util/sql.util.js';
|
|
6
|
+
import type { NeonDialect } from './neonDialect.js';
|
|
7
|
+
/** Neon's HTTP query function, answering each statement's whole result: what a statement goes through outside a session. */
|
|
8
|
+
export type NeonHttp = NeonQueryFunction<false, true>;
|
|
9
|
+
/**
|
|
10
|
+
* Querier for Neon, over HTTP first: a statement is one request, and a list one request running it as a
|
|
11
|
+
* transaction. A WebSocket session, taken from the pool for what one request cannot hold (a transaction a
|
|
12
|
+
* callback runs in, a stream's loop), serves the querier until it is released. Every query passes the pool's
|
|
13
|
+
* `types` itself, since `neon()` ignores them, so a row decodes as it does over the session.
|
|
14
|
+
*/
|
|
15
|
+
export declare class NeonQuerier extends PgQuerier<PoolClient> {
|
|
16
|
+
private readonly http;
|
|
17
|
+
private readonly types;
|
|
18
|
+
constructor(http: NeonHttp, types: CustomTypesConfig, connect: () => Promise<PoolClient>, dialect: NeonDialect, extra?: ExtraOptions);
|
|
19
|
+
/** Connects nothing: a statement goes over HTTP until a session holds the connection. */
|
|
20
|
+
protected lazyConnect(): Promise<void>;
|
|
21
|
+
protected execute(sql: string, values?: unknown[]): Promise<SqlExecution>;
|
|
22
|
+
/** A list as one HTTP transaction, all or none; inside an open transaction, in turn on its session, which it joins. */
|
|
23
|
+
protected executeBatch(statements: readonly BoundStatement[]): Promise<SqlExecution[]>;
|
|
24
|
+
protected openTransaction(opts?: TransactionOptions): Promise<void>;
|
|
25
|
+
internalStream(query: string, values?: unknown[]): AsyncGenerator<import("../type/utility.js").RawRow, void, any>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { pgExecution } from '../postgres/pgExecution.js';
|
|
2
|
+
import { PgQuerier } from '../postgres/pgQuerier.js';
|
|
3
|
+
/**
|
|
4
|
+
* Querier for Neon, over HTTP first: a statement is one request, and a list one request running it as a
|
|
5
|
+
* transaction. A WebSocket session, taken from the pool for what one request cannot hold (a transaction a
|
|
6
|
+
* callback runs in, a stream's loop), serves the querier until it is released. Every query passes the pool's
|
|
7
|
+
* `types` itself, since `neon()` ignores them, so a row decodes as it does over the session.
|
|
8
|
+
*/
|
|
9
|
+
export class NeonQuerier extends PgQuerier {
|
|
10
|
+
http;
|
|
11
|
+
types;
|
|
12
|
+
constructor(http, types, connect, dialect, extra) {
|
|
13
|
+
super(connect, dialect, extra);
|
|
14
|
+
this.http = http;
|
|
15
|
+
this.types = types;
|
|
16
|
+
}
|
|
17
|
+
/** Connects nothing: a statement goes over HTTP until a session holds the connection. */
|
|
18
|
+
async lazyConnect() {
|
|
19
|
+
this.assertActive();
|
|
20
|
+
}
|
|
21
|
+
async execute(sql, values) {
|
|
22
|
+
if (this.conn) {
|
|
23
|
+
return super.execute(sql, values);
|
|
24
|
+
}
|
|
25
|
+
return pgExecution(await this.http.query(sql, values, { types: this.types }));
|
|
26
|
+
}
|
|
27
|
+
/** A list as one HTTP transaction, all or none; inside an open transaction, in turn on its session, which it joins. */
|
|
28
|
+
async executeBatch(statements) {
|
|
29
|
+
if (this.hasOpenTransaction) {
|
|
30
|
+
const results = [];
|
|
31
|
+
for (const { sql, values } of statements) {
|
|
32
|
+
results.push(await super.execute(sql, values));
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
35
|
+
}
|
|
36
|
+
const results = await this.http.transaction(statements.map(({ sql, values }) => this.http.query(sql, values, { types: this.types })));
|
|
37
|
+
return results.map(pgExecution);
|
|
38
|
+
}
|
|
39
|
+
async openTransaction(opts) {
|
|
40
|
+
await super.lazyConnect();
|
|
41
|
+
await super.openTransaction(opts);
|
|
42
|
+
}
|
|
43
|
+
async *internalStream(query, values) {
|
|
44
|
+
await super.lazyConnect();
|
|
45
|
+
yield* super.internalStream(query, values);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Pool, type PoolClient, type PoolConfig } from '@neondatabase/serverless';
|
|
2
2
|
import { AbstractPgQuerierPool } from '../postgres/abstractPgQuerierPool.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PgQuerier } from '../postgres/pgQuerier.js';
|
|
4
4
|
import type { ExtraOptions } from '../type/index.js';
|
|
5
|
-
|
|
5
|
+
import { NeonDialect } from './neonDialect.js';
|
|
6
|
+
import { NeonQuerier } from './neonQuerier.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pool for Neon, over HTTP first: its queriers send statements and lists over HTTP, taking a WebSocket session
|
|
9
|
+
* from its `pool` only for a transaction or a stream. A migration runs on a session throughout, since its lock
|
|
10
|
+
* is the session's. [The design](../../../../architecture/split-writes.md).
|
|
11
|
+
*/
|
|
12
|
+
export declare class NeonQuerierPool extends AbstractPgQuerierPool<PoolClient, NeonDialect> {
|
|
13
|
+
#private;
|
|
6
14
|
readonly pool: Pool;
|
|
7
15
|
constructor(opts: PoolConfig, extra?: ExtraOptions);
|
|
16
|
+
getQuerier(): Promise<NeonQuerier>;
|
|
17
|
+
getMigrationQuerier(): Promise<PgQuerier<PoolClient>>;
|
|
8
18
|
}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import { Pool, types } from '@neondatabase/serverless';
|
|
1
|
+
import { neon, Pool, types } from '@neondatabase/serverless';
|
|
2
2
|
import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
|
|
3
3
|
import { AbstractPgQuerierPool } from '../postgres/abstractPgQuerierPool.js';
|
|
4
|
+
import { PgQuerier } from '../postgres/pgQuerier.js';
|
|
4
5
|
import { wireTypes } from '../postgres/pgWireTypes.js';
|
|
5
|
-
import {
|
|
6
|
+
import { NeonDialect } from './neonDialect.js';
|
|
7
|
+
import { NeonQuerier } from './neonQuerier.js';
|
|
8
|
+
/**
|
|
9
|
+
* Pool for Neon, over HTTP first: its queriers send statements and lists over HTTP, taking a WebSocket session
|
|
10
|
+
* from its `pool` only for a transaction or a stream. A migration runs on a session throughout, since its lock
|
|
11
|
+
* is the session's. [The design](../../../../architecture/split-writes.md).
|
|
12
|
+
*/
|
|
6
13
|
export class NeonQuerierPool extends AbstractPgQuerierPool {
|
|
14
|
+
#http;
|
|
15
|
+
#types;
|
|
7
16
|
constructor(opts, extra) {
|
|
8
17
|
// Neon's own `types`, not `pg`'s: this entry has to load on an edge runtime where `pg` is absent.
|
|
9
|
-
|
|
18
|
+
const wire = opts.types ?? wireTypes(types);
|
|
19
|
+
super(new NeonDialect(dialectOptionsFrom(extra)), new Pool({ ...opts, types: wire }), extra);
|
|
20
|
+
const { connectionString, host, port, user, password, database } = opts;
|
|
21
|
+
this.#http = neon({ connectionString, host, port, user, password, database, fullResults: true });
|
|
22
|
+
this.#types = wire;
|
|
23
|
+
}
|
|
24
|
+
async getQuerier() {
|
|
25
|
+
return new NeonQuerier(this.#http, this.#types, () => this.pool.connect(), this.dialect, this.extra);
|
|
26
|
+
}
|
|
27
|
+
async getMigrationQuerier() {
|
|
28
|
+
return new PgQuerier(() => this.pool.connect(), this.dialect, this.extra);
|
|
10
29
|
}
|
|
11
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractSqlQuerier } from '../querier/index.js';
|
|
2
|
-
import type { ExtraOptions } from '../type/index.js';
|
|
2
|
+
import type { ExtraOptions, RawRow } from '../type/index.js';
|
|
3
3
|
import type { PgliteDialect } from './pgliteDialect.js';
|
|
4
4
|
/** The two methods uql uses of `@electric-sql/pglite`, stated so its published types do not depend on a pre-1.0 package. */
|
|
5
5
|
export type PgliteDatabase = {
|
|
@@ -21,8 +21,12 @@ export declare class PgliteQuerier extends AbstractSqlQuerier {
|
|
|
21
21
|
constructor(db: PgliteDatabase, dialect: PgliteDialect, extra?: ExtraOptions | undefined);
|
|
22
22
|
/** Every querier of the pool is this one handle's session, so they share its transaction. */
|
|
23
23
|
protected get connection(): object;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
/**
|
|
25
|
+
* `affectedRows`, not `rowCount`: PGlite derives the former from the command tag of a write only, where the
|
|
26
|
+
* latter also counts a `SELECT`'s rows and is absent altogether from a DDL tag.
|
|
27
|
+
*/
|
|
28
|
+
protected execute(sql: string, values?: unknown[]): Promise<{
|
|
29
|
+
rows: RawRow[];
|
|
30
|
+
changes: number | undefined;
|
|
31
|
+
}>;
|
|
28
32
|
}
|
|
@@ -17,16 +17,12 @@ export class PgliteQuerier extends AbstractSqlQuerier {
|
|
|
17
17
|
get connection() {
|
|
18
18
|
return this.db;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* `affectedRows`, not `rowCount`: PGlite derives the former from the command tag of a write only, where the
|
|
22
|
+
* latter also counts a `SELECT`'s rows and is absent altogether from a DDL tag.
|
|
23
|
+
*/
|
|
24
|
+
async execute(sql, values) {
|
|
25
|
+
const { rows, affectedRows } = await this.db.query(sql, values);
|
|
26
|
+
return { rows, changes: affectedRows };
|
|
23
27
|
}
|
|
24
|
-
async internalRun(query, values) {
|
|
25
|
-
const res = await this.db.query(query, values);
|
|
26
|
-
// `affectedRows`, not `rowCount`: PGlite derives the former from the command tag of a write only,
|
|
27
|
-
// where the latter also counts a `SELECT`'s rows and is absent altogether from a DDL tag.
|
|
28
|
-
return this.buildUpdateResult({ rows: res.rows, changes: res.affectedRows });
|
|
29
|
-
}
|
|
30
|
-
/** The handle belongs to the pool, which hands out one querier per unit of work over it. */
|
|
31
|
-
async internalRelease() { }
|
|
32
28
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RawRow } from '../type/index.js';
|
|
2
|
+
import type { SqlExecution } from '../util/sql.util.js';
|
|
3
|
+
/** A node-postgres result as the querier reads it: its rows, and the rows it changed. */
|
|
4
|
+
export type PgResult = {
|
|
5
|
+
readonly rows: RawRow[];
|
|
6
|
+
readonly rowCount: number | null;
|
|
7
|
+
};
|
|
8
|
+
export declare function pgExecution({ rows, rowCount }: PgResult): SqlExecution;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
2
2
|
import type { RawRow } from '../type/index.js';
|
|
3
|
+
import { type PgResult } from './pgExecution.js';
|
|
3
4
|
export interface PgAnyClient {
|
|
4
|
-
query(text: string, values?: unknown[]): Promise<
|
|
5
|
-
rows: RawRow[];
|
|
6
|
-
rowCount: number | null;
|
|
7
|
-
}>;
|
|
5
|
+
query(text: string, values?: unknown[]): Promise<PgResult>;
|
|
8
6
|
query(stream: object): AsyncIterable<RawRow>;
|
|
9
7
|
on(event: 'error', listener: (err: Error) => void): unknown;
|
|
10
8
|
removeListener(event: 'error', listener: (err: Error) => void): unknown;
|
|
@@ -21,8 +19,7 @@ export declare class PgQuerier<C extends PgAnyClient = PgAnyClient> extends Abst
|
|
|
21
19
|
* the process: the querier hears it while it holds the client, `pg-pool` while it idles, never both at once.
|
|
22
20
|
*/
|
|
23
21
|
protected acquired(conn: C): C;
|
|
24
|
-
|
|
25
|
-
internalRun(query: string, values?: unknown[]): Promise<import("../type/query.js").QueryUpdateResult>;
|
|
22
|
+
protected execute(sql: string, values?: unknown[]): Promise<import("../util/sql.util.js").SqlExecution>;
|
|
26
23
|
internalStream(query: string, values?: unknown[]): AsyncGenerator<RawRow, void, any>;
|
|
27
24
|
protected releaseConn(conn: C, discard: boolean): Promise<void>;
|
|
28
25
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
2
|
+
import { pgExecution } from './pgExecution.js';
|
|
2
3
|
const ignoreError = () => { };
|
|
3
4
|
/**
|
|
4
5
|
* Querier for every client with node-postgres' API: `pg` itself, for Postgres and CockroachDB, and
|
|
@@ -13,13 +14,8 @@ export class PgQuerier extends AbstractPoolQuerier {
|
|
|
13
14
|
conn.on('error', ignoreError);
|
|
14
15
|
return conn;
|
|
15
16
|
}
|
|
16
|
-
async
|
|
17
|
-
|
|
18
|
-
return res.rows;
|
|
19
|
-
}
|
|
20
|
-
async internalRun(query, values) {
|
|
21
|
-
const res = await this.getConn().query(query, values);
|
|
22
|
-
return this.buildUpdateResult({ rows: res.rows, changes: res.rowCount ?? 0 });
|
|
17
|
+
async execute(sql, values) {
|
|
18
|
+
return pgExecution(await this.getConn().query(sql, values));
|
|
23
19
|
}
|
|
24
20
|
async *internalStream(query, values) {
|
|
25
21
|
const { default: QueryStream } = await import('pg-query-stream');
|
|
@@ -2,11 +2,6 @@ import type { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
|
2
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, RelationKey, SavepointCommand, TransactionOptions, Type, UpdatePayload, UpdateWrite, ReturningResult, WriteOptions, PrimaryKey, WrittenId } from '../type/index.js';
|
|
3
3
|
import { LoggerWrapper } from '../util/index.js';
|
|
4
4
|
import { type TransactionScope } from './transaction.js';
|
|
5
|
-
/**
|
|
6
|
-
* Writes the key an upsert reported onto each row that named none - only the key, since an `onInsert`
|
|
7
|
-
* value was never written to a row the upsert updated. A report aligns with the rows only when it
|
|
8
|
-
* speaks for every one: a `firstId` dialect reports nothing for a batch.
|
|
9
|
-
*/
|
|
10
5
|
/** What an upsert reports of a row: the value a driver answers for a lone key, or the key the read back names. */
|
|
11
6
|
export type UpsertedId<E> = PrimaryKey | WrittenId<E>;
|
|
12
7
|
/** An `UPDATE` and a `DELETE` of one statement each, reporting the rows they wrote with the fields `keys` names. */
|
|
@@ -20,14 +15,11 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
20
15
|
readonly extra?: ExtraOptions | undefined;
|
|
21
16
|
/** The last task {@link serialize} queued, which the next one runs after. */
|
|
22
17
|
private taskQueue;
|
|
23
|
-
/**
|
|
24
|
-
* A querier is one unit of work, so releasing ends it. Checked where each backend reaches for its
|
|
25
|
-
* connection, on every driver and not just the pooled ones.
|
|
26
|
-
*/
|
|
27
|
-
protected released: boolean;
|
|
28
18
|
protected readonly logger: LoggerWrapper;
|
|
29
19
|
abstract readonly dialect: AbstractDialect;
|
|
30
20
|
constructor(extra?: ExtraOptions | undefined);
|
|
21
|
+
/** Refuses a call on a released querier: each backend calls it where it reaches for its connection. */
|
|
22
|
+
protected assertActive(): void;
|
|
31
23
|
/**
|
|
32
24
|
* What the transaction this querier opens belongs to: the querier itself, its own connection, unless every
|
|
33
25
|
* querier of its pool is one session (SQLite, PGlite), whose queriers then name that handle and share it.
|
|
@@ -119,8 +111,11 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
119
111
|
* transaction with only the fields it lists.
|
|
120
112
|
*/
|
|
121
113
|
private writeReturning;
|
|
122
|
-
/**
|
|
123
|
-
|
|
114
|
+
/**
|
|
115
|
+
* The rows `ids` names, in their order, each with only the fields `keys` names: as written, whatever a filter
|
|
116
|
+
* says of them, since a soft-deleted row inserted is still written.
|
|
117
|
+
*/
|
|
118
|
+
private readBack;
|
|
124
119
|
/** What `returning` reports of `rows`: each through `afterLoad`, as a read's are, then only the fields `keys` names. */
|
|
125
120
|
private returned;
|
|
126
121
|
/**
|
|
@@ -206,8 +201,8 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
206
201
|
* architecture/security-filter-writes.md.
|
|
207
202
|
*/
|
|
208
203
|
private readThenUpsert;
|
|
209
|
-
/** Upserts `payload`, answering each row's key in payload order
|
|
210
|
-
protected abstract internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(UpsertedId<E> | undefined)[]
|
|
204
|
+
/** Upserts `payload`, answering each row's key in payload order, `undefined` for one the engine did not report. */
|
|
205
|
+
protected abstract internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(UpsertedId<E> | undefined)[]>;
|
|
211
206
|
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>>;
|
|
212
207
|
/** Delete records matching the query, the entity passed first or as `$entity`; soft-deletes unless `opts.hardDelete`. */
|
|
213
208
|
deleteMany<E extends object>(q: QuerySearch<E> & {
|
|
@@ -315,12 +310,18 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
315
310
|
*/
|
|
316
311
|
private emitLoaded;
|
|
317
312
|
/**
|
|
318
|
-
* The ids of `rows`, read
|
|
319
|
-
* {@link readForWrite} holds
|
|
320
|
-
*
|
|
321
|
-
* where a guessed one is not.
|
|
313
|
+
* The ids of `rows`, read by the columns an upsert matches them on, soft-deleted rows included since a unique key
|
|
314
|
+
* holds across both, each read held as {@link readForWrite} holds its rows. A row no found row matches, or two do,
|
|
315
|
+
* reads none, since a missing id is honest where a guessed one is not; a null key never conflicts, so is not read.
|
|
322
316
|
*/
|
|
323
317
|
protected idsByConflict<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, rows: EntityData<E>[]): Promise<(WrittenId<E> | undefined)[]>;
|
|
318
|
+
/**
|
|
319
|
+
* `ids` completed where an upsert reported no id for a row whose key it does not keep (`kept`, asked before the
|
|
320
|
+
* write fills one in): read back by the conflict columns.
|
|
321
|
+
*/
|
|
322
|
+
protected withUnreportedIds<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: EntityData<E>[], ids: (UpsertedId<E> | undefined)[], kept: readonly boolean[]): Promise<(UpsertedId<E> | undefined)[]>;
|
|
323
|
+
/** Reads of the rows matching one of `rows` on `keys`, as many per statement as a key list takes, selecting `select`. */
|
|
324
|
+
private keyedReads;
|
|
324
325
|
/**
|
|
325
326
|
* Runs `write` between the event's `before`/`after` pair. The before hooks get the caller's rows, so
|
|
326
327
|
* what they assign is written; `write` and the after hooks get a copy, which by then carries what
|
|
@@ -363,6 +364,9 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
363
364
|
*/
|
|
364
365
|
release(): Promise<void>;
|
|
365
366
|
[Symbol.asyncDispose](): Promise<void>;
|
|
366
|
-
/**
|
|
367
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Hands back what the querier holds, nothing where it holds no connection of its own. `discard` means the
|
|
369
|
+
* connection must not be reused; backends with a pool evict it instead.
|
|
370
|
+
*/
|
|
371
|
+
protected internalRelease(_discard: boolean): Promise<void>;
|
|
368
372
|
}
|