@mikro-orm/sqlite 7.1.0-dev.5 → 7.1.0-dev.50
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 +3 -3
- package/SqliteMikroORM.js +3 -2
- package/index.d.ts +4 -0
- package/index.js +2 -0
- package/package.json +6 -6
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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
2
|
-
import type
|
|
1
|
+
import { type AnyEntity, type EntityClass, type EntitySchema, type MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
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
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>>;
|
|
@@ -8,7 +8,7 @@ export declare function defineSqliteConfig<EM extends SqlEntityManager<SqliteDri
|
|
|
8
8
|
/**
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
|
-
export declare class SqliteMikroORM<EM extends SqlEntityManager<SqliteDriver> = SqlEntityManager<SqliteDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends
|
|
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
|
*/
|
package/SqliteMikroORM.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineConfig,
|
|
1
|
+
import { defineConfig, } from '@mikro-orm/core';
|
|
2
|
+
import { SqlMikroORM } from '@mikro-orm/sql';
|
|
2
3
|
import { SqliteDriver } from './SqliteDriver.js';
|
|
3
4
|
/** Creates a type-safe configuration object for the SQLite driver. */
|
|
4
5
|
export function defineSqliteConfig(options) {
|
|
@@ -7,7 +8,7 @@ export function defineSqliteConfig(options) {
|
|
|
7
8
|
/**
|
|
8
9
|
* @inheritDoc
|
|
9
10
|
*/
|
|
10
|
-
export class SqliteMikroORM extends
|
|
11
|
+
export class SqliteMikroORM extends SqlMikroORM {
|
|
11
12
|
/**
|
|
12
13
|
* @inheritDoc
|
|
13
14
|
*/
|
package/index.d.ts
CHANGED
|
@@ -2,3 +2,7 @@ export * from '@mikro-orm/sql';
|
|
|
2
2
|
export * from './SqliteConnection.js';
|
|
3
3
|
export { SqliteDriver } from './SqliteDriver.js';
|
|
4
4
|
export { SqliteMikroORM as MikroORM, type SqliteOptions as Options, defineSqliteConfig as defineConfig, } from './SqliteMikroORM.js';
|
|
5
|
+
import { type AbstractSqlDriver, SqlEntityManager } from '@mikro-orm/sql';
|
|
6
|
+
import type { SqliteDriver as SqliteDriverType } from './SqliteDriver.js';
|
|
7
|
+
export type EntityManager<Driver extends AbstractSqlDriver = SqliteDriverType> = SqlEntityManager<Driver>;
|
|
8
|
+
export declare const EntityManager: typeof SqlEntityManager;
|
package/index.js
CHANGED
|
@@ -2,3 +2,5 @@ export * from '@mikro-orm/sql';
|
|
|
2
2
|
export * from './SqliteConnection.js';
|
|
3
3
|
export { SqliteDriver } from './SqliteDriver.js';
|
|
4
4
|
export { SqliteMikroORM as MikroORM, defineSqliteConfig as defineConfig, } from './SqliteMikroORM.js';
|
|
5
|
+
import { SqlEntityManager } from '@mikro-orm/sql';
|
|
6
|
+
export const EntityManager = SqlEntityManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sqlite",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.50",
|
|
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,15 +47,15 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.1.0-dev.
|
|
51
|
-
"better-sqlite3": "12.
|
|
52
|
-
"kysely": "0.
|
|
50
|
+
"@mikro-orm/sql": "7.1.0-dev.50",
|
|
51
|
+
"better-sqlite3": "12.10.0",
|
|
52
|
+
"kysely": "0.29.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@mikro-orm/core": "^7.0.
|
|
55
|
+
"@mikro-orm/core": "^7.0.17"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@mikro-orm/core": "7.1.0-dev.
|
|
58
|
+
"@mikro-orm/core": "7.1.0-dev.50"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">= 22.17.0"
|