kysely 0.28.2 → 0.28.4
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/dist/cjs/dialect/mssql/mssql-driver.d.ts +3 -2
- package/dist/cjs/dialect/mssql/mssql-driver.js +68 -57
- package/dist/cjs/dialect/postgres/postgres-introspector.js +2 -0
- package/dist/cjs/helpers/mssql.d.ts +4 -4
- package/dist/cjs/helpers/mysql.d.ts +4 -4
- package/dist/cjs/helpers/postgres.d.ts +4 -4
- package/dist/cjs/helpers/sqlite.d.ts +4 -4
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/kysely.d.ts +4 -0
- package/dist/cjs/kysely.js +12 -6
- package/dist/cjs/migration/migrator.js +2 -1
- package/dist/cjs/parser/delete-from-parser.d.ts +5 -1
- package/dist/cjs/parser/merge-into-parser.d.ts +3 -1
- package/dist/cjs/parser/select-from-parser.d.ts +3 -1
- package/dist/cjs/parser/update-parser.d.ts +5 -1
- package/dist/cjs/query-builder/delete-query-builder.js +2 -2
- package/dist/cjs/query-builder/function-module.d.ts +6 -6
- package/dist/cjs/query-builder/insert-query-builder.js +2 -2
- package/dist/cjs/query-builder/merge-query-builder.js +1 -1
- package/dist/cjs/query-builder/select-query-builder.js +2 -2
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +1 -4
- package/dist/cjs/query-executor/query-executor-base.d.ts +2 -2
- package/dist/cjs/query-executor/query-executor-base.js +4 -4
- package/dist/cjs/query-executor/query-executor.d.ts +2 -2
- package/dist/cjs/raw-builder/raw-builder.js +1 -1
- package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.js +1 -1
- package/dist/cjs/schema/alter-table-add-index-builder.js +1 -1
- package/dist/cjs/schema/alter-table-builder.js +1 -1
- package/dist/cjs/schema/alter-table-drop-constraint-builder.js +1 -1
- package/dist/cjs/schema/alter-table-executor.js +1 -1
- package/dist/cjs/schema/create-index-builder.js +1 -1
- package/dist/cjs/schema/create-schema-builder.js +1 -1
- package/dist/cjs/schema/create-table-builder.js +1 -1
- package/dist/cjs/schema/create-type-builder.js +1 -1
- package/dist/cjs/schema/create-view-builder.js +1 -1
- package/dist/cjs/schema/drop-index-builder.js +1 -1
- package/dist/cjs/schema/drop-schema-builder.js +1 -1
- package/dist/cjs/schema/drop-table-builder.js +1 -1
- package/dist/cjs/schema/drop-type-builder.js +1 -1
- package/dist/cjs/schema/drop-view-builder.js +1 -1
- package/dist/cjs/schema/refresh-materialized-view-builder.js +1 -1
- package/dist/cjs/util/type-utils.d.ts +18 -0
- package/dist/esm/dialect/mssql/mssql-driver.d.ts +3 -2
- package/dist/esm/dialect/mssql/mssql-driver.js +68 -57
- package/dist/esm/dialect/postgres/postgres-introspector.js +2 -0
- package/dist/esm/helpers/mssql.d.ts +4 -4
- package/dist/esm/helpers/mysql.d.ts +4 -4
- package/dist/esm/helpers/postgres.d.ts +4 -4
- package/dist/esm/helpers/sqlite.d.ts +4 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/kysely.d.ts +4 -0
- package/dist/esm/kysely.js +12 -6
- package/dist/esm/migration/migrator.js +3 -2
- package/dist/esm/parser/delete-from-parser.d.ts +5 -1
- package/dist/esm/parser/merge-into-parser.d.ts +3 -1
- package/dist/esm/parser/select-from-parser.d.ts +3 -1
- package/dist/esm/parser/update-parser.d.ts +5 -1
- package/dist/esm/query-builder/delete-query-builder.js +2 -2
- package/dist/esm/query-builder/function-module.d.ts +6 -6
- package/dist/esm/query-builder/insert-query-builder.js +2 -2
- package/dist/esm/query-builder/merge-query-builder.js +1 -1
- package/dist/esm/query-builder/select-query-builder.js +2 -2
- package/dist/esm/query-builder/update-query-builder.js +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +1 -4
- package/dist/esm/query-executor/query-executor-base.d.ts +2 -2
- package/dist/esm/query-executor/query-executor-base.js +4 -4
- package/dist/esm/query-executor/query-executor.d.ts +2 -2
- package/dist/esm/raw-builder/raw-builder.js +1 -1
- package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js +1 -1
- package/dist/esm/schema/alter-table-add-index-builder.js +1 -1
- package/dist/esm/schema/alter-table-builder.js +1 -1
- package/dist/esm/schema/alter-table-drop-constraint-builder.js +1 -1
- package/dist/esm/schema/alter-table-executor.js +1 -1
- package/dist/esm/schema/create-index-builder.js +1 -1
- package/dist/esm/schema/create-schema-builder.js +1 -1
- package/dist/esm/schema/create-table-builder.js +1 -1
- package/dist/esm/schema/create-type-builder.js +1 -1
- package/dist/esm/schema/create-view-builder.js +1 -1
- package/dist/esm/schema/drop-index-builder.js +1 -1
- package/dist/esm/schema/drop-schema-builder.js +1 -1
- package/dist/esm/schema/drop-table-builder.js +1 -1
- package/dist/esm/schema/drop-type-builder.js +1 -1
- package/dist/esm/schema/drop-view-builder.js +1 -1
- package/dist/esm/schema/refresh-materialized-view-builder.js +1 -1
- package/dist/esm/util/type-utils.d.ts +18 -0
- package/package.json +57 -57
- package/.renovaterc.json +0 -3
- package/CODE_OF_CONDUCT.md +0 -183
- package/FUNDING.md +0 -25
- package/deno.check.d.ts +0 -96
- package/deno.check.json +0 -21
package/dist/esm/kysely.js
CHANGED
|
@@ -17,6 +17,7 @@ import { CaseNode } from './operation-node/case-node.js';
|
|
|
17
17
|
import { parseExpression } from './parser/expression-parser.js';
|
|
18
18
|
import { WithSchemaPlugin } from './plugin/with-schema/with-schema-plugin.js';
|
|
19
19
|
import { provideControlledConnection, } from './util/provide-controlled-connection.js';
|
|
20
|
+
import { logOnce } from './util/log-once.js';
|
|
20
21
|
// @ts-ignore
|
|
21
22
|
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
|
22
23
|
/**
|
|
@@ -457,9 +458,14 @@ export class Kysely extends QueryCreator {
|
|
|
457
458
|
*
|
|
458
459
|
* See {@link https://github.com/kysely-org/kysely/blob/master/site/docs/recipes/0004-splitting-query-building-and-execution.md#execute-compiled-queries splitting build, compile and execute code recipe} for more information.
|
|
459
460
|
*/
|
|
460
|
-
executeQuery(query,
|
|
461
|
+
executeQuery(query,
|
|
462
|
+
// TODO: remove this in the future. deprecated in 0.28.x
|
|
463
|
+
queryId) {
|
|
464
|
+
if (queryId !== undefined) {
|
|
465
|
+
logOnce('Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.');
|
|
466
|
+
}
|
|
461
467
|
const compiledQuery = isCompilable(query) ? query.compile() : query;
|
|
462
|
-
return this.getExecutor().executeQuery(compiledQuery
|
|
468
|
+
return this.getExecutor().executeQuery(compiledQuery);
|
|
463
469
|
}
|
|
464
470
|
async [Symbol.asyncDispose]() {
|
|
465
471
|
await this.destroy();
|
|
@@ -878,13 +884,13 @@ class NotCommittedOrRolledBackAssertingExecutor {
|
|
|
878
884
|
provideConnection(consumer) {
|
|
879
885
|
return this.#executor.provideConnection(consumer);
|
|
880
886
|
}
|
|
881
|
-
executeQuery(compiledQuery
|
|
887
|
+
executeQuery(compiledQuery) {
|
|
882
888
|
assertNotCommittedOrRolledBack(this.#state);
|
|
883
|
-
return this.#executor.executeQuery(compiledQuery
|
|
889
|
+
return this.#executor.executeQuery(compiledQuery);
|
|
884
890
|
}
|
|
885
|
-
stream(compiledQuery, chunkSize
|
|
891
|
+
stream(compiledQuery, chunkSize) {
|
|
886
892
|
assertNotCommittedOrRolledBack(this.#state);
|
|
887
|
-
return this.#executor.stream(compiledQuery, chunkSize
|
|
893
|
+
return this.#executor.stream(compiledQuery, chunkSize);
|
|
888
894
|
}
|
|
889
895
|
withConnectionProvider(connectionProvider) {
|
|
890
896
|
return new NotCommittedOrRolledBackAssertingExecutor(this.#executor.withConnectionProvider(connectionProvider), this.#state);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="./migrator.d.ts" />
|
|
2
2
|
import { NoopPlugin } from '../plugin/noop-plugin.js';
|
|
3
3
|
import { WithSchemaPlugin } from '../plugin/with-schema/with-schema-plugin.js';
|
|
4
|
-
import { freeze, getLast } from '../util/object-utils.js';
|
|
4
|
+
import { freeze, getLast, isObject } from '../util/object-utils.js';
|
|
5
5
|
export const DEFAULT_MIGRATION_TABLE = 'kysely_migration';
|
|
6
6
|
export const DEFAULT_MIGRATION_LOCK_TABLE = 'kysely_migration_lock';
|
|
7
7
|
export const DEFAULT_ALLOW_UNORDERED_MIGRATIONS = false;
|
|
@@ -176,7 +176,8 @@ export class Migrator {
|
|
|
176
176
|
*/
|
|
177
177
|
async migrateTo(targetMigrationName) {
|
|
178
178
|
return this.#migrate(({ migrations, executedMigrations, pendingMigrations, }) => {
|
|
179
|
-
if (targetMigrationName
|
|
179
|
+
if (isObject(targetMigrationName) &&
|
|
180
|
+
targetMigrationName.__noMigrations__ === true) {
|
|
180
181
|
return { direction: 'Down', step: Infinity };
|
|
181
182
|
}
|
|
182
183
|
if (!migrations.find((m) => m.name === targetMigrationName)) {
|
|
@@ -2,4 +2,8 @@ import type { DeleteQueryBuilder } from '../query-builder/delete-query-builder.j
|
|
|
2
2
|
import type { DeleteResult } from '../query-builder/delete-result.js';
|
|
3
3
|
import type { ShallowRecord } from '../util/type-utils.js';
|
|
4
4
|
import type { ExtractTableAlias, From, FromTables, TableExpressionOrList } from './table-parser.js';
|
|
5
|
-
export type DeleteFrom<DB, TE extends TableExpressionOrList<DB, never>> =
|
|
5
|
+
export type DeleteFrom<DB, TE extends TableExpressionOrList<DB, never>> = [
|
|
6
|
+
TE
|
|
7
|
+
] extends [keyof DB] ? DeleteQueryBuilder<DB, ExtractTableAlias<DB, TE>, DeleteResult> : [
|
|
8
|
+
TE
|
|
9
|
+
] extends [`${infer T} as ${infer A}`] ? T extends keyof DB ? DeleteQueryBuilder<DB & ShallowRecord<A, DB[T]>, A, DeleteResult> : never : TE extends ReadonlyArray<infer T> ? DeleteQueryBuilder<From<DB, T>, FromTables<DB, never, T>, DeleteResult> : DeleteQueryBuilder<From<DB, TE>, FromTables<DB, never, TE>, DeleteResult>;
|
|
@@ -2,4 +2,6 @@ import type { MergeQueryBuilder } from '../query-builder/merge-query-builder.js'
|
|
|
2
2
|
import type { MergeResult } from '../query-builder/merge-result.js';
|
|
3
3
|
import type { ShallowRecord } from '../util/type-utils.js';
|
|
4
4
|
import type { ExtractTableAlias, SimpleTableReference } from './table-parser.js';
|
|
5
|
-
export type MergeInto<DB, TE extends SimpleTableReference<DB>> = TE extends
|
|
5
|
+
export type MergeInto<DB, TE extends SimpleTableReference<DB>> = [TE] extends [
|
|
6
|
+
keyof DB
|
|
7
|
+
] ? MergeQueryBuilder<DB, ExtractTableAlias<DB, TE>, MergeResult> : [TE] extends [`${infer T} as ${infer A}`] ? T extends keyof DB ? MergeQueryBuilder<DB & ShallowRecord<A, DB[T]>, A, MergeResult> : never : never;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { SelectQueryBuilder } from '../query-builder/select-query-builder.js';
|
|
2
2
|
import type { ShallowRecord } from '../util/type-utils.js';
|
|
3
3
|
import type { ExtractTableAlias, From, FromTables, TableExpressionOrList } from './table-parser.js';
|
|
4
|
-
export type SelectFrom<DB, TB extends keyof DB, TE extends TableExpressionOrList<DB, TB>> = TE extends keyof DB
|
|
4
|
+
export type SelectFrom<DB, TB extends keyof DB, TE extends TableExpressionOrList<DB, TB>> = [TE] extends [keyof DB] ? SelectQueryBuilder<DB, TB | ExtractTableAlias<DB, TE>, {}> : [
|
|
5
|
+
TE
|
|
6
|
+
] extends [`${infer T} as ${infer A}`] ? T extends keyof DB ? SelectQueryBuilder<DB & ShallowRecord<A, DB[T]>, TB | A, {}> : never : TE extends ReadonlyArray<infer T> ? SelectQueryBuilder<From<DB, T>, FromTables<DB, TB, T>, {}> : SelectQueryBuilder<From<DB, TE>, FromTables<DB, TB, TE>, {}>;
|
|
@@ -2,4 +2,8 @@ import type { UpdateQueryBuilder } from '../query-builder/update-query-builder.j
|
|
|
2
2
|
import type { UpdateResult } from '../query-builder/update-result.js';
|
|
3
3
|
import type { ShallowRecord } from '../util/type-utils.js';
|
|
4
4
|
import type { ExtractTableAlias, From, FromTables, TableExpressionOrList } from './table-parser.js';
|
|
5
|
-
export type UpdateTable<DB, TE extends TableExpressionOrList<DB, never>> =
|
|
5
|
+
export type UpdateTable<DB, TE extends TableExpressionOrList<DB, never>> = [
|
|
6
|
+
TE
|
|
7
|
+
] extends [keyof DB] ? UpdateQueryBuilder<DB, ExtractTableAlias<DB, TE>, ExtractTableAlias<DB, TE>, UpdateResult> : [
|
|
8
|
+
TE
|
|
9
|
+
] extends [`${infer T} as ${infer A}`] ? T extends keyof DB ? UpdateQueryBuilder<DB & ShallowRecord<A, DB[T]>, A, A, UpdateResult> : never : TE extends ReadonlyArray<infer T> ? UpdateQueryBuilder<From<DB, T>, FromTables<DB, never, T>, FromTables<DB, never, T>, UpdateResult> : UpdateQueryBuilder<From<DB, TE>, FromTables<DB, never, TE>, FromTables<DB, never, TE>, UpdateResult>;
|
|
@@ -449,7 +449,7 @@ export class DeleteQueryBuilder {
|
|
|
449
449
|
*/
|
|
450
450
|
async execute() {
|
|
451
451
|
const compiledQuery = this.compile();
|
|
452
|
-
const result = await this.#props.executor.executeQuery(compiledQuery
|
|
452
|
+
const result = await this.#props.executor.executeQuery(compiledQuery);
|
|
453
453
|
const { adapter } = this.#props.executor;
|
|
454
454
|
const query = compiledQuery.query;
|
|
455
455
|
if ((query.returning && adapter.supportsReturning) ||
|
|
@@ -486,7 +486,7 @@ export class DeleteQueryBuilder {
|
|
|
486
486
|
}
|
|
487
487
|
async *stream(chunkSize = 100) {
|
|
488
488
|
const compiledQuery = this.compile();
|
|
489
|
-
const stream = this.#props.executor.stream(compiledQuery, chunkSize
|
|
489
|
+
const stream = this.#props.executor.stream(compiledQuery, chunkSize);
|
|
490
490
|
for await (const item of stream) {
|
|
491
491
|
yield* item.rows;
|
|
492
492
|
}
|
|
@@ -3,10 +3,10 @@ import { Expression } from '../expression/expression.js';
|
|
|
3
3
|
import { ExtractTypeFromCoalesce1, ExtractTypeFromCoalesce3, ExtractTypeFromCoalesce2, ExtractTypeFromCoalesce4, ExtractTypeFromCoalesce5 } from '../parser/coalesce-parser.js';
|
|
4
4
|
import { ExtractTypeFromReferenceExpression, ReferenceExpression, StringReference, ExtractTypeFromStringReference } from '../parser/reference-parser.js';
|
|
5
5
|
import { KyselyTypeError } from '../util/type-error.js';
|
|
6
|
-
import { IsNever } from '../util/type-utils.js';
|
|
6
|
+
import { IsNever, ShallowDehydrateObject, ShallowDehydrateValue, Simplify } from '../util/type-utils.js';
|
|
7
7
|
import { AggregateFunctionBuilder } from './aggregate-function-builder.js';
|
|
8
8
|
import { SelectQueryBuilderExpression } from '../query-builder/select-query-builder-expression.js';
|
|
9
|
-
import { Selectable } from '../util/column-type.js';
|
|
9
|
+
import { Selectable, SelectType } from '../util/column-type.js';
|
|
10
10
|
/**
|
|
11
11
|
* Helpers for type safe SQL function calls.
|
|
12
12
|
*
|
|
@@ -514,7 +514,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
|
|
|
514
514
|
* $1 = any("person"."nicknames")
|
|
515
515
|
* ```
|
|
516
516
|
*/
|
|
517
|
-
any<RE extends StringReference<DB, TB>>(expr: RE): Exclude<
|
|
517
|
+
any<RE extends StringReference<DB, TB>>(expr: RE): Exclude<ExtractTypeFromReferenceExpression<DB, TB, RE>, null> extends ReadonlyArray<infer I> ? ExpressionWrapper<DB, TB, I> : KyselyTypeError<'any(expr) call failed: expr must be an array'>;
|
|
518
518
|
any<T>(subquery: SelectQueryBuilderExpression<Record<string, T>>): ExpressionWrapper<DB, TB, T>;
|
|
519
519
|
any<T>(expr: Expression<ReadonlyArray<T>>): ExpressionWrapper<DB, TB, T>;
|
|
520
520
|
/**
|
|
@@ -565,8 +565,8 @@ export interface FunctionModule<DB, TB extends keyof DB> {
|
|
|
565
565
|
* group by "person"."first_name"
|
|
566
566
|
* ```
|
|
567
567
|
*/
|
|
568
|
-
jsonAgg<T extends (TB & string) | Expression<unknown>>(table: T): AggregateFunctionBuilder<DB, TB, T extends TB ? Selectable<DB[T]
|
|
569
|
-
jsonAgg<RE extends StringReference<DB, TB>>(column: RE): AggregateFunctionBuilder<DB, TB, ExtractTypeFromStringReference<DB, TB, RE
|
|
568
|
+
jsonAgg<T extends (TB & string) | Expression<unknown>>(table: T): AggregateFunctionBuilder<DB, TB, T extends TB ? Simplify<ShallowDehydrateObject<Selectable<DB[T]>>>[] : T extends Expression<infer O> ? Simplify<ShallowDehydrateObject<O>>[] : never>;
|
|
569
|
+
jsonAgg<RE extends StringReference<DB, TB>>(column: RE): AggregateFunctionBuilder<DB, TB, ShallowDehydrateValue<SelectType<ExtractTypeFromStringReference<DB, TB, RE>>>[] | null>;
|
|
570
570
|
/**
|
|
571
571
|
* Creates a to_json function call.
|
|
572
572
|
*
|
|
@@ -587,6 +587,6 @@ export interface FunctionModule<DB, TB extends keyof DB> {
|
|
|
587
587
|
* inner join "pet" on "pet"."owner_id" = "person"."id"
|
|
588
588
|
* ```
|
|
589
589
|
*/
|
|
590
|
-
toJson<T extends (TB & string) | Expression<unknown>>(table: T): ExpressionWrapper<DB, TB, T extends TB ? Selectable<DB[T]
|
|
590
|
+
toJson<T extends (TB & string) | Expression<unknown>>(table: T): ExpressionWrapper<DB, TB, T extends TB ? Simplify<ShallowDehydrateObject<Selectable<DB[T]>>> : T extends Expression<infer O> ? Simplify<ShallowDehydrateObject<O>> : never>;
|
|
591
591
|
}
|
|
592
592
|
export declare function createFunctionModule<DB, TB extends keyof DB>(): FunctionModule<DB, TB>;
|
|
@@ -1103,7 +1103,7 @@ export class InsertQueryBuilder {
|
|
|
1103
1103
|
*/
|
|
1104
1104
|
async execute() {
|
|
1105
1105
|
const compiledQuery = this.compile();
|
|
1106
|
-
const result = await this.#props.executor.executeQuery(compiledQuery
|
|
1106
|
+
const result = await this.#props.executor.executeQuery(compiledQuery);
|
|
1107
1107
|
const { adapter } = this.#props.executor;
|
|
1108
1108
|
const query = compiledQuery.query;
|
|
1109
1109
|
if ((query.returning && adapter.supportsReturning) ||
|
|
@@ -1142,7 +1142,7 @@ export class InsertQueryBuilder {
|
|
|
1142
1142
|
}
|
|
1143
1143
|
async *stream(chunkSize = 100) {
|
|
1144
1144
|
const compiledQuery = this.compile();
|
|
1145
|
-
const stream = this.#props.executor.stream(compiledQuery, chunkSize
|
|
1145
|
+
const stream = this.#props.executor.stream(compiledQuery, chunkSize);
|
|
1146
1146
|
for await (const item of stream) {
|
|
1147
1147
|
yield* item.rows;
|
|
1148
1148
|
}
|
|
@@ -416,7 +416,7 @@ export class WheneableMergeQueryBuilder {
|
|
|
416
416
|
*/
|
|
417
417
|
async execute() {
|
|
418
418
|
const compiledQuery = this.compile();
|
|
419
|
-
const result = await this.#props.executor.executeQuery(compiledQuery
|
|
419
|
+
const result = await this.#props.executor.executeQuery(compiledQuery);
|
|
420
420
|
const { adapter } = this.#props.executor;
|
|
421
421
|
const query = compiledQuery.query;
|
|
422
422
|
if ((query.returning && adapter.supportsReturning) ||
|
|
@@ -314,7 +314,7 @@ class SelectQueryBuilderImpl {
|
|
|
314
314
|
}
|
|
315
315
|
async execute() {
|
|
316
316
|
const compiledQuery = this.compile();
|
|
317
|
-
const result = await this.#props.executor.executeQuery(compiledQuery
|
|
317
|
+
const result = await this.#props.executor.executeQuery(compiledQuery);
|
|
318
318
|
return result.rows;
|
|
319
319
|
}
|
|
320
320
|
async executeTakeFirst() {
|
|
@@ -333,7 +333,7 @@ class SelectQueryBuilderImpl {
|
|
|
333
333
|
}
|
|
334
334
|
async *stream(chunkSize = 100) {
|
|
335
335
|
const compiledQuery = this.compile();
|
|
336
|
-
const stream = this.#props.executor.stream(compiledQuery, chunkSize
|
|
336
|
+
const stream = this.#props.executor.stream(compiledQuery, chunkSize);
|
|
337
337
|
for await (const item of stream) {
|
|
338
338
|
yield* item.rows;
|
|
339
339
|
}
|
|
@@ -456,7 +456,7 @@ export class UpdateQueryBuilder {
|
|
|
456
456
|
*/
|
|
457
457
|
async execute() {
|
|
458
458
|
const compiledQuery = this.compile();
|
|
459
|
-
const result = await this.#props.executor.executeQuery(compiledQuery
|
|
459
|
+
const result = await this.#props.executor.executeQuery(compiledQuery);
|
|
460
460
|
const { adapter } = this.#props.executor;
|
|
461
461
|
const query = compiledQuery.query;
|
|
462
462
|
if ((query.returning && adapter.supportsReturning) ||
|
|
@@ -495,7 +495,7 @@ export class UpdateQueryBuilder {
|
|
|
495
495
|
}
|
|
496
496
|
async *stream(chunkSize = 100) {
|
|
497
497
|
const compiledQuery = this.compile();
|
|
498
|
-
const stream = this.#props.executor.stream(compiledQuery, chunkSize
|
|
498
|
+
const stream = this.#props.executor.stream(compiledQuery, chunkSize);
|
|
499
499
|
for await (const item of stream) {
|
|
500
500
|
yield* item.rows;
|
|
501
501
|
}
|
|
@@ -1318,7 +1318,7 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
1318
1318
|
if (isString(value)) {
|
|
1319
1319
|
this.appendStringLiteral(value);
|
|
1320
1320
|
}
|
|
1321
|
-
else if (isNumber(value) || isBoolean(value)) {
|
|
1321
|
+
else if (isNumber(value) || isBoolean(value) || isBigInt(value)) {
|
|
1322
1322
|
this.append(value.toString());
|
|
1323
1323
|
}
|
|
1324
1324
|
else if (isNull(value)) {
|
|
@@ -1327,9 +1327,6 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
1327
1327
|
else if (isDate(value)) {
|
|
1328
1328
|
this.appendImmediateValue(value.toISOString());
|
|
1329
1329
|
}
|
|
1330
|
-
else if (isBigInt(value)) {
|
|
1331
|
-
this.appendImmediateValue(value.toString());
|
|
1332
|
-
}
|
|
1333
1330
|
else {
|
|
1334
1331
|
throw new Error(`invalid immediate value ${value}`);
|
|
1335
1332
|
}
|
|
@@ -35,13 +35,13 @@ export declare abstract class QueryExecutorBase implements QueryExecutor {
|
|
|
35
35
|
* Executes a compiled query and runs the result through all plugins'
|
|
36
36
|
* `transformResult` method.
|
|
37
37
|
*/
|
|
38
|
-
executeQuery<R>(compiledQuery: CompiledQuery
|
|
38
|
+
executeQuery<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
|
|
39
39
|
/**
|
|
40
40
|
* Executes a compiled query and runs the result through all plugins'
|
|
41
41
|
* `transformResult` method. Results are streamead instead of loaded
|
|
42
42
|
* at once.
|
|
43
43
|
*/
|
|
44
|
-
stream<R>(compiledQuery: CompiledQuery, chunkSize: number
|
|
44
|
+
stream<R>(compiledQuery: CompiledQuery, chunkSize: number): AsyncIterableIterator<QueryResult<R>>;
|
|
45
45
|
/**
|
|
46
46
|
* Returns a copy of this executor with a new connection provider.
|
|
47
47
|
*/
|
|
@@ -30,20 +30,20 @@ export class QueryExecutorBase {
|
|
|
30
30
|
}
|
|
31
31
|
return node;
|
|
32
32
|
}
|
|
33
|
-
async executeQuery(compiledQuery
|
|
33
|
+
async executeQuery(compiledQuery) {
|
|
34
34
|
return await this.provideConnection(async (connection) => {
|
|
35
35
|
const result = await connection.executeQuery(compiledQuery);
|
|
36
36
|
if ('numUpdatedOrDeletedRows' in result) {
|
|
37
37
|
logOnce('kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.');
|
|
38
38
|
}
|
|
39
|
-
return await this.#transformResult(result, queryId);
|
|
39
|
+
return await this.#transformResult(result, compiledQuery.queryId);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
async *stream(compiledQuery, chunkSize
|
|
42
|
+
async *stream(compiledQuery, chunkSize) {
|
|
43
43
|
const { connection, release } = await provideControlledConnection(this);
|
|
44
44
|
try {
|
|
45
45
|
for await (const result of connection.streamQuery(compiledQuery, chunkSize)) {
|
|
46
|
-
yield await this.#transformResult(result, queryId);
|
|
46
|
+
yield await this.#transformResult(result, compiledQuery.queryId);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
finally {
|
|
@@ -36,7 +36,7 @@ export interface QueryExecutor extends ConnectionProvider {
|
|
|
36
36
|
* Executes a compiled query and runs the result through all plugins'
|
|
37
37
|
* `transformResult` method.
|
|
38
38
|
*/
|
|
39
|
-
executeQuery<R>(compiledQuery: CompiledQuery<R
|
|
39
|
+
executeQuery<R>(compiledQuery: CompiledQuery<R>): Promise<QueryResult<R>>;
|
|
40
40
|
/**
|
|
41
41
|
* Executes a compiled query and runs the result through all plugins'
|
|
42
42
|
* `transformResult` method. Results are streamead instead of loaded
|
|
@@ -47,7 +47,7 @@ export interface QueryExecutor extends ConnectionProvider {
|
|
|
47
47
|
* How many rows should be pulled from the database at once. Supported
|
|
48
48
|
* only by the postgres driver.
|
|
49
49
|
*/
|
|
50
|
-
chunkSize: number
|
|
50
|
+
chunkSize: number): AsyncIterableIterator<QueryResult<R>>;
|
|
51
51
|
/**
|
|
52
52
|
* Returns a copy of this executor with a new connection provider.
|
|
53
53
|
*/
|
|
@@ -40,7 +40,7 @@ class RawBuilderImpl {
|
|
|
40
40
|
}
|
|
41
41
|
async execute(executorProvider) {
|
|
42
42
|
const executor = this.#getExecutor(executorProvider);
|
|
43
|
-
return executor.executeQuery(this.#compile(executor)
|
|
43
|
+
return executor.executeQuery(this.#compile(executor));
|
|
44
44
|
}
|
|
45
45
|
#getExecutor(executorProvider) {
|
|
46
46
|
const executor = executorProvider !== undefined
|
|
@@ -59,6 +59,6 @@ export class AlterTableAddForeignKeyConstraintBuilder {
|
|
|
59
59
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
60
60
|
}
|
|
61
61
|
async execute() {
|
|
62
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
62
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -157,6 +157,6 @@ export class AlterTableAddIndexBuilder {
|
|
|
157
157
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
158
158
|
}
|
|
159
159
|
async execute() {
|
|
160
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
160
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -258,6 +258,6 @@ export class AlterTableColumnAlteringBuilder {
|
|
|
258
258
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
259
259
|
}
|
|
260
260
|
async execute() {
|
|
261
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
261
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
262
262
|
}
|
|
263
263
|
}
|
|
@@ -51,6 +51,6 @@ export class AlterTableDropConstraintBuilder {
|
|
|
51
51
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
52
52
|
}
|
|
53
53
|
async execute() {
|
|
54
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
54
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -12,6 +12,6 @@ export class AlterTableExecutor {
|
|
|
12
12
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
13
13
|
}
|
|
14
14
|
async execute() {
|
|
15
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
15
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -194,6 +194,6 @@ export class CreateIndexBuilder {
|
|
|
194
194
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
195
195
|
}
|
|
196
196
|
async execute() {
|
|
197
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
197
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
198
198
|
}
|
|
199
199
|
}
|
|
@@ -26,6 +26,6 @@ export class CreateSchemaBuilder {
|
|
|
26
26
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
27
27
|
}
|
|
28
28
|
async execute() {
|
|
29
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
29
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -403,6 +403,6 @@ export class CreateTableBuilder {
|
|
|
403
403
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
404
404
|
}
|
|
405
405
|
async execute() {
|
|
406
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
406
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
407
407
|
}
|
|
408
408
|
}
|
|
@@ -35,6 +35,6 @@ export class CreateTypeBuilder {
|
|
|
35
35
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
36
36
|
}
|
|
37
37
|
async execute() {
|
|
38
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
38
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -90,6 +90,6 @@ export class CreateViewBuilder {
|
|
|
90
90
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
91
91
|
}
|
|
92
92
|
async execute() {
|
|
93
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
93
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -49,6 +49,6 @@ export class DropIndexBuilder {
|
|
|
49
49
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
50
50
|
}
|
|
51
51
|
async execute() {
|
|
52
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
52
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -36,6 +36,6 @@ export class DropSchemaBuilder {
|
|
|
36
36
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
37
37
|
}
|
|
38
38
|
async execute() {
|
|
39
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
39
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -36,6 +36,6 @@ export class DropTableBuilder {
|
|
|
36
36
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
37
37
|
}
|
|
38
38
|
async execute() {
|
|
39
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
39
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -28,6 +28,6 @@ export class DropTypeBuilder {
|
|
|
28
28
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
29
29
|
}
|
|
30
30
|
async execute() {
|
|
31
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
31
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -44,6 +44,6 @@ export class DropViewBuilder {
|
|
|
44
44
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
45
45
|
}
|
|
46
46
|
async execute() {
|
|
47
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
47
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -67,6 +67,6 @@ export class RefreshMaterializedViewBuilder {
|
|
|
67
67
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
68
68
|
}
|
|
69
69
|
async execute() {
|
|
70
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
70
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -169,3 +169,21 @@ export type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never;
|
|
|
169
169
|
export type ShallowRecord<K extends keyof any, T> = DrainOuterGeneric<{
|
|
170
170
|
[P in K]: T;
|
|
171
171
|
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Dehydrates any root properties of an object that are not valid JSON types.
|
|
174
|
+
*
|
|
175
|
+
* For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`.
|
|
176
|
+
*/
|
|
177
|
+
export type ShallowDehydrateObject<O> = {
|
|
178
|
+
[K in keyof O]: ShallowDehydrateValue<O[K]>;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Dehydrates a value when it is not a valid JSON type.
|
|
182
|
+
*
|
|
183
|
+
* For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`,
|
|
184
|
+
* and anything in {@link NumbersWhenDataTypeNotAvailable} and convert it to `number`.
|
|
185
|
+
*/
|
|
186
|
+
export type ShallowDehydrateValue<T> = T extends null | undefined ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
|
|
187
|
+
export type StringsWhenDataTypeNotAvailable = Date | Buffer | ArrayBuffer;
|
|
188
|
+
export type NumbersWhenDataTypeNotAvailable = bigint | NumericString;
|
|
189
|
+
export type NumericString = `${number}`;
|