@mikro-orm/sqlite 7.0.17 → 7.0.18-dev.1
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 -1
- package/SqliteConnection.d.ts +4 -0
- package/SqliteConnection.js +27 -0
- package/SqliteMikroORM.d.ts +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL (including CockroachDB and PGlite), SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
@@ -19,6 +19,7 @@ Install a driver package for your database:
|
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install @mikro-orm/postgresql # PostgreSQL
|
|
22
|
+
npm install @mikro-orm/pglite # PGlite (embedded PostgreSQL in WASM)
|
|
22
23
|
npm install @mikro-orm/mysql # MySQL
|
|
23
24
|
npm install @mikro-orm/mariadb # MariaDB
|
|
24
25
|
npm install @mikro-orm/sqlite # SQLite
|
package/SqliteConnection.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { BaseSqliteConnection, type Dictionary } from '@mikro-orm/sql';
|
|
2
2
|
import { type Dialect } from 'kysely';
|
|
3
|
+
import { type Routine, type Transaction } from '@mikro-orm/core';
|
|
3
4
|
/** SQLite database connection using the `better-sqlite3` driver. */
|
|
4
5
|
export declare class SqliteConnection extends BaseSqliteConnection {
|
|
6
|
+
#private;
|
|
5
7
|
private database;
|
|
6
8
|
createKyselyDialect(options: Dictionary): Dialect;
|
|
7
9
|
/** @inheritDoc */
|
|
8
10
|
executeDump(dump: string): Promise<void>;
|
|
11
|
+
/** SQLite has no procedures; functions bridge via `bodyJs` registered as a UDF. */
|
|
12
|
+
callRoutine<T>(routine: Routine, args?: Record<string, unknown>, ctx?: Transaction): Promise<T>;
|
|
9
13
|
}
|
package/SqliteConnection.js
CHANGED
|
@@ -4,9 +4,13 @@ import Database from 'better-sqlite3';
|
|
|
4
4
|
/** SQLite database connection using the `better-sqlite3` driver. */
|
|
5
5
|
export class SqliteConnection extends BaseSqliteConnection {
|
|
6
6
|
database;
|
|
7
|
+
// Routine name → registered `bodyJs` ref. Reference compare to detect HMR swaps and re-register.
|
|
8
|
+
#registeredRoutines = new Map();
|
|
7
9
|
createKyselyDialect(options) {
|
|
8
10
|
const dbName = options.dbName ?? this.config.get('dbName');
|
|
9
11
|
this.database = new Database(dbName, options);
|
|
12
|
+
// Fresh Database = fresh process-side function table; clear cached registrations.
|
|
13
|
+
this.#registeredRoutines.clear();
|
|
10
14
|
return new SqliteDialect({
|
|
11
15
|
database: this.database,
|
|
12
16
|
onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
|
|
@@ -17,4 +21,27 @@ export class SqliteConnection extends BaseSqliteConnection {
|
|
|
17
21
|
await this.ensureConnection();
|
|
18
22
|
this.database.exec(dump);
|
|
19
23
|
}
|
|
24
|
+
/** SQLite has no procedures; functions bridge via `bodyJs` registered as a UDF. */
|
|
25
|
+
async callRoutine(routine, args = {}, ctx) {
|
|
26
|
+
if (routine.type === 'procedure') {
|
|
27
|
+
throw new Error(`Stored procedures are not supported on SQLite. Routine ${routine.name} cannot be invoked here — define a separate code path for SQLite or call it only against a server-side database.`);
|
|
28
|
+
}
|
|
29
|
+
if (!routine.bodyJs) {
|
|
30
|
+
throw new Error(`Function ${routine.name} cannot be invoked on SQLite without a 'bodyJs' fallback. Add a JS implementation to the Routine declaration to enable cross-DB testing.`);
|
|
31
|
+
}
|
|
32
|
+
await this.ensureConnection();
|
|
33
|
+
const fn = routine.bodyJs;
|
|
34
|
+
// Re-register on reference mismatch (HMR or a re-bound closure); better-sqlite3 replaces silently.
|
|
35
|
+
if (this.#registeredRoutines.get(routine.name) !== fn) {
|
|
36
|
+
this.database.function(routine.name, { deterministic: routine.deterministic ?? false, varargs: true }, (...positional) => {
|
|
37
|
+
const named = {};
|
|
38
|
+
routine.params.forEach((p, i) => {
|
|
39
|
+
named[p.name] = positional[i];
|
|
40
|
+
});
|
|
41
|
+
return fn(named);
|
|
42
|
+
});
|
|
43
|
+
this.#registeredRoutines.set(routine.name, fn);
|
|
44
|
+
}
|
|
45
|
+
return this.callRoutineFunction(routine, args, ctx);
|
|
46
|
+
}
|
|
20
47
|
}
|
package/SqliteMikroORM.d.ts
CHANGED
|
@@ -2,17 +2,17 @@ import { type AnyEntity, type EntityClass, type EntitySchema, type MikroORM, typ
|
|
|
2
2
|
import { SqlMikroORM, type SqlEntityManager } from '@mikro-orm/sql';
|
|
3
3
|
import { SqliteDriver } from './SqliteDriver.js';
|
|
4
4
|
/** Configuration options for the SQLite driver. */
|
|
5
|
-
export type SqliteOptions<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<SqliteDriver, EM, Entities>>;
|
|
5
|
+
export type SqliteOptions<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<SqliteDriver, EM, Entities>>;
|
|
6
6
|
/** Creates a type-safe configuration object for the SQLite driver. */
|
|
7
|
-
export declare function defineSqliteConfig<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<SqliteDriver, EM, Entities>>): Partial<Options<SqliteDriver, EM, Entities>>;
|
|
7
|
+
export declare function defineSqliteConfig<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<SqliteDriver, EM, Entities>>): Partial<Options<SqliteDriver, EM, Entities>>;
|
|
8
8
|
/**
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
|
-
export declare class SqliteMikroORM<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends SqlMikroORM<SqliteDriver, EM, Entities> {
|
|
11
|
+
export declare class SqliteMikroORM<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends SqlMikroORM<SqliteDriver, EM, Entities> {
|
|
12
12
|
/**
|
|
13
13
|
* @inheritDoc
|
|
14
14
|
*/
|
|
15
|
-
static init<D extends IDatabaseDriver = SqliteDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
15
|
+
static init<D extends IDatabaseDriver = SqliteDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
16
16
|
/**
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sqlite",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.18-dev.1",
|
|
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",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.0.
|
|
50
|
+
"@mikro-orm/sql": "7.0.18-dev.1",
|
|
51
51
|
"better-sqlite3": "12.10.0",
|
|
52
52
|
"kysely": "0.29.2"
|
|
53
53
|
},
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@mikro-orm/core": "^7.0.17"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@mikro-orm/core": "7.0.
|
|
58
|
+
"@mikro-orm/core": "7.0.18-dev.1"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">= 22.17.0"
|