kysely 0.11.0 → 0.11.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/mysql/mysql-query-compiler.d.ts +0 -2
- package/dist/cjs/dialect/mysql/mysql-query-compiler.js +0 -6
- package/dist/cjs/dialect/postgres/postgres-query-compiler.d.ts +3 -0
- package/dist/cjs/dialect/postgres/postgres-query-compiler.js +9 -1
- package/dist/cjs/dialect/sqlite/sqlite-adapter.js +6 -2
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +7 -7
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +19 -6
- package/dist/cjs/dialect/sqlite/sqlite-query-compiler.d.ts +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-query-compiler.js +6 -6
- package/dist/cjs/driver/runtime-driver.js +1 -1
- package/dist/cjs/index.d.ts +38 -30
- package/dist/cjs/index.js +37 -29
- package/dist/cjs/kysely.d.ts +22 -6
- package/dist/cjs/operation-node/alias-node.d.ts +1 -1
- package/dist/cjs/operation-node/operation-node-utils.d.ts +1 -1
- package/dist/cjs/parser/filter-parser.d.ts +1 -0
- package/dist/cjs/parser/filter-parser.js +49 -52
- package/dist/cjs/parser/insert-values-parser.d.ts +6 -5
- package/dist/cjs/parser/insert-values-parser.js +11 -5
- package/dist/cjs/query-builder/join-builder.d.ts +3 -0
- package/dist/cjs/query-builder/query-builder.d.ts +22 -1
- package/dist/cjs/query-builder/query-builder.js +1 -1
- package/dist/cjs/util/dynamic-import.js +1 -1
- package/dist/cjs/util/log.d.ts +10 -8
- package/dist/cjs/util/log.js +29 -9
- package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +0 -2
- package/dist/esm/dialect/mysql/mysql-query-compiler.js +0 -6
- package/dist/esm/dialect/postgres/postgres-query-compiler.d.ts +3 -0
- package/dist/esm/dialect/postgres/postgres-query-compiler.js +9 -1
- package/dist/esm/dialect/sqlite/sqlite-adapter.js +6 -2
- package/dist/esm/dialect/sqlite/sqlite-driver.js +7 -7
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +19 -6
- package/dist/esm/dialect/sqlite/sqlite-query-compiler.d.ts +2 -2
- package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +6 -6
- package/dist/esm/driver/runtime-driver.js +1 -1
- package/dist/esm/index.d.ts +38 -30
- package/dist/esm/index.js +37 -29
- package/dist/esm/kysely.d.ts +22 -6
- package/dist/esm/operation-node/alias-node.d.ts +1 -1
- package/dist/esm/operation-node/operation-node-utils.d.ts +1 -1
- package/dist/esm/parser/filter-parser.d.ts +1 -0
- package/dist/esm/parser/filter-parser.js +48 -52
- package/dist/esm/parser/insert-values-parser.d.ts +6 -5
- package/dist/esm/parser/insert-values-parser.js +12 -6
- package/dist/esm/query-builder/join-builder.d.ts +3 -0
- package/dist/esm/query-builder/query-builder.d.ts +22 -1
- package/dist/esm/query-builder/query-builder.js +1 -1
- package/dist/esm/util/dynamic-import.js +1 -1
- package/dist/esm/util/log.d.ts +10 -8
- package/dist/esm/util/log.js +30 -10
- package/package.json +1 -1
|
@@ -9,11 +9,11 @@ const value_list_node_js_1 = require("../operation-node/value-list-node.js");
|
|
|
9
9
|
const value_node_js_1 = require("../operation-node/value-node.js");
|
|
10
10
|
const generated_placeholder_js_1 = require("../util/generated-placeholder.js");
|
|
11
11
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
12
|
-
function parseInsertObjectOrList(args) {
|
|
13
|
-
return parseInsertColumnsAndValues(Array.isArray(args) ? args : [args]);
|
|
12
|
+
function parseInsertObjectOrList(ctx, args) {
|
|
13
|
+
return parseInsertColumnsAndValues(ctx, Array.isArray(args) ? args : [args]);
|
|
14
14
|
}
|
|
15
15
|
exports.parseInsertObjectOrList = parseInsertObjectOrList;
|
|
16
|
-
function parseInsertColumnsAndValues(rows) {
|
|
16
|
+
function parseInsertColumnsAndValues(ctx, rows) {
|
|
17
17
|
const columns = [];
|
|
18
18
|
const values = [];
|
|
19
19
|
for (const row of rows) {
|
|
@@ -36,12 +36,12 @@ function parseInsertColumnsAndValues(rows) {
|
|
|
36
36
|
values.push(primitive_value_list_node_js_1.PrimitiveValueListNode.create(rowValues));
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
values.push(value_list_node_js_1.ValueListNode.create(rowValues.map(parseInsertValueExpression)));
|
|
39
|
+
values.push(value_list_node_js_1.ValueListNode.create(rowValues.map((it) => parseInsertValueExpression(ctx, it))));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
return [columns.map(column_node_js_1.ColumnNode.create), values];
|
|
43
43
|
}
|
|
44
|
-
function parseInsertValueExpression(value) {
|
|
44
|
+
function parseInsertValueExpression(ctx, value) {
|
|
45
45
|
if ((0, object_utils_js_1.isPrimitive)(value)) {
|
|
46
46
|
return value_node_js_1.ValueNode.create(value);
|
|
47
47
|
}
|
|
@@ -51,6 +51,12 @@ function parseInsertValueExpression(value) {
|
|
|
51
51
|
return node;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
else if ((0, object_utils_js_1.isFunction)(value)) {
|
|
55
|
+
const node = value(ctx.createExpressionBuilder()).toOperationNode();
|
|
56
|
+
if (!query_node_js_1.QueryNode.isMutating(node)) {
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
54
60
|
throw new Error(`unsupported value for insert object ${JSON.stringify(value)}`);
|
|
55
61
|
}
|
|
56
62
|
exports.parseInsertValueExpression = parseInsertValueExpression;
|
|
@@ -4,6 +4,7 @@ import { ExistsExpression, FilterOperator } from '../parser/filter-parser.js';
|
|
|
4
4
|
import { ParseContext } from '../parser/parse-context.js';
|
|
5
5
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
6
6
|
import { ValueExpressionOrList } from '../parser/value-parser.js';
|
|
7
|
+
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
7
8
|
export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNodeSource {
|
|
8
9
|
#private;
|
|
9
10
|
constructor(props: JoinBuilderProps);
|
|
@@ -15,6 +16,7 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
|
|
|
15
16
|
*/
|
|
16
17
|
on<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
|
|
17
18
|
on(grouper: (qb: JoinBuilder<DB, TB>) => JoinBuilder<DB, TB>): JoinBuilder<DB, TB>;
|
|
19
|
+
on(raw: AnyRawBuilder): JoinBuilder<DB, TB>;
|
|
18
20
|
/**
|
|
19
21
|
* Just like {@link QueryBuilder.orWhere} but adds an item to the join's
|
|
20
22
|
* `on` clause instead.
|
|
@@ -23,6 +25,7 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
|
|
|
23
25
|
*/
|
|
24
26
|
orOn<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
|
|
25
27
|
orOn(grouper: (qb: JoinBuilder<DB, TB>) => JoinBuilder<DB, TB>): JoinBuilder<DB, TB>;
|
|
28
|
+
orOn(raw: AnyRawBuilder): JoinBuilder<DB, TB>;
|
|
26
29
|
/**
|
|
27
30
|
* Just like {@link QueryBuilder.whereRef} but adds an item to the join's
|
|
28
31
|
* `on` clause instead.
|
|
@@ -10,7 +10,7 @@ import { QueryBuilderWithReturning } from '../parser/returning-parser.js';
|
|
|
10
10
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
11
11
|
import { ValueExpressionOrList } from '../parser/value-parser.js';
|
|
12
12
|
import { QueryNode } from '../operation-node/query-node.js';
|
|
13
|
-
import { AnyColumn, SingleResultType } from '../util/type-utils.js';
|
|
13
|
+
import { AnyColumn, AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
|
|
14
14
|
import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-by-parser.js';
|
|
15
15
|
import { MutationObject } from '../parser/update-set-parser.js';
|
|
16
16
|
import { Compilable } from '../util/compilable.js';
|
|
@@ -220,6 +220,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
220
220
|
*/
|
|
221
221
|
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
|
|
222
222
|
where(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
|
|
223
|
+
where(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
|
|
223
224
|
/**
|
|
224
225
|
* Adds a `where` clause where both sides of the operator are references
|
|
225
226
|
* to columns.
|
|
@@ -339,6 +340,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
339
340
|
*/
|
|
340
341
|
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
|
|
341
342
|
orWhere(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
|
|
343
|
+
orWhere(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
|
|
342
344
|
/**
|
|
343
345
|
* Adds an `or where` clause to the query. Otherwise works just like
|
|
344
346
|
* {@link QueryBuilder.whereRef | whereRef}.
|
|
@@ -424,6 +426,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
424
426
|
*/
|
|
425
427
|
having<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
|
|
426
428
|
having(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
|
|
429
|
+
having(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
|
|
427
430
|
/**
|
|
428
431
|
* Just like {@link QueryBuilder.whereRef | whereRef} but adds a `having` statement
|
|
429
432
|
* instead of a `where` statement.
|
|
@@ -435,6 +438,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
435
438
|
*/
|
|
436
439
|
orHaving<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
|
|
437
440
|
orHaving(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
|
|
441
|
+
orHaving(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
|
|
438
442
|
/**
|
|
439
443
|
* Just like {@link QueryBuilder.orWhereRef | orWhereRef} but adds a `having` statement
|
|
440
444
|
* instead of a `where` statement.
|
|
@@ -998,6 +1002,23 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
998
1002
|
* insert into "person" ("first_name", "last_name", "age")
|
|
999
1003
|
* values ($1, $2 || $3, (select avg(age) from "person"))
|
|
1000
1004
|
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* You can also use the callback version of subqueries or raw expressions:
|
|
1008
|
+
*
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* db.with('jennifer', (db) => db
|
|
1011
|
+
* .selectFrom('person')
|
|
1012
|
+
* .where('first_name', '=', 'Jennifer')
|
|
1013
|
+
* .select(['id', 'first_name', 'gender'])
|
|
1014
|
+
* .limit(1)
|
|
1015
|
+
* ).insertInto('pet').values({
|
|
1016
|
+
* id: db.generated,
|
|
1017
|
+
* owner_id: (eb) => eb.subQuery('jennifer').select('id'),
|
|
1018
|
+
* name: (eb) => eb.subQuery('jennifer').select('first_name'),
|
|
1019
|
+
* species: 'cat',
|
|
1020
|
+
* })
|
|
1021
|
+
* ```
|
|
1001
1022
|
*/
|
|
1002
1023
|
values(row: InsertObject<DB, TB>): QueryBuilder<DB, TB, O>;
|
|
1003
1024
|
values(row: ReadonlyArray<InsertObject<DB, TB>>): QueryBuilder<DB, TB, O>;
|
|
@@ -440,7 +440,7 @@ class QueryBuilder {
|
|
|
440
440
|
}
|
|
441
441
|
values(args) {
|
|
442
442
|
assertCanHaveInsertValues(this.#props.queryNode);
|
|
443
|
-
const [columns, values] = (0, insert_values_parser_js_1.parseInsertObjectOrList)(args);
|
|
443
|
+
const [columns, values] = (0, insert_values_parser_js_1.parseInsertObjectOrList)(this.#props.parseContext, args);
|
|
444
444
|
return new QueryBuilder({
|
|
445
445
|
...this.#props,
|
|
446
446
|
queryNode: insert_query_node_js_1.InsertQueryNode.cloneWith(this.#props.queryNode, {
|
|
@@ -4,7 +4,7 @@ exports.importNamedFunction = exports.importFunction = void 0;
|
|
|
4
4
|
const object_utils_js_1 = require("./object-utils.js");
|
|
5
5
|
async function importFunction(modulePath) {
|
|
6
6
|
const module = await Promise.resolve().then(() => require(modulePath));
|
|
7
|
-
const errorMessage = `module "${modulePath}" doesn export a function`;
|
|
7
|
+
const errorMessage = `module "${modulePath}" doesn't export a function`;
|
|
8
8
|
if ((0, object_utils_js_1.isFunction)(module)) {
|
|
9
9
|
return module;
|
|
10
10
|
}
|
package/dist/cjs/util/log.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
import { CompiledQuery } from '../index.js';
|
|
1
2
|
import { ArrayItemType } from './type-utils.js';
|
|
2
3
|
export declare const LOG_LEVELS: readonly ["query", "error"];
|
|
3
4
|
export declare type LogLevel = ArrayItemType<typeof LOG_LEVELS>;
|
|
4
|
-
export declare class Log {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(levels: ReadonlyArray<LogLevel>);
|
|
7
|
-
query(getEvent: () => QueryLogEvent): void;
|
|
8
|
-
error(getEvent: () => ErrorLogEvent): void;
|
|
9
|
-
}
|
|
10
|
-
export declare type LogEvent = QueryLogEvent | ErrorLogEvent;
|
|
11
5
|
export interface QueryLogEvent {
|
|
12
6
|
readonly level: 'query';
|
|
13
|
-
readonly
|
|
7
|
+
readonly query: CompiledQuery;
|
|
14
8
|
readonly queryDurationMillis: number;
|
|
15
9
|
}
|
|
16
10
|
export interface ErrorLogEvent {
|
|
17
11
|
readonly level: 'error';
|
|
18
12
|
readonly error: unknown;
|
|
19
13
|
}
|
|
14
|
+
export declare type LogEvent = QueryLogEvent | ErrorLogEvent;
|
|
15
|
+
export declare type LogConfig = ReadonlyArray<LogLevel> | ((event: LogEvent) => void);
|
|
16
|
+
export declare class Log {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(config: LogConfig);
|
|
19
|
+
query(getEvent: () => QueryLogEvent): void;
|
|
20
|
+
error(getEvent: () => ErrorLogEvent): void;
|
|
21
|
+
}
|
package/dist/cjs/util/log.js
CHANGED
|
@@ -2,27 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Log = exports.LOG_LEVELS = void 0;
|
|
4
4
|
const object_utils_js_1 = require("./object-utils.js");
|
|
5
|
-
exports.LOG_LEVELS = ['query', 'error'];
|
|
5
|
+
exports.LOG_LEVELS = (0, object_utils_js_1.freeze)(['query', 'error']);
|
|
6
6
|
class Log {
|
|
7
7
|
#levels;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
#logger;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
if ((0, object_utils_js_1.isFunction)(config)) {
|
|
11
|
+
this.#logger = config;
|
|
12
|
+
this.#levels = (0, object_utils_js_1.freeze)({
|
|
13
|
+
query: true,
|
|
14
|
+
error: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.#levels = (0, object_utils_js_1.freeze)({
|
|
19
|
+
query: config.includes('query'),
|
|
20
|
+
error: config.includes('error'),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
13
23
|
}
|
|
14
24
|
query(getEvent) {
|
|
15
25
|
if (this.#levels.query) {
|
|
16
|
-
this.#
|
|
26
|
+
if (this.#logger) {
|
|
27
|
+
this.#logger(getEvent());
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.#defaultQuery(getEvent());
|
|
31
|
+
}
|
|
17
32
|
}
|
|
18
33
|
}
|
|
19
34
|
error(getEvent) {
|
|
20
35
|
if (this.#levels.error) {
|
|
21
|
-
this.#
|
|
36
|
+
if (this.#logger) {
|
|
37
|
+
this.#logger(getEvent());
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.#defaultError(getEvent());
|
|
41
|
+
}
|
|
22
42
|
}
|
|
23
43
|
}
|
|
24
44
|
#defaultQuery(event) {
|
|
25
|
-
console.log(`kysely:query: ${event.sql}`);
|
|
45
|
+
console.log(`kysely:query: ${event.query.sql}`);
|
|
26
46
|
console.log(`kysely:query: duration: ${event.queryDurationMillis.toFixed(1)}ms`);
|
|
27
47
|
}
|
|
28
48
|
#defaultError(event) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
|
|
2
2
|
export declare class MysqlQueryCompiler extends DefaultQueryCompiler {
|
|
3
|
-
protected visitReturning(): void;
|
|
4
|
-
protected getSql(): string;
|
|
5
3
|
protected getCurrentParameterPlaceholder(): string;
|
|
6
4
|
protected getLeftIdentifierWrapper(): string;
|
|
7
5
|
protected getRightIdentifierWrapper(): string;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
|
|
2
2
|
export class MysqlQueryCompiler extends DefaultQueryCompiler {
|
|
3
|
-
visitReturning() {
|
|
4
|
-
// Do nothing.
|
|
5
|
-
}
|
|
6
|
-
getSql() {
|
|
7
|
-
return super.getSql().trimEnd();
|
|
8
|
-
}
|
|
9
3
|
getCurrentParameterPlaceholder() {
|
|
10
4
|
return '?';
|
|
11
5
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
|
|
2
2
|
export declare class PostgresQueryCompiler extends DefaultQueryCompiler {
|
|
3
|
+
protected getCurrentParameterPlaceholder(): string;
|
|
4
|
+
protected getLeftIdentifierWrapper(): string;
|
|
5
|
+
protected getRightIdentifierWrapper(): string;
|
|
3
6
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
|
|
2
|
-
// The default query compiler is for PostgreSQL.
|
|
3
2
|
export class PostgresQueryCompiler extends DefaultQueryCompiler {
|
|
3
|
+
getCurrentParameterPlaceholder() {
|
|
4
|
+
return '$' + this.numParameters;
|
|
5
|
+
}
|
|
6
|
+
getLeftIdentifierWrapper() {
|
|
7
|
+
return '"';
|
|
8
|
+
}
|
|
9
|
+
getRightIdentifierWrapper() {
|
|
10
|
+
return '"';
|
|
11
|
+
}
|
|
4
12
|
}
|
|
@@ -6,9 +6,13 @@ export class SqliteAdapter {
|
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
async acquireMigrationLock() {
|
|
9
|
-
//
|
|
9
|
+
// SQLite only has one connection that's reserved by the migration system
|
|
10
|
+
// for the whole time between acquireMigrationLock and releaseMigrationLock.
|
|
11
|
+
// We don't need to do anything here.
|
|
10
12
|
}
|
|
11
13
|
async releaseMigrationLock() {
|
|
12
|
-
//
|
|
14
|
+
// SQLite only has one connection that's reserved by the migration system
|
|
15
|
+
// for the whole time between acquireMigrationLock and releaseMigrationLock.
|
|
16
|
+
// We don't need to do anything here.
|
|
13
17
|
}
|
|
14
18
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
2
2
|
import { importFunction } from '../../util/dynamic-import.js';
|
|
3
|
+
import { isBoolean, isFunction, isNumber } from '../../util/object-utils.js';
|
|
3
4
|
export class SqliteDriver {
|
|
4
5
|
#config;
|
|
5
6
|
#connectionMutex = new ConnectionMutex();
|
|
@@ -16,16 +17,16 @@ export class SqliteDriver {
|
|
|
16
17
|
// into javascript. You can check the built javascript code.
|
|
17
18
|
const DatabaseConstructor = await importBetterSqlite3Database();
|
|
18
19
|
const options = {};
|
|
19
|
-
if (
|
|
20
|
+
if (isBoolean(this.#config.readonly)) {
|
|
20
21
|
options.readonly = this.#config.readonly;
|
|
21
22
|
}
|
|
22
|
-
if (
|
|
23
|
+
if (isBoolean(this.#config.fileMustExist)) {
|
|
23
24
|
options.fileMustExist = this.#config.fileMustExist;
|
|
24
25
|
}
|
|
25
|
-
if (
|
|
26
|
+
if (isNumber(this.#config.timeout)) {
|
|
26
27
|
options.timeout = this.#config.timeout;
|
|
27
28
|
}
|
|
28
|
-
if (
|
|
29
|
+
if (isFunction(this.#config.verbose)) {
|
|
29
30
|
options.verbose = this.#config.verbose;
|
|
30
31
|
}
|
|
31
32
|
this.#db = new DatabaseConstructor(this.#config.databasePath, options);
|
|
@@ -35,8 +36,8 @@ export class SqliteDriver {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
async acquireConnection() {
|
|
38
|
-
//
|
|
39
|
-
//
|
|
39
|
+
// SQLite only has one single connection. We use a mutex here to wait
|
|
40
|
+
// until the single connection has been released.
|
|
40
41
|
await this.#connectionMutex.lock();
|
|
41
42
|
return this.#connection;
|
|
42
43
|
}
|
|
@@ -61,7 +62,6 @@ async function importBetterSqlite3Database() {
|
|
|
61
62
|
return await importFunction('better-sqlite3');
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
64
|
-
console.error(error);
|
|
65
65
|
throw new Error('SQLite client not installed. Please run `npm install better-sqlite3`');
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -9,18 +9,31 @@ export class SqliteIntrospector {
|
|
|
9
9
|
.selectFrom('sqlite_schema')
|
|
10
10
|
.where('type', '=', 'table')
|
|
11
11
|
.where('name', 'not like', 'sqlite_%')
|
|
12
|
-
.select('name')
|
|
12
|
+
.select('name')
|
|
13
|
+
.castTo();
|
|
13
14
|
if (!options.withInternalKyselyTables) {
|
|
14
15
|
query = query
|
|
15
16
|
.where('name', '!=', MIGRATION_TABLE)
|
|
16
17
|
.where('name', '!=', MIGRATION_LOCK_TABLE);
|
|
17
18
|
}
|
|
18
|
-
const
|
|
19
|
+
const tables = await query.execute();
|
|
19
20
|
return {
|
|
20
|
-
tables:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
tables: await Promise.all(tables.map(({ name }) => this.#getTableMetadata(name))),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async #getTableMetadata(table) {
|
|
25
|
+
const db = this.#db;
|
|
26
|
+
const columns = await db
|
|
27
|
+
.selectFrom(db.raw(`PRAGMA_TABLE_INFO(?)`, [table]).as('table_info'))
|
|
28
|
+
.select(['name', 'type', 'notnull'])
|
|
29
|
+
.castTo()
|
|
30
|
+
.execute();
|
|
31
|
+
return {
|
|
32
|
+
name: table,
|
|
33
|
+
columns: columns.map((col) => ({
|
|
34
|
+
name: col.name,
|
|
35
|
+
dataType: col.type,
|
|
36
|
+
isNullable: !col.notnull,
|
|
24
37
|
})),
|
|
25
38
|
};
|
|
26
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
|
|
2
2
|
export declare class SqliteQueryCompiler extends DefaultQueryCompiler {
|
|
3
|
-
protected visitReturning(): void;
|
|
4
|
-
protected getSql(): string;
|
|
5
3
|
protected getCurrentParameterPlaceholder(): string;
|
|
4
|
+
protected getLeftIdentifierWrapper(): string;
|
|
5
|
+
protected getRightIdentifierWrapper(): string;
|
|
6
6
|
protected getAutoIncrement(): string;
|
|
7
7
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
|
|
2
2
|
export class SqliteQueryCompiler extends DefaultQueryCompiler {
|
|
3
|
-
visitReturning() {
|
|
4
|
-
// Do nothing.
|
|
5
|
-
}
|
|
6
|
-
getSql() {
|
|
7
|
-
return super.getSql().trimEnd();
|
|
8
|
-
}
|
|
9
3
|
getCurrentParameterPlaceholder() {
|
|
10
4
|
return '?';
|
|
11
5
|
}
|
|
6
|
+
getLeftIdentifierWrapper() {
|
|
7
|
+
return '"';
|
|
8
|
+
}
|
|
9
|
+
getRightIdentifierWrapper() {
|
|
10
|
+
return '"';
|
|
11
|
+
}
|
|
12
12
|
getAutoIncrement() {
|
|
13
13
|
return 'autoincrement';
|
|
14
14
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -51,35 +51,8 @@ export * from './migration/migration.js';
|
|
|
51
51
|
export * from './dialect/dialect.js';
|
|
52
52
|
export * from './dialect/dialect-adapter.js';
|
|
53
53
|
export * from './dialect/dialect-adapter-base.js';
|
|
54
|
-
export * from './operation-node/operation-node-transformer.js';
|
|
55
|
-
export * from './operation-node/operation-node-visitor.js';
|
|
56
54
|
export * from './plugin/kysely-plugin.js';
|
|
57
55
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
58
|
-
export * from './operation-node/operation-node-transformer.js';
|
|
59
|
-
export * from './operation-node/operation-node-visitor.js';
|
|
60
|
-
export * from './operation-node/operator-node.js';
|
|
61
|
-
export * from './operation-node/or-node.js';
|
|
62
|
-
export * from './operation-node/order-by-item-node.js';
|
|
63
|
-
export * from './operation-node/order-by-node.js';
|
|
64
|
-
export * from './operation-node/parens-node.js';
|
|
65
|
-
export * from './operation-node/primary-constraint-node.js';
|
|
66
|
-
export * from './operation-node/primitive-value-list-node.js';
|
|
67
|
-
export * from './operation-node/query-node.js';
|
|
68
|
-
export * from './operation-node/raw-node.js';
|
|
69
|
-
export * from './operation-node/reference-node.js';
|
|
70
|
-
export * from './operation-node/references-node.js';
|
|
71
|
-
export * from './operation-node/rename-column-node.js';
|
|
72
|
-
export * from './operation-node/returning-node.js';
|
|
73
|
-
export * from './operation-node/select-all-node.js';
|
|
74
|
-
export * from './operation-node/select-query-node.js';
|
|
75
|
-
export * from './operation-node/selection-node.js';
|
|
76
|
-
export * from './operation-node/table-node.js';
|
|
77
|
-
export * from './operation-node/unique-constraint-node.js';
|
|
78
|
-
export * from './operation-node/update-query-node.js';
|
|
79
|
-
export * from './operation-node/value-list-node.js';
|
|
80
|
-
export * from './operation-node/value-node.js';
|
|
81
|
-
export * from './operation-node/where-node.js';
|
|
82
|
-
export * from './operation-node/with-node.js';
|
|
83
56
|
export * from './operation-node/add-column-node.js';
|
|
84
57
|
export * from './operation-node/add-constraint-node.js';
|
|
85
58
|
export * from './operation-node/alias-node.js';
|
|
@@ -95,16 +68,20 @@ export * from './operation-node/constraint-node.js';
|
|
|
95
68
|
export * from './operation-node/create-index-node.js';
|
|
96
69
|
export * from './operation-node/create-schema-node.js';
|
|
97
70
|
export * from './operation-node/create-table-node.js';
|
|
71
|
+
export * from './operation-node/create-view-node.js';
|
|
98
72
|
export * from './operation-node/data-type-node.js';
|
|
73
|
+
export * from './operation-node/default-value-node.js';
|
|
99
74
|
export * from './operation-node/delete-query-node.js';
|
|
100
75
|
export * from './operation-node/drop-column-node.js';
|
|
101
76
|
export * from './operation-node/drop-constraint-node.js';
|
|
102
77
|
export * from './operation-node/drop-index-node.js';
|
|
103
78
|
export * from './operation-node/drop-schema-node.js';
|
|
104
79
|
export * from './operation-node/drop-table-node.js';
|
|
80
|
+
export * from './operation-node/drop-view-node.js';
|
|
105
81
|
export * from './operation-node/filter-node.js';
|
|
106
82
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
107
83
|
export * from './operation-node/from-node.js';
|
|
84
|
+
export * from './operation-node/generated-always-as-node.js';
|
|
108
85
|
export * from './operation-node/group-by-item-node.js';
|
|
109
86
|
export * from './operation-node/group-by-node.js';
|
|
110
87
|
export * from './operation-node/having-node.js';
|
|
@@ -113,19 +90,50 @@ export * from './operation-node/insert-query-node.js';
|
|
|
113
90
|
export * from './operation-node/join-node.js';
|
|
114
91
|
export * from './operation-node/limit-node.js';
|
|
115
92
|
export * from './operation-node/list-node.js';
|
|
93
|
+
export * from './operation-node/modify-column-node.js';
|
|
116
94
|
export * from './operation-node/offset-node.js';
|
|
117
|
-
export * from './operation-node
|
|
118
|
-
export * from './operation-node/
|
|
95
|
+
export * from './operation-node/on-conflict-node.js';
|
|
96
|
+
export * from './operation-node/on-duplicate-key-node.js';
|
|
97
|
+
export * from './operation-node/on-node.js';
|
|
119
98
|
export * from './operation-node/operation-node-source.js';
|
|
99
|
+
export * from './operation-node/operation-node-transformer.js';
|
|
100
|
+
export * from './operation-node/operation-node-utils.js';
|
|
101
|
+
export * from './operation-node/operation-node-visitor.js';
|
|
102
|
+
export * from './operation-node/operation-node.js';
|
|
103
|
+
export * from './operation-node/operator-node.js';
|
|
104
|
+
export * from './operation-node/or-node.js';
|
|
105
|
+
export * from './operation-node/order-by-item-node.js';
|
|
120
106
|
export * from './operation-node/order-by-node.js';
|
|
107
|
+
export * from './operation-node/parens-node.js';
|
|
108
|
+
export * from './operation-node/primary-constraint-node.js';
|
|
109
|
+
export * from './operation-node/primitive-value-list-node.js';
|
|
110
|
+
export * from './operation-node/query-node.js';
|
|
111
|
+
export * from './operation-node/raw-node.js';
|
|
112
|
+
export * from './operation-node/reference-node.js';
|
|
113
|
+
export * from './operation-node/references-node.js';
|
|
114
|
+
export * from './operation-node/rename-column-node.js';
|
|
115
|
+
export * from './operation-node/returning-node.js';
|
|
116
|
+
export * from './operation-node/select-all-node.js';
|
|
117
|
+
export * from './operation-node/select-query-node.js';
|
|
118
|
+
export * from './operation-node/select-query-node.js';
|
|
119
|
+
export * from './operation-node/selection-node.js';
|
|
120
|
+
export * from './operation-node/table-node.js';
|
|
121
|
+
export * from './operation-node/union-node.js';
|
|
122
|
+
export * from './operation-node/unique-constraint-node.js';
|
|
123
|
+
export * from './operation-node/update-query-node.js';
|
|
124
|
+
export * from './operation-node/value-list-node.js';
|
|
125
|
+
export * from './operation-node/value-node.js';
|
|
126
|
+
export * from './operation-node/where-node.js';
|
|
127
|
+
export * from './operation-node/with-node.js';
|
|
121
128
|
export * from './introspection/database-introspector.js';
|
|
122
129
|
export * from './util/compilable.js';
|
|
130
|
+
export * from './util/log.js';
|
|
123
131
|
export { AnyColumn, UnknownRow, AnyQueryBuilder } from './util/type-utils.js';
|
|
124
132
|
export { SelectExpression, SelectExpressionOrList, } from './parser/select-parser.js';
|
|
125
133
|
export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
|
|
126
134
|
export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
|
|
127
135
|
export { ExistsExpression, FilterOperator } from './parser/filter-parser.js';
|
|
128
|
-
export { TableExpression } from './parser/table-parser.js';
|
|
136
|
+
export { TableExpression, TableExpressionOrList, } from './parser/table-parser.js';
|
|
129
137
|
export { JoinReferenceExpression, JoinCallbackExpression, } from './parser/join-parser.js';
|
|
130
138
|
export { InsertObject } from './parser/insert-values-parser.js';
|
|
131
139
|
export { MutationObject } from './parser/update-set-parser.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -51,35 +51,8 @@ export * from './migration/migration.js';
|
|
|
51
51
|
export * from './dialect/dialect.js';
|
|
52
52
|
export * from './dialect/dialect-adapter.js';
|
|
53
53
|
export * from './dialect/dialect-adapter-base.js';
|
|
54
|
-
export * from './operation-node/operation-node-transformer.js';
|
|
55
|
-
export * from './operation-node/operation-node-visitor.js';
|
|
56
54
|
export * from './plugin/kysely-plugin.js';
|
|
57
55
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
58
|
-
export * from './operation-node/operation-node-transformer.js';
|
|
59
|
-
export * from './operation-node/operation-node-visitor.js';
|
|
60
|
-
export * from './operation-node/operator-node.js';
|
|
61
|
-
export * from './operation-node/or-node.js';
|
|
62
|
-
export * from './operation-node/order-by-item-node.js';
|
|
63
|
-
export * from './operation-node/order-by-node.js';
|
|
64
|
-
export * from './operation-node/parens-node.js';
|
|
65
|
-
export * from './operation-node/primary-constraint-node.js';
|
|
66
|
-
export * from './operation-node/primitive-value-list-node.js';
|
|
67
|
-
export * from './operation-node/query-node.js';
|
|
68
|
-
export * from './operation-node/raw-node.js';
|
|
69
|
-
export * from './operation-node/reference-node.js';
|
|
70
|
-
export * from './operation-node/references-node.js';
|
|
71
|
-
export * from './operation-node/rename-column-node.js';
|
|
72
|
-
export * from './operation-node/returning-node.js';
|
|
73
|
-
export * from './operation-node/select-all-node.js';
|
|
74
|
-
export * from './operation-node/select-query-node.js';
|
|
75
|
-
export * from './operation-node/selection-node.js';
|
|
76
|
-
export * from './operation-node/table-node.js';
|
|
77
|
-
export * from './operation-node/unique-constraint-node.js';
|
|
78
|
-
export * from './operation-node/update-query-node.js';
|
|
79
|
-
export * from './operation-node/value-list-node.js';
|
|
80
|
-
export * from './operation-node/value-node.js';
|
|
81
|
-
export * from './operation-node/where-node.js';
|
|
82
|
-
export * from './operation-node/with-node.js';
|
|
83
56
|
export * from './operation-node/add-column-node.js';
|
|
84
57
|
export * from './operation-node/add-constraint-node.js';
|
|
85
58
|
export * from './operation-node/alias-node.js';
|
|
@@ -95,16 +68,20 @@ export * from './operation-node/constraint-node.js';
|
|
|
95
68
|
export * from './operation-node/create-index-node.js';
|
|
96
69
|
export * from './operation-node/create-schema-node.js';
|
|
97
70
|
export * from './operation-node/create-table-node.js';
|
|
71
|
+
export * from './operation-node/create-view-node.js';
|
|
98
72
|
export * from './operation-node/data-type-node.js';
|
|
73
|
+
export * from './operation-node/default-value-node.js';
|
|
99
74
|
export * from './operation-node/delete-query-node.js';
|
|
100
75
|
export * from './operation-node/drop-column-node.js';
|
|
101
76
|
export * from './operation-node/drop-constraint-node.js';
|
|
102
77
|
export * from './operation-node/drop-index-node.js';
|
|
103
78
|
export * from './operation-node/drop-schema-node.js';
|
|
104
79
|
export * from './operation-node/drop-table-node.js';
|
|
80
|
+
export * from './operation-node/drop-view-node.js';
|
|
105
81
|
export * from './operation-node/filter-node.js';
|
|
106
82
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
107
83
|
export * from './operation-node/from-node.js';
|
|
84
|
+
export * from './operation-node/generated-always-as-node.js';
|
|
108
85
|
export * from './operation-node/group-by-item-node.js';
|
|
109
86
|
export * from './operation-node/group-by-node.js';
|
|
110
87
|
export * from './operation-node/having-node.js';
|
|
@@ -113,10 +90,41 @@ export * from './operation-node/insert-query-node.js';
|
|
|
113
90
|
export * from './operation-node/join-node.js';
|
|
114
91
|
export * from './operation-node/limit-node.js';
|
|
115
92
|
export * from './operation-node/list-node.js';
|
|
93
|
+
export * from './operation-node/modify-column-node.js';
|
|
116
94
|
export * from './operation-node/offset-node.js';
|
|
117
|
-
export * from './operation-node
|
|
118
|
-
export * from './operation-node/
|
|
95
|
+
export * from './operation-node/on-conflict-node.js';
|
|
96
|
+
export * from './operation-node/on-duplicate-key-node.js';
|
|
97
|
+
export * from './operation-node/on-node.js';
|
|
119
98
|
export * from './operation-node/operation-node-source.js';
|
|
99
|
+
export * from './operation-node/operation-node-transformer.js';
|
|
100
|
+
export * from './operation-node/operation-node-utils.js';
|
|
101
|
+
export * from './operation-node/operation-node-visitor.js';
|
|
102
|
+
export * from './operation-node/operation-node.js';
|
|
103
|
+
export * from './operation-node/operator-node.js';
|
|
104
|
+
export * from './operation-node/or-node.js';
|
|
105
|
+
export * from './operation-node/order-by-item-node.js';
|
|
120
106
|
export * from './operation-node/order-by-node.js';
|
|
107
|
+
export * from './operation-node/parens-node.js';
|
|
108
|
+
export * from './operation-node/primary-constraint-node.js';
|
|
109
|
+
export * from './operation-node/primitive-value-list-node.js';
|
|
110
|
+
export * from './operation-node/query-node.js';
|
|
111
|
+
export * from './operation-node/raw-node.js';
|
|
112
|
+
export * from './operation-node/reference-node.js';
|
|
113
|
+
export * from './operation-node/references-node.js';
|
|
114
|
+
export * from './operation-node/rename-column-node.js';
|
|
115
|
+
export * from './operation-node/returning-node.js';
|
|
116
|
+
export * from './operation-node/select-all-node.js';
|
|
117
|
+
export * from './operation-node/select-query-node.js';
|
|
118
|
+
export * from './operation-node/select-query-node.js';
|
|
119
|
+
export * from './operation-node/selection-node.js';
|
|
120
|
+
export * from './operation-node/table-node.js';
|
|
121
|
+
export * from './operation-node/union-node.js';
|
|
122
|
+
export * from './operation-node/unique-constraint-node.js';
|
|
123
|
+
export * from './operation-node/update-query-node.js';
|
|
124
|
+
export * from './operation-node/value-list-node.js';
|
|
125
|
+
export * from './operation-node/value-node.js';
|
|
126
|
+
export * from './operation-node/where-node.js';
|
|
127
|
+
export * from './operation-node/with-node.js';
|
|
121
128
|
export * from './introspection/database-introspector.js';
|
|
122
129
|
export * from './util/compilable.js';
|
|
130
|
+
export * from './util/log.js';
|