@mikro-orm/knex 6.2.10-dev.73 → 6.2.10-dev.74
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.
|
@@ -2,5 +2,10 @@ import { MonkeyPatchable } from '../../MonkeyPatchable';
|
|
|
2
2
|
export declare class LibSqlKnexDialect extends MonkeyPatchable.BetterSqlite3Dialect {
|
|
3
3
|
get driverName(): string;
|
|
4
4
|
_driver(): any;
|
|
5
|
+
_query(this: any, connection: any, obj: any): Promise<any>;
|
|
6
|
+
acquireRawConnection(this: any): Promise<any>;
|
|
5
7
|
tableCompiler(): any;
|
|
8
|
+
validateConnection(connection: any): boolean;
|
|
9
|
+
private getCallMethod;
|
|
10
|
+
private isRunQuery;
|
|
6
11
|
}
|
|
@@ -10,9 +10,76 @@ class LibSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.BetterSqlite3D
|
|
|
10
10
|
_driver() {
|
|
11
11
|
return require('libsql');
|
|
12
12
|
}
|
|
13
|
+
async _query(connection, obj) {
|
|
14
|
+
/* istanbul ignore next */
|
|
15
|
+
if (!obj.sql) {
|
|
16
|
+
throw new Error('The query is empty');
|
|
17
|
+
}
|
|
18
|
+
/* istanbul ignore next */
|
|
19
|
+
if (!connection) {
|
|
20
|
+
throw new Error('No connection provided');
|
|
21
|
+
}
|
|
22
|
+
const callMethod = this.getCallMethod(obj);
|
|
23
|
+
const statement = connection.prepare(obj.sql);
|
|
24
|
+
const bindings = this._formatBindings(obj.bindings);
|
|
25
|
+
const response = await statement[callMethod](bindings);
|
|
26
|
+
obj.response = response;
|
|
27
|
+
obj.context = {
|
|
28
|
+
lastID: response.lastInsertRowid,
|
|
29
|
+
changes: response.changes,
|
|
30
|
+
};
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
async acquireRawConnection() {
|
|
34
|
+
const connection = new this.driver(this.connectionSettings.filename, {
|
|
35
|
+
...this.connectionSettings,
|
|
36
|
+
});
|
|
37
|
+
connection.__created = Date.now();
|
|
38
|
+
return connection;
|
|
39
|
+
}
|
|
13
40
|
tableCompiler() {
|
|
14
41
|
// eslint-disable-next-line prefer-rest-params
|
|
15
42
|
return new SqliteTableCompiler_1.SqliteTableCompiler(this, ...arguments);
|
|
16
43
|
}
|
|
44
|
+
validateConnection(connection) {
|
|
45
|
+
if (connection.memory) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/* istanbul ignore next */
|
|
49
|
+
return connection.__created > Date.now() - 10_000;
|
|
50
|
+
}
|
|
51
|
+
getCallMethod(obj) {
|
|
52
|
+
if (obj.method === 'raw') {
|
|
53
|
+
const query = obj.sql.trim().toLowerCase();
|
|
54
|
+
if ((query.startsWith('insert into') || query.startsWith('update ')) && query.includes(' returning ')) {
|
|
55
|
+
return 'all';
|
|
56
|
+
}
|
|
57
|
+
if (this.isRunQuery(query)) {
|
|
58
|
+
return 'run';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/* istanbul ignore next */
|
|
62
|
+
switch (obj.method) {
|
|
63
|
+
case 'insert':
|
|
64
|
+
case 'update':
|
|
65
|
+
return obj.returning ? 'all' : 'run';
|
|
66
|
+
case 'counter':
|
|
67
|
+
case 'del':
|
|
68
|
+
return 'run';
|
|
69
|
+
default:
|
|
70
|
+
return 'all';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
isRunQuery(query) {
|
|
74
|
+
query = query.trim().toLowerCase();
|
|
75
|
+
/* istanbul ignore next */
|
|
76
|
+
if ((query.startsWith('insert into') || query.startsWith('update ')) && query.includes(' returning ')) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return query.startsWith('insert into') ||
|
|
80
|
+
query.startsWith('update') ||
|
|
81
|
+
query.startsWith('delete') ||
|
|
82
|
+
query.startsWith('truncate');
|
|
83
|
+
}
|
|
17
84
|
}
|
|
18
85
|
exports.LibSqlKnexDialect = LibSqlKnexDialect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.2.10-dev.
|
|
3
|
+
"version": "6.2.10-dev.74",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.2.9"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.2.10-dev.
|
|
69
|
+
"@mikro-orm/core": "6.2.10-dev.74",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -70,17 +70,11 @@ class DatabaseTable {
|
|
|
70
70
|
prop.length = undefined;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
if (mappedType instanceof core_1.DateTimeType || mappedType instanceof core_1.IntervalType) {
|
|
74
|
-
const match = prop.columnTypes[idx].match(/\w+\((\d+)\)/);
|
|
75
|
-
if (match) {
|
|
76
|
-
prop.length ??= +match[1];
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
prop.length ??= this.platform.getDefaultDateTimeLength();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
73
|
if (prop.length == null && prop.columnTypes[idx]) {
|
|
83
74
|
prop.length = this.platform.getSchemaHelper().inferLengthFromColumnType(prop.columnTypes[idx]);
|
|
75
|
+
if (typeof mappedType.getDefaultLength !== 'undefined') {
|
|
76
|
+
prop.length ??= mappedType.getDefaultLength(this.platform);
|
|
77
|
+
}
|
|
84
78
|
}
|
|
85
79
|
const primary = !meta.compositePK && !!prop.primary && prop.kind === core_1.ReferenceKind.SCALAR && this.platform.isNumericColumn(mappedType);
|
|
86
80
|
this.columns[field] = {
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -30,7 +30,11 @@ class SchemaHelper {
|
|
|
30
30
|
return core_1.Utils.flatten(pks);
|
|
31
31
|
}
|
|
32
32
|
inferLengthFromColumnType(type) {
|
|
33
|
-
|
|
33
|
+
const match = type.match(/^\w+\s*(?:\(\s*(\d+)\s*\)|$)/);
|
|
34
|
+
if (!match) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
return +match[1];
|
|
34
38
|
}
|
|
35
39
|
async getForeignKeys(connection, tableName, schemaName) {
|
|
36
40
|
const fks = await connection.execute(this.getForeignKeysSQL(tableName, schemaName));
|