@mikro-orm/sqlite 7.1.0-dev.43 → 7.1.0-dev.45

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.
@@ -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
  }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sqlite",
3
- "version": "7.1.0-dev.43",
3
+ "version": "7.1.0-dev.45",
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.1.0-dev.43",
50
+ "@mikro-orm/sql": "7.1.0-dev.45",
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.1.0-dev.43"
58
+ "@mikro-orm/core": "7.1.0-dev.45"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">= 22.17.0"