uql-orm 0.54.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +4 -4
- package/dist/bunSql/bunSql.util.d.ts +3 -14
- package/dist/bunSql/bunSql.util.js +33 -56
- package/dist/bunSql/bunSqlQuerier.d.ts +3 -6
- package/dist/bunSql/bunSqlQuerier.js +7 -13
- package/dist/bunSql/bunSqlQuerierPool.d.ts +10 -5
- package/dist/bunSql/bunSqlQuerierPool.js +25 -10
- package/dist/cockroachdb/crdbQuerierPool.d.ts +1 -3
- package/dist/cockroachdb/crdbQuerierPool.js +0 -4
- package/dist/cockroachdb/index.d.ts +0 -1
- package/dist/cockroachdb/index.js +0 -1
- package/dist/d1/d1SqliteDialect.d.ts +5 -0
- package/dist/d1/d1SqliteDialect.js +7 -0
- package/dist/dialect/abstractSqlDialect.d.ts +9 -9
- package/dist/dialect/abstractSqlDialect.js +38 -51
- package/dist/dialect/hydrateColumn.js +2 -2
- package/dist/dialect/mergeSqlDialect.d.ts +2 -2
- package/dist/dialect/mergeSqlDialect.js +0 -4
- package/dist/dialect/mysqlLikeSqlDialect.js +2 -3
- package/dist/dialect/pgLikeSqlDialect.d.ts +5 -0
- package/dist/dialect/pgLikeSqlDialect.js +14 -4
- package/dist/dialect/queryJoins.js +2 -4
- package/dist/entity/index.d.ts +1 -1
- package/dist/entity/index.js +1 -1
- package/dist/entity/metadata/definition.d.ts +5 -1
- package/dist/entity/metadata/definition.js +32 -26
- package/dist/libsql/index.d.ts +0 -1
- package/dist/libsql/index.js +0 -1
- package/dist/libsql/libsqlQuerierPool.d.ts +3 -5
- package/dist/libsql/libsqlQuerierPool.js +2 -5
- package/dist/maria/mariadbQuerier.d.ts +0 -3
- package/dist/maria/mariadbQuerier.js +6 -7
- package/dist/maria/mariadbQuerierPool.js +4 -7
- package/dist/migrate/builder/splitSqlStatements.js +2 -2
- package/dist/migrate/cli.js +2 -9
- package/dist/migrate/codegen/fieldOptionsSource.js +1 -1
- package/dist/migrate/ddl/index.d.ts +3 -3
- package/dist/migrate/ddl/index.js +3 -3
- package/dist/migrate/ddl/pgIndexDdl.d.ts +5 -0
- package/dist/migrate/ddl/pgIndexDdl.js +9 -0
- package/dist/migrate/drift/driftDetector.js +21 -8
- package/dist/migrate/generator/mongoSchemaGenerator.js +1 -1
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +65 -76
- package/dist/migrate/introspection/mssqlIntrospector.js +2 -1
- package/dist/migrate/introspection/mysqlIntrospector.js +5 -8
- package/dist/migrate/introspection/sqliteIntrospector.js +2 -5
- package/dist/migrate/migrator.d.ts +5 -2
- package/dist/migrate/migrator.js +9 -14
- package/dist/migrate/schemaGenerator.js +2 -6
- package/dist/mongo/index.d.ts +0 -1
- package/dist/mongo/index.js +0 -1
- package/dist/mongo/mongoDialect.d.ts +1 -2
- package/dist/mongo/mongoDialect.js +7 -21
- package/dist/mongo/mongodbQuerier.js +12 -11
- package/dist/mongo/mongodbQuerierPool.d.ts +2 -2
- package/dist/mongo/mongodbQuerierPool.js +2 -2
- package/dist/mssql/mssqlDialect.d.ts +3 -5
- package/dist/mssql/mssqlDialect.js +9 -8
- package/dist/mssql/mssqlQuerier.d.ts +13 -6
- package/dist/mssql/mssqlQuerier.js +30 -75
- package/dist/mssql/mssqlQuerierPool.js +2 -0
- package/dist/mssql/mssqlWireTypes.d.ts +3 -4
- package/dist/mssql/mssqlWireTypes.js +5 -8
- package/dist/mysql/index.d.ts +0 -1
- package/dist/mysql/index.js +0 -1
- package/dist/mysql/mysql2Querier.d.ts +1 -4
- package/dist/mysql/mysql2Querier.js +0 -3
- package/dist/mysql/mysql2QuerierPool.d.ts +2 -2
- package/dist/mysql/mysql2QuerierPool.js +5 -3
- package/dist/neon/index.d.ts +0 -2
- package/dist/neon/index.js +0 -2
- package/dist/neon/neonQuerierPool.d.ts +2 -4
- package/dist/neon/neonQuerierPool.js +2 -6
- package/dist/pglite/index.d.ts +0 -1
- package/dist/pglite/index.js +0 -1
- package/dist/pglite/pgliteQuerier.d.ts +3 -3
- package/dist/pglite/pgliteQuerier.js +1 -1
- package/dist/pglite/pgliteQuerierPool.d.ts +7 -2
- package/dist/pglite/pgliteQuerierPool.js +16 -6
- package/dist/postgres/abstractPgQuerierPool.d.ts +8 -12
- package/dist/postgres/abstractPgQuerierPool.js +8 -6
- package/dist/postgres/index.d.ts +0 -1
- package/dist/postgres/index.js +0 -1
- package/dist/postgres/pgNumericTypes.d.ts +5 -5
- package/dist/postgres/pgNumericTypes.js +11 -7
- package/dist/postgres/pgQuerier.d.ts +22 -4
- package/dist/postgres/pgQuerier.js +29 -2
- package/dist/postgres/pgQuerierPool.d.ts +2 -4
- package/dist/postgres/pgQuerierPool.js +2 -6
- package/dist/postgres/postgresDialect.d.ts +5 -5
- package/dist/postgres/postgresDialect.js +5 -5
- package/dist/postgres/postgresWireDriverCapabilities.d.ts +2 -2
- package/dist/postgres/postgresWireDriverCapabilities.js +2 -2
- package/dist/querier/abstractPoolQuerier.d.ts +1 -1
- package/dist/querier/abstractPoolQuerier.js +1 -1
- package/dist/querier/abstractQuerier.js +17 -22
- package/dist/querier/abstractSqlQuerier.d.ts +21 -12
- package/dist/querier/abstractSqlQuerier.js +61 -43
- package/dist/schema/canonicalType.js +0 -2
- package/dist/schema/dependencyGraph.js +2 -4
- package/dist/schema/indexDifferences.js +2 -2
- package/dist/schema/schemaASTBuilder.js +3 -10
- package/dist/schema/schemaASTDiffer.d.ts +10 -2
- package/dist/schema/schemaASTDiffer.js +12 -11
- package/dist/schema/types.d.ts +1 -1
- package/dist/sqlite/hranaQuerier.d.ts +6 -8
- package/dist/sqlite/hranaQuerier.js +13 -30
- package/dist/sqlite/hranaQuerierPool.d.ts +3 -4
- package/dist/sqlite/hranaQuerierPool.js +2 -1
- package/dist/sqlite/localSqliteQuerierPool.d.ts +3 -3
- package/dist/sqlite/localSqliteQuerierPool.js +4 -2
- package/dist/sqlite/nodeSqliteAdapter.d.ts +0 -1
- package/dist/sqlite/nodeSqliteQuerierPool.js +0 -2
- package/dist/sqlite/sqliteDialect.js +2 -1
- package/dist/sqlite/sqlitePragmas.d.ts +12 -0
- package/dist/sqlite/sqlitePragmas.js +15 -0
- package/dist/sqlite/sqliteQuerierPool.d.ts +0 -5
- package/dist/sqlite/sqliteQuerierPool.js +2 -13
- package/dist/turso/index.d.ts +0 -1
- package/dist/turso/index.js +0 -1
- package/dist/turso/tursoLocalQuerier.d.ts +0 -1
- package/dist/turso/tursoLocalQuerierPool.js +2 -2
- package/dist/turso/tursoQuerierPool.d.ts +1 -3
- package/dist/turso/tursoQuerierPool.js +0 -4
- package/dist/type/dialect.d.ts +1 -1
- package/dist/util/dialect.util.d.ts +8 -2
- package/dist/util/dialect.util.js +20 -1
- package/dist/util/logger.d.ts +17 -9
- package/dist/util/logger.js +36 -11
- package/dist/util/object.util.d.ts +2 -0
- package/dist/util/object.util.js +4 -0
- package/dist/util/raw.js +3 -3
- package/dist/util/relationQuery.util.d.ts +3 -3
- package/dist/util/relationQuery.util.js +8 -2
- package/dist/util/sqlLiteral.js +3 -8
- package/dist/util/string.util.js +2 -6
- package/dist/util/wideNumber.d.ts +14 -0
- package/dist/util/wideNumber.js +24 -0
- package/package.json +1 -1
- package/dist/cockroachdb/crdbQuerier.d.ts +0 -8
- package/dist/cockroachdb/crdbQuerier.js +0 -6
- package/dist/libsql/libsqlQuerier.d.ts +0 -10
- package/dist/libsql/libsqlQuerier.js +0 -10
- package/dist/mongo/mongodbNativeDialect.d.ts +0 -9
- package/dist/mongo/mongodbNativeDialect.js +0 -9
- package/dist/mysql/mysql2Dialect.d.ts +0 -9
- package/dist/mysql/mysql2Dialect.js +0 -9
- package/dist/neon/neonDialect.d.ts +0 -10
- package/dist/neon/neonDialect.js +0 -10
- package/dist/neon/neonQuerier.d.ts +0 -5
- package/dist/neon/neonQuerier.js +0 -3
- package/dist/pglite/pgliteDialect.d.ts +0 -14
- package/dist/pglite/pgliteDialect.js +0 -14
- package/dist/postgres/abstractPgQuerier.d.ts +0 -24
- package/dist/postgres/abstractPgQuerier.js +0 -32
- package/dist/postgres/pgDialect.d.ts +0 -10
- package/dist/postgres/pgDialect.js +0 -10
- package/dist/turso/tursoQuerier.d.ts +0 -10
- package/dist/turso/tursoQuerier.js +0 -10
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
|
|
2
2
|
import { AbstractSharedHandleQuerierPool } from '../querier/abstractSharedHandleQuerierPool.js';
|
|
3
|
+
import { applySqlitePragmas } from '../sqlite/sqlitePragmas.js';
|
|
3
4
|
import { TursoDialect } from './tursoDialect.js';
|
|
4
5
|
import { TursoLocalQuerier } from './tursoLocalQuerier.js';
|
|
5
6
|
/**
|
|
@@ -21,8 +22,7 @@ export class TursoLocalQuerierPool extends AbstractSharedHandleQuerierPool {
|
|
|
21
22
|
const { connect } = await import('@tursodatabase/database');
|
|
22
23
|
// Annotated rather than cast, so the structural contract is checked against the real driver.
|
|
23
24
|
const db = await connect(this.filename, this.opts);
|
|
24
|
-
await db
|
|
25
|
-
await db.pragma('foreign_keys = ON');
|
|
25
|
+
await applySqlitePragmas(db);
|
|
26
26
|
return db;
|
|
27
27
|
}
|
|
28
28
|
buildQuerier(db) {
|
|
@@ -2,7 +2,6 @@ import type { HranaClient } from '../sqlite/hranaQuerier.js';
|
|
|
2
2
|
import { AbstractHranaQuerierPool } from '../sqlite/hranaQuerierPool.js';
|
|
3
3
|
import type { ExtraOptions } from '../type/index.js';
|
|
4
4
|
import { TursoDialect } from './tursoDialect.js';
|
|
5
|
-
import { TursoQuerier } from './tursoQuerier.js';
|
|
6
5
|
/**
|
|
7
6
|
* Connection settings for Turso Cloud, mirroring `@tursodatabase/serverless`.
|
|
8
7
|
*
|
|
@@ -26,7 +25,7 @@ export type TursoConfig = {
|
|
|
26
25
|
* because over plain HTTP consecutive requests need not share a connection. Compat's session-backed
|
|
27
26
|
* transaction handle is the piece that makes it work.
|
|
28
27
|
*/
|
|
29
|
-
export declare class TursoQuerierPool extends AbstractHranaQuerierPool<
|
|
28
|
+
export declare class TursoQuerierPool extends AbstractHranaQuerierPool<TursoDialect> {
|
|
30
29
|
protected readonly ownsClient: boolean;
|
|
31
30
|
private readonly conf;
|
|
32
31
|
/**
|
|
@@ -35,5 +34,4 @@ export declare class TursoQuerierPool extends AbstractHranaQuerierPool<TursoQuer
|
|
|
35
34
|
*/
|
|
36
35
|
constructor(conf: TursoConfig | HranaClient, extra?: ExtraOptions);
|
|
37
36
|
protected openClient(): Promise<HranaClient>;
|
|
38
|
-
protected buildQuerier(client: HranaClient): TursoQuerier;
|
|
39
37
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
|
|
2
2
|
import { AbstractHranaQuerierPool } from '../sqlite/hranaQuerierPool.js';
|
|
3
3
|
import { TursoDialect } from './tursoDialect.js';
|
|
4
|
-
import { TursoQuerier } from './tursoQuerier.js';
|
|
5
4
|
function isClient(conf) {
|
|
6
5
|
return typeof conf.execute === 'function';
|
|
7
6
|
}
|
|
@@ -33,7 +32,4 @@ export class TursoQuerierPool extends AbstractHranaQuerierPool {
|
|
|
33
32
|
const { createClient } = await import('@tursodatabase/serverless/compat');
|
|
34
33
|
return createClient(this.conf);
|
|
35
34
|
}
|
|
36
|
-
buildQuerier(client) {
|
|
37
|
-
return new TursoQuerier(client, this.dialect, this.extra);
|
|
38
|
-
}
|
|
39
35
|
}
|
package/dist/type/dialect.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export interface DriverCapabilities {
|
|
|
59
59
|
readonly explicitJsonCast: boolean;
|
|
60
60
|
/**
|
|
61
61
|
* Whether the driver natively supports JS arrays for the underlying database type.
|
|
62
|
-
* `
|
|
62
|
+
* `PgQuerierPool` keeps this `true` for node-postgres; `BunSqlQuerierPool` sets `false` and binds
|
|
63
63
|
* `toPgArray` string literals instead.
|
|
64
64
|
*/
|
|
65
65
|
readonly nativeArrays: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CascadeType, type EntityData, type EntityId, type EntityIndexMeta, type EntityMeta, type FieldKey, type FieldOptions, type JsonUpdateOp, type OnFieldCallback, type Query, type QueryAggMap, type QueryAggregateOp, type QueryExclude, type QueryGroupMap, type QueryOptions, QueryRaw, type QuerySearch, type QuerySelect, type QuerySelectValue, type QuerySizeComparisonOps, type QuerySortMap, type QueryVectorSearch, type QueryWhere, type RelationKey, type UpdatePayload } from '../type/index.js';
|
|
1
|
+
import { type CascadeType, type EntityData, type EntityId, type EntityIndexMeta, type EntityMeta, type FieldKey, type FieldOptions, type JsonUpdateOp, type OnFieldCallback, type Query, type QueryAggMap, type QueryAggregateOp, type QueryExclude, type QueryGroupMap, type QueryOptions, QueryRaw, type QuerySearch, type QuerySelect, type QuerySelectValue, type QuerySizeComparisonOps, type QuerySortMap, type QueryTextSearchOptions, type QueryVectorSearch, type QueryWhere, type RelationKey, type UpdatePayload } from '../type/index.js';
|
|
2
2
|
export type CallbackKey = keyof Pick<FieldOptions, 'onInsert' | 'onUpdate'>;
|
|
3
3
|
export declare function filterFieldKeys<E>(meta: EntityMeta<E>, payload: EntityData<E>, callbackKey: CallbackKey): FieldKey<E>[];
|
|
4
4
|
/** Appends `record`'s not-yet-`seen` insertable keys (real, caller-written, defined value) to `keys`. */
|
|
@@ -170,4 +170,10 @@ export declare function assertNonNegativeInteger(value: number, clause: string):
|
|
|
170
170
|
*/
|
|
171
171
|
export declare function throwUnknownAggregateColumn(key: string, clause: string): never;
|
|
172
172
|
/** {@link throwUnknownAggregateColumn} over every key of a clause, for backends that check up front. */
|
|
173
|
-
export declare function assertAggregateColumns(clauseMap: object
|
|
173
|
+
export declare function assertAggregateColumns(clauseMap: object, emitted: ReadonlySet<string>, clause: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* The fields a `$text` searches: those it names, or else the columns of the entity's fulltext index,
|
|
176
|
+
* the declaration MySQL's `MATCH` has to name exactly and a MongoDB text index already is. Refused
|
|
177
|
+
* where neither says, rather than guessed: every engine answers a guess with an error of its own.
|
|
178
|
+
*/
|
|
179
|
+
export declare function textSearchFields<E>(meta: EntityMeta<E>, search: QueryTextSearchOptions<E>): readonly string[];
|
|
@@ -418,9 +418,28 @@ export function throwUnknownAggregateColumn(key, clause) {
|
|
|
418
418
|
}
|
|
419
419
|
/** {@link throwUnknownAggregateColumn} over every key of a clause, for backends that check up front. */
|
|
420
420
|
export function assertAggregateColumns(clauseMap, emitted, clause) {
|
|
421
|
-
for (const key of getKeys(clauseMap
|
|
421
|
+
for (const key of getKeys(clauseMap)) {
|
|
422
422
|
if (!emitted.has(key)) {
|
|
423
423
|
throwUnknownAggregateColumn(key, clause);
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* The fields a `$text` searches: those it names, or else the columns of the entity's fulltext index,
|
|
429
|
+
* the declaration MySQL's `MATCH` has to name exactly and a MongoDB text index already is. Refused
|
|
430
|
+
* where neither says, rather than guessed: every engine answers a guess with an error of its own.
|
|
431
|
+
*/
|
|
432
|
+
export function textSearchFields(meta, search) {
|
|
433
|
+
if (search.$fields?.length) {
|
|
434
|
+
return search.$fields;
|
|
435
|
+
}
|
|
436
|
+
const fulltext = (meta.indexes ?? []).filter((index) => index.type === 'fulltext');
|
|
437
|
+
if (fulltext.length === 1) {
|
|
438
|
+
return fulltext[0].columns.map((entry) => entry.column);
|
|
439
|
+
}
|
|
440
|
+
const name = entityName(meta);
|
|
441
|
+
const declared = fulltext.length
|
|
442
|
+
? `${fulltext.length} fulltext indexes to choose from`
|
|
443
|
+
: 'no fulltext index to search';
|
|
444
|
+
throw new TypeError(`$text on '${name}' names no $fields, and '${name}' declares ${declared}. Name them with $fields.`);
|
|
445
|
+
}
|
package/dist/util/logger.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class LoggerWrapper implements Logger {
|
|
|
34
34
|
private readonly loggerFunction?;
|
|
35
35
|
private readonly logValues;
|
|
36
36
|
private readonly slowQuery?;
|
|
37
|
-
constructor(options
|
|
37
|
+
constructor(options?: LoggingOptions, config?: LoggerWrapperConfig);
|
|
38
38
|
/** Whether `logQuery` would ever actually surface bound values, given the configured levels/slowQuery/logValues. */
|
|
39
39
|
willLogValues(): boolean;
|
|
40
40
|
logQuery(query: string, values?: unknown[], duration?: number): void;
|
|
@@ -46,6 +46,15 @@ export declare class LoggerWrapper implements Logger {
|
|
|
46
46
|
logSkippedMigration(message: string): void;
|
|
47
47
|
private log;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The wrapper a querier logs through, one per options object and read once: a pool builds a querier
|
|
51
|
+
* for every statement, and all of them log by the same options.
|
|
52
|
+
*/
|
|
53
|
+
export declare function queryLoggerFor(extra?: {
|
|
54
|
+
readonly logger?: LoggingOptions;
|
|
55
|
+
readonly logValues?: boolean;
|
|
56
|
+
readonly slowQuery?: number;
|
|
57
|
+
}): LoggerWrapper;
|
|
49
58
|
/**
|
|
50
59
|
* Structural type for any EventEmitter-like connection pool that emits an
|
|
51
60
|
* `'error'` event on a dropped connection (node-postgres, `mariadb`, etc.).
|
|
@@ -54,12 +63,11 @@ export interface ErrorEmittingPool {
|
|
|
54
63
|
on(event: 'error', listener: (err: Error) => void): unknown;
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
|
-
* Attaches an error listener to a connection pool so a dropped connection is
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* swallowed pool error is exactly the failure mode this guards against.
|
|
66
|
+
* Attaches an error listener to a connection pool so a dropped connection is logged instead of left
|
|
67
|
+
* unhandled - which crashes the process for drivers that don't guard against it themselves
|
|
68
|
+
* (node-postgres, `mssql`), or is silently swallowed by those that install a no-op of their own
|
|
69
|
+
* (`mariadb`). Reported through the pool's own logger when it has one, and through the default one
|
|
70
|
+
* otherwise: never dropped, whatever levels were configured, since a swallowed pool error is exactly
|
|
71
|
+
* the failure this guards against.
|
|
64
72
|
*/
|
|
65
|
-
export declare function attachPoolErrorHandler(pool: ErrorEmittingPool, message: string): void;
|
|
73
|
+
export declare function attachPoolErrorHandler(pool: ErrorEmittingPool, message: string, logging?: LoggingOptions): void;
|
package/dist/util/logger.js
CHANGED
|
@@ -7,18 +7,22 @@ const DEFAULT_LOG_LEVELS = [
|
|
|
7
7
|
'migration',
|
|
8
8
|
'skippedMigration',
|
|
9
9
|
];
|
|
10
|
+
/** Bound values as JSON, a `bigint` by its digits: `JSON.stringify` refuses one outright. */
|
|
11
|
+
function renderValues(values) {
|
|
12
|
+
return JSON.stringify(values, (_key, value) => (typeof value === 'bigint' ? value.toString() : value));
|
|
13
|
+
}
|
|
10
14
|
/**
|
|
11
15
|
* Default implementation of the Logger interface using console methods.
|
|
12
16
|
*/
|
|
13
17
|
export class DefaultLogger {
|
|
14
18
|
logQuery(query, values, duration) {
|
|
15
19
|
const time = duration !== undefined ? ` [${duration}ms]` : '';
|
|
16
|
-
const params = values?.length ? ` -- ${
|
|
20
|
+
const params = values?.length ? ` -- ${renderValues(values)}` : '';
|
|
17
21
|
console.log(`\x1b[36mquery:\x1b[0m ${query}${params}\x1b[32m${time}\x1b[0m`);
|
|
18
22
|
}
|
|
19
23
|
logSlowQuery(query, values, duration) {
|
|
20
24
|
const time = duration !== undefined ? ` [${duration}ms]` : '';
|
|
21
|
-
const params = values?.length ? ` -- ${
|
|
25
|
+
const params = values?.length ? ` -- ${renderValues(values)}` : '';
|
|
22
26
|
console.warn(`\x1b[33mslow query:\x1b[0m ${query}${params}\x1b[31m${time}\x1b[0m`);
|
|
23
27
|
}
|
|
24
28
|
logWarn(message) {
|
|
@@ -132,18 +136,39 @@ export class LoggerWrapper {
|
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
}
|
|
139
|
+
const wrappersByOptions = new WeakMap();
|
|
140
|
+
let unconfigured;
|
|
135
141
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* that don't guard against it themselves (node-postgres), or silently
|
|
139
|
-
* swallowed with zero visibility for drivers that already install their own
|
|
140
|
-
* no-op safety net (`mariadb`'s `createPool`). Always logs via a dedicated
|
|
141
|
-
* logger (ignoring the consumer's configured log level) since a silently
|
|
142
|
-
* swallowed pool error is exactly the failure mode this guards against.
|
|
142
|
+
* The wrapper a querier logs through, one per options object and read once: a pool builds a querier
|
|
143
|
+
* for every statement, and all of them log by the same options.
|
|
143
144
|
*/
|
|
144
|
-
export function
|
|
145
|
-
|
|
145
|
+
export function queryLoggerFor(extra) {
|
|
146
|
+
if (!extra) {
|
|
147
|
+
unconfigured ??= new LoggerWrapper();
|
|
148
|
+
return unconfigured;
|
|
149
|
+
}
|
|
150
|
+
let wrapper = wrappersByOptions.get(extra);
|
|
151
|
+
if (!wrapper) {
|
|
152
|
+
wrapper = new LoggerWrapper(extra.logger, { logValues: extra.logValues, slowQuery: extra.slowQuery });
|
|
153
|
+
wrappersByOptions.set(extra, wrapper);
|
|
154
|
+
}
|
|
155
|
+
return wrapper;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Attaches an error listener to a connection pool so a dropped connection is logged instead of left
|
|
159
|
+
* unhandled - which crashes the process for drivers that don't guard against it themselves
|
|
160
|
+
* (node-postgres, `mssql`), or is silently swallowed by those that install a no-op of their own
|
|
161
|
+
* (`mariadb`). Reported through the pool's own logger when it has one, and through the default one
|
|
162
|
+
* otherwise: never dropped, whatever levels were configured, since a swallowed pool error is exactly
|
|
163
|
+
* the failure this guards against.
|
|
164
|
+
*/
|
|
165
|
+
export function attachPoolErrorHandler(pool, message, logging) {
|
|
166
|
+
const logger = new LoggerWrapper(isOwnLogger(logging) ? logging : true);
|
|
146
167
|
pool.on('error', (err) => {
|
|
147
168
|
logger.logError(message, err);
|
|
148
169
|
});
|
|
149
170
|
}
|
|
171
|
+
/** A logger the consumer wrote, as opposed to a switch or a level list for the default one. */
|
|
172
|
+
function isOwnLogger(logging) {
|
|
173
|
+
return typeof logging === 'function' || (typeof logging === 'object' && !Array.isArray(logging));
|
|
174
|
+
}
|
|
@@ -20,6 +20,8 @@ export declare function isOperatorObject(value: unknown): value is Record<string
|
|
|
20
20
|
/** Whether every key of the non-empty object `value` is an operator (no plain field names mixed in). */
|
|
21
21
|
export declare function isOperatorOnlyObject(value: unknown): value is Record<string, unknown>;
|
|
22
22
|
export declare function getKeys<T extends object>(obj: T): (keyof T & string)[];
|
|
23
|
+
/** The entries of `record` holding a value: a key declared but left `undefined` is no entry at all. */
|
|
24
|
+
export declare function definedEntries<K extends string, V>(record: Partial<Record<K, V>>): [K, V][];
|
|
23
25
|
/**
|
|
24
26
|
* The entity's own name, declared or its class's. `meta.name` holds only what the author wrote, so
|
|
25
27
|
* the fallback is what an entity that named no table is called - which is why the sites spelling this
|
package/dist/util/object.util.js
CHANGED
|
@@ -52,6 +52,10 @@ export function isOperatorOnlyObject(value) {
|
|
|
52
52
|
export function getKeys(obj) {
|
|
53
53
|
return obj ? Object.keys(obj) : [];
|
|
54
54
|
}
|
|
55
|
+
/** The entries of `record` holding a value: a key declared but left `undefined` is no entry at all. */
|
|
56
|
+
export function definedEntries(record) {
|
|
57
|
+
return Object.entries(record).filter((entry) => entry[1] !== undefined);
|
|
58
|
+
}
|
|
55
59
|
/**
|
|
56
60
|
* The entity's own name, declared or its class's. `meta.name` holds only what the author wrote, so
|
|
57
61
|
* the fallback is what an entity that named no table is called - which is why the sites spelling this
|
package/dist/util/raw.js
CHANGED
|
@@ -7,11 +7,11 @@ export function raw(value, ...rest) {
|
|
|
7
7
|
if (!rest.length) {
|
|
8
8
|
// Nothing to bind, so this is the string form: keep it one, for the DDL paths that need to read
|
|
9
9
|
// the expression back as text (an index expression cannot carry a parameter).
|
|
10
|
-
return new QueryRaw(value[0]
|
|
10
|
+
return new QueryRaw(value[0]);
|
|
11
11
|
}
|
|
12
12
|
return new QueryRaw((opts) => {
|
|
13
13
|
const { ctx } = opts;
|
|
14
|
-
ctx.append(value[0]
|
|
14
|
+
ctx.append(value[0]);
|
|
15
15
|
rest.forEach((interpolated, i) => {
|
|
16
16
|
if (interpolated instanceof QueryRaw) {
|
|
17
17
|
interpolated.render(opts);
|
|
@@ -19,7 +19,7 @@ export function raw(value, ...rest) {
|
|
|
19
19
|
else {
|
|
20
20
|
ctx.addValue(interpolated);
|
|
21
21
|
}
|
|
22
|
-
ctx.append(value[i + 1]
|
|
22
|
+
ctx.append(value[i + 1]);
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { EntityMeta, FieldMeta, Except, Query, QueryPopulate, RelationKey, RelationMeta } from '../type/index.js';
|
|
2
2
|
export type RelationRequestSummary<E> = {
|
|
3
|
-
readonly requestedKeys: RelationKey<E>[];
|
|
4
|
-
readonly joinableKeys: RelationKey<E>[];
|
|
5
|
-
readonly toManyKeys: RelationKey<E>[];
|
|
3
|
+
readonly requestedKeys: readonly RelationKey<E>[];
|
|
4
|
+
readonly joinableKeys: readonly RelationKey<E>[];
|
|
5
|
+
readonly toManyKeys: readonly RelationKey<E>[];
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Whether a relation holds many rows per parent, so it cannot be joined into the parent's row. Takes
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { QUERY_BOOLEAN_CLAUSES, QUERY_NUMBER_CLAUSES, QUERY_OBJECT_CLAUSES, QUERY_ROOT_NUMBER_CLAUSES, } from '../type/query.js';
|
|
2
2
|
import { getKeys, someKey } from './object.util.js';
|
|
3
|
+
/** What a query populating nothing requests, shared: most reads populate nothing, and ask on every one. */
|
|
4
|
+
const NOTHING_REQUESTED = Object.freeze({
|
|
5
|
+
requestedKeys: Object.freeze([]),
|
|
6
|
+
joinableKeys: Object.freeze([]),
|
|
7
|
+
toManyKeys: Object.freeze([]),
|
|
8
|
+
});
|
|
3
9
|
/**
|
|
4
10
|
* Whether a relation holds many rows per parent, so it cannot be joined into the parent's row. Takes
|
|
5
11
|
* the one field it reads, so it answers for a relation being declared as well as for a resolved one.
|
|
@@ -142,11 +148,11 @@ function assertJoinableRelationQuery(relKey, value) {
|
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
150
|
export function getRelationRequestSummary(meta, populate) {
|
|
151
|
+
if (!populate)
|
|
152
|
+
return NOTHING_REQUESTED;
|
|
145
153
|
const requestedKeys = [];
|
|
146
154
|
const joinableKeys = [];
|
|
147
155
|
const toManyKeys = [];
|
|
148
|
-
if (!populate)
|
|
149
|
-
return { requestedKeys, joinableKeys, toManyKeys };
|
|
150
156
|
for (const key of getKeys(populate)) {
|
|
151
157
|
if (!populate[key])
|
|
152
158
|
continue;
|
package/dist/util/sqlLiteral.js
CHANGED
|
@@ -33,9 +33,6 @@ const MYSQL_ESCAPES = {
|
|
|
33
33
|
};
|
|
34
34
|
const mysqlStringLiteral = (val) => `'${val.replace(MYSQL_SPECIALS, (char) => MYSQL_ESCAPES[char])}'`;
|
|
35
35
|
const pad = (value, len) => String(value).padStart(len, '0');
|
|
36
|
-
function isByteSource(val) {
|
|
37
|
-
return (typeof Buffer !== 'undefined' && Buffer.isBuffer(val)) || val instanceof Uint8Array;
|
|
38
|
-
}
|
|
39
36
|
const HEX_BYTES = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, '0'));
|
|
40
37
|
/** Native hex encoder where available (~130x faster on 4 KB); lookup table for browsers. */
|
|
41
38
|
function bytesToHexLiteral(bytes) {
|
|
@@ -72,7 +69,8 @@ function createEscaper(escapeString) {
|
|
|
72
69
|
if (Array.isArray(value)) {
|
|
73
70
|
return sqlList(value);
|
|
74
71
|
}
|
|
75
|
-
|
|
72
|
+
// A Node `Buffer` is a `Uint8Array` too.
|
|
73
|
+
if (value instanceof Uint8Array) {
|
|
76
74
|
return bytesToHexLiteral(value);
|
|
77
75
|
}
|
|
78
76
|
if ('toSqlString' in value && typeof value.toSqlString === 'function') {
|
|
@@ -95,11 +93,8 @@ function createEscaper(escapeString) {
|
|
|
95
93
|
return escapeString(value);
|
|
96
94
|
case 'object':
|
|
97
95
|
return escapeObject(value);
|
|
98
|
-
case 'symbol':
|
|
99
|
-
case 'function':
|
|
100
|
-
throw new TypeError('escapeSqlLiteral: symbol and function values are not supported; use bound parameters.');
|
|
101
96
|
default:
|
|
102
|
-
//
|
|
97
|
+
// A symbol or a function, or a future JS type: none of them may silently become SQL.
|
|
103
98
|
throw new TypeError(`escapeSqlLiteral: unsupported value type '${typeof value}'; use bound parameters.`);
|
|
104
99
|
}
|
|
105
100
|
};
|
package/dist/util/string.util.js
CHANGED
|
@@ -6,14 +6,10 @@ export function kebabCase(val) {
|
|
|
6
6
|
return resp;
|
|
7
7
|
}
|
|
8
8
|
export function upperFirst(text) {
|
|
9
|
-
|
|
10
|
-
return text;
|
|
11
|
-
return text[0].toUpperCase() + text.slice(1);
|
|
9
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
12
10
|
}
|
|
13
11
|
export function lowerFirst(text) {
|
|
14
|
-
|
|
15
|
-
return text;
|
|
16
|
-
return text[0].toLowerCase() + text.slice(1);
|
|
12
|
+
return text.charAt(0).toLowerCase() + text.slice(1);
|
|
17
13
|
}
|
|
18
14
|
export function snakeCase(val) {
|
|
19
15
|
if (val === null || val === undefined)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RawRow } from '../type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A wide number as a JS number where that number is exact, and as its exact decimal text where it is
|
|
4
|
+
* not - past 2^53, where a number silently rounds. The one rule every driver decodes a BIGINT by, and
|
|
5
|
+
* hydration a numeric column a driver handed back as text: never a wrong number. `type: BigInt` is the
|
|
6
|
+
* declared way to a typed exact integer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function decodeWideNumber(value: string | bigint): number | string;
|
|
9
|
+
/**
|
|
10
|
+
* {@link decodeWideNumber} over every `bigint` cell of a row, for the drivers that hand a BIGINT back
|
|
11
|
+
* as one (`bun:sql` with `bigint: true`, `mariadb`). In place: the row is the driver's fresh object, and
|
|
12
|
+
* a copy per row cost more than the decode it carried.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeBigInts(row: RawRow): RawRow;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wide number as a JS number where that number is exact, and as its exact decimal text where it is
|
|
3
|
+
* not - past 2^53, where a number silently rounds. The one rule every driver decodes a BIGINT by, and
|
|
4
|
+
* hydration a numeric column a driver handed back as text: never a wrong number. `type: BigInt` is the
|
|
5
|
+
* declared way to a typed exact integer.
|
|
6
|
+
*/
|
|
7
|
+
export function decodeWideNumber(value) {
|
|
8
|
+
const decoded = Number(value);
|
|
9
|
+
return Math.abs(decoded) <= Number.MAX_SAFE_INTEGER ? decoded : String(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* {@link decodeWideNumber} over every `bigint` cell of a row, for the drivers that hand a BIGINT back
|
|
13
|
+
* as one (`bun:sql` with `bigint: true`, `mariadb`). In place: the row is the driver's fresh object, and
|
|
14
|
+
* a copy per row cost more than the decode it carried.
|
|
15
|
+
*/
|
|
16
|
+
export function decodeBigInts(row) {
|
|
17
|
+
for (const key in row) {
|
|
18
|
+
const value = row[key];
|
|
19
|
+
if (typeof value === 'bigint') {
|
|
20
|
+
row[key] = decodeWideNumber(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return row;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
4
|
"description": "The JSON-native TypeScript ORM for Bun, Browsers, Edge, Deno, Node, Workers. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.56.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PoolClient } from 'pg';
|
|
2
|
-
import { AbstractPgQuerier } from '../postgres/abstractPgQuerier.js';
|
|
3
|
-
import type { CockroachDialect } from './cockroachDialect.js';
|
|
4
|
-
/**
|
|
5
|
-
* Querier for CockroachDB utilizing the standard `pg` PoolClient.
|
|
6
|
-
*/
|
|
7
|
-
export declare class CrdbQuerier extends AbstractPgQuerier<PoolClient, CockroachDialect> {
|
|
8
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { HranaQuerier } from '../sqlite/hranaQuerier.js';
|
|
2
|
-
/**
|
|
3
|
-
* Querier for the `@libsql/client` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Empty subclass by design: that client speaks the Hrana protocol, so the whole
|
|
6
|
-
* implementation is inherited. Kept as a distinct type for `LibsqlQuerierPool` and as a hook for
|
|
7
|
-
* future libsql-specific behavior.
|
|
8
|
-
*/
|
|
9
|
-
export declare class LibsqlQuerier extends HranaQuerier {
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { HranaQuerier } from '../sqlite/hranaQuerier.js';
|
|
2
|
-
/**
|
|
3
|
-
* Querier for the `@libsql/client` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Empty subclass by design: that client speaks the Hrana protocol, so the whole
|
|
6
|
-
* implementation is inherited. Kept as a distinct type for `LibsqlQuerierPool` and as a hook for
|
|
7
|
-
* future libsql-specific behavior.
|
|
8
|
-
*/
|
|
9
|
-
export class LibsqlQuerier extends HranaQuerier {
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MongoDialect } from './mongoDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* MongoDB Dialect specialization for the official `mongodb` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Empty subclass by design: distinct type for `MongodbQuerierPool` and a hook
|
|
6
|
-
* for future driver-specific behavior.
|
|
7
|
-
*/
|
|
8
|
-
export declare class MongodbNativeDialect extends MongoDialect {
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MongoDialect } from './mongoDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* MongoDB Dialect specialization for the official `mongodb` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Empty subclass by design: distinct type for `MongodbQuerierPool` and a hook
|
|
6
|
-
* for future driver-specific behavior.
|
|
7
|
-
*/
|
|
8
|
-
export class MongodbNativeDialect extends MongoDialect {
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MySqlDialect } from './mysqlDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* MySQL Dialect specialization for the `mysql2` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Empty subclass by design: distinct type for `Mysql2QuerierPool` and a place
|
|
6
|
-
* for future mysql2-specific query or capability overrides.
|
|
7
|
-
*/
|
|
8
|
-
export declare class MySql2Dialect extends MySqlDialect {
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MySqlDialect } from './mysqlDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* MySQL Dialect specialization for the `mysql2` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Empty subclass by design: distinct type for `Mysql2QuerierPool` and a place
|
|
6
|
-
* for future mysql2-specific query or capability overrides.
|
|
7
|
-
*/
|
|
8
|
-
export class MySql2Dialect extends MySqlDialect {
|
|
9
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* Postgres dialect marker for the `@neondatabase/serverless` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Extends {@link PostgresDialect} with identical defaults (`explicitJsonCast: false`,
|
|
6
|
-
* `nativeArrays: true`, etc.). Kept as a distinct class for `NeonQuerierPool` typing and for
|
|
7
|
-
* Neon-only capability tweaks later without affecting `pg` or Bun pools.
|
|
8
|
-
*/
|
|
9
|
-
export declare class NeonDialect extends PostgresDialect {
|
|
10
|
-
}
|
package/dist/neon/neonDialect.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* Postgres dialect marker for the `@neondatabase/serverless` driver.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Extends {@link PostgresDialect} with identical defaults (`explicitJsonCast: false`,
|
|
6
|
-
* `nativeArrays: true`, etc.). Kept as a distinct class for `NeonQuerierPool` typing and for
|
|
7
|
-
* Neon-only capability tweaks later without affecting `pg` or Bun pools.
|
|
8
|
-
*/
|
|
9
|
-
export class NeonDialect extends PostgresDialect {
|
|
10
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { PoolClient } from '@neondatabase/serverless';
|
|
2
|
-
import { AbstractPgQuerier } from '../postgres/abstractPgQuerier.js';
|
|
3
|
-
import type { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
4
|
-
export declare class NeonQuerier extends AbstractPgQuerier<PoolClient, PostgresDialect> {
|
|
5
|
-
}
|
package/dist/neon/neonQuerier.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* Postgres dialect for PGlite, the WASM Postgres build.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Keeps every {@link PostgresDialect} default, `dialectName` included: PGlite *is* Postgres,
|
|
6
|
-
* so the introspector, schema generator and CLI must all resolve to the Postgres ones. Both driver
|
|
7
|
-
* capabilities are inherited deliberately rather than by omission. `nativeArrays: true` holds because
|
|
8
|
-
* PGlite registers an array serializer for every built-in array type at boot and resolves each
|
|
9
|
-
* parameter's type from a server-side `Describe` before binding; `explicitJsonCast: false` holds
|
|
10
|
-
* because `PgLikeSqlDialect` already emits `$n::jsonb`, which is what makes that `Describe` report
|
|
11
|
-
* JSONB and select PGlite's `JSON.stringify` serializer. A bare `$n` would bind `[object Object]`.
|
|
12
|
-
*/
|
|
13
|
-
export declare class PgliteDialect extends PostgresDialect {
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PostgresDialect } from '../postgres/postgresDialect.js';
|
|
2
|
-
/**
|
|
3
|
-
* Postgres dialect for PGlite, the WASM Postgres build.
|
|
4
|
-
*
|
|
5
|
-
* @remarks Keeps every {@link PostgresDialect} default, `dialectName` included: PGlite *is* Postgres,
|
|
6
|
-
* so the introspector, schema generator and CLI must all resolve to the Postgres ones. Both driver
|
|
7
|
-
* capabilities are inherited deliberately rather than by omission. `nativeArrays: true` holds because
|
|
8
|
-
* PGlite registers an array serializer for every built-in array type at boot and resolves each
|
|
9
|
-
* parameter's type from a server-side `Describe` before binding; `explicitJsonCast: false` holds
|
|
10
|
-
* because `PgLikeSqlDialect` already emits `$n::jsonb`, which is what makes that `Describe` report
|
|
11
|
-
* JSONB and select PGlite's `JSON.stringify` serializer. A bare `$n` would bind `[object Object]`.
|
|
12
|
-
*/
|
|
13
|
-
export class PgliteDialect extends PostgresDialect {
|
|
14
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
2
|
-
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
3
|
-
import type { ExtraOptions, RawRow } from '../type/index.js';
|
|
4
|
-
export interface PgAnyClient {
|
|
5
|
-
query(text: string, values?: unknown[]): Promise<{
|
|
6
|
-
rows: RawRow[];
|
|
7
|
-
rowCount: number | null;
|
|
8
|
-
}>;
|
|
9
|
-
query(stream: object): AsyncIterable<RawRow> & {
|
|
10
|
-
destroy(): void;
|
|
11
|
-
};
|
|
12
|
-
/** Any truthy argument makes `pg-pool` evict the client instead of returning it to the idle list. */
|
|
13
|
-
release(discard?: boolean): void | Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Shared base class for Postgres-compatible queriers (standard pg, CockroachDB, Neon).
|
|
17
|
-
*/
|
|
18
|
-
export declare abstract class AbstractPgQuerier<C extends PgAnyClient, D extends AbstractSqlDialect> extends AbstractPoolQuerier<C> {
|
|
19
|
-
constructor(connect: () => Promise<C>, dialect: D, extra?: ExtraOptions);
|
|
20
|
-
internalAll<T>(query: string, values?: unknown[]): Promise<T[]>;
|
|
21
|
-
internalRun(query: string, values?: unknown[]): Promise<import("../type/query.js").QueryUpdateResult>;
|
|
22
|
-
internalStream<T>(query: string, values?: unknown[]): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
23
|
-
protected releaseConn(conn: C, discard: boolean): Promise<void>;
|
|
24
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
|
|
2
|
-
/**
|
|
3
|
-
* Shared base class for Postgres-compatible queriers (standard pg, CockroachDB, Neon).
|
|
4
|
-
*/
|
|
5
|
-
export class AbstractPgQuerier extends AbstractPoolQuerier {
|
|
6
|
-
constructor(connect, dialect, extra) {
|
|
7
|
-
super(dialect, connect, extra);
|
|
8
|
-
}
|
|
9
|
-
async internalAll(query, values) {
|
|
10
|
-
const res = await this.getConn().query(query, values);
|
|
11
|
-
return res.rows;
|
|
12
|
-
}
|
|
13
|
-
async internalRun(query, values) {
|
|
14
|
-
const res = await this.getConn().query(query, values);
|
|
15
|
-
return this.buildUpdateResult({ rows: res.rows, changes: res.rowCount ?? 0 });
|
|
16
|
-
}
|
|
17
|
-
async *internalStream(query, values) {
|
|
18
|
-
const { default: QueryStream } = await import('pg-query-stream');
|
|
19
|
-
const stream = this.getConn().query(new QueryStream(query, values));
|
|
20
|
-
try {
|
|
21
|
-
for await (const row of stream) {
|
|
22
|
-
yield row;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
stream.destroy();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async releaseConn(conn, discard) {
|
|
30
|
-
await conn.release(discard);
|
|
31
|
-
}
|
|
32
|
-
}
|