@mikro-orm/sql 7.1.9-dev.4 → 7.1.9-dev.6
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.
|
@@ -7,4 +7,7 @@ export declare class BaseSqliteConnection extends AbstractSqlConnection {
|
|
|
7
7
|
skipOnConnect?: boolean;
|
|
8
8
|
}): Promise<void>;
|
|
9
9
|
protected attachDatabases(): Promise<void>;
|
|
10
|
+
/** Per-connection state, lost whenever the underlying connection is recreated, so it has to be replayed. */
|
|
11
|
+
protected getConnectionSetupSql(): Promise<string[]>;
|
|
12
|
+
private getAttachDatabasesSql;
|
|
10
13
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CompiledQuery } from 'kysely';
|
|
2
2
|
import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
|
|
3
|
+
const FOREIGN_KEYS_PRAGMA = 'pragma foreign_keys = on';
|
|
3
4
|
export class BaseSqliteConnection extends AbstractSqlConnection {
|
|
4
5
|
createKyselyDialect(options) {
|
|
5
6
|
throw new Error('No SQLite dialect configured. Pass a Kysely dialect via the `driverOptions` config option, ' +
|
|
@@ -7,19 +8,28 @@ export class BaseSqliteConnection extends AbstractSqlConnection {
|
|
|
7
8
|
}
|
|
8
9
|
async connect(options) {
|
|
9
10
|
await super.connect(options);
|
|
10
|
-
await this.getClient().executeQuery(CompiledQuery.raw(
|
|
11
|
+
await this.getClient().executeQuery(CompiledQuery.raw(FOREIGN_KEYS_PRAGMA));
|
|
11
12
|
await this.attachDatabases();
|
|
12
13
|
}
|
|
13
14
|
async attachDatabases() {
|
|
15
|
+
for (const sql of await this.getAttachDatabasesSql()) {
|
|
16
|
+
await this.execute(sql);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Per-connection state, lost whenever the underlying connection is recreated, so it has to be replayed. */
|
|
20
|
+
async getConnectionSetupSql() {
|
|
21
|
+
return [FOREIGN_KEYS_PRAGMA, ...(await this.getAttachDatabasesSql())];
|
|
22
|
+
}
|
|
23
|
+
async getAttachDatabasesSql() {
|
|
14
24
|
const attachDatabases = this.config.get('attachDatabases');
|
|
15
25
|
if (!attachDatabases?.length) {
|
|
16
|
-
return;
|
|
26
|
+
return [];
|
|
17
27
|
}
|
|
18
28
|
const { fs } = await import('@mikro-orm/core/fs-utils');
|
|
19
29
|
const baseDir = this.config.get('baseDir');
|
|
20
|
-
|
|
30
|
+
return attachDatabases.map(db => {
|
|
21
31
|
const path = fs.absolutePath(db.path, baseDir);
|
|
22
|
-
|
|
23
|
-
}
|
|
32
|
+
return `attach database '${path}' as ${this.platform.quoteIdentifier(db.name)}`;
|
|
33
|
+
});
|
|
24
34
|
}
|
|
25
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.9-dev.
|
|
3
|
+
"version": "7.1.9-dev.6",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.1.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.9-dev.6"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|