@mikro-orm/pglite 7.1.5-dev.2 → 7.1.5-dev.20

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.
@@ -40,14 +40,16 @@ export class PgliteConnection extends AbstractSqlConnection {
40
40
  const dataDir = options.dataDir ?? dbName;
41
41
  const parsers = { ...createPostgreSqlTypeParsers(s => array.parse(s)), ...options.parsers };
42
42
  this.#ownsPglite = !userPglite;
43
- // Skip `pglite.close()` (called by kysely's `PGliteDriver.destroy()`) when:
44
- // - the user owns the instance (closing it is their responsibility), or
45
- // - we hold an in-memory DB whose data would otherwise be lost on
46
- // reconnect (e.g. test harnesses that drive `orm.close()` + `orm.connect()`).
47
- // For file/IDB-backed instances we let kysely close so file handles / IDB
48
- // connections are released; we drop our cached promise in `close()` below
49
- // so the next dialect-construction rebuilds the PGlite instance.
50
- this.#neuterClose = !this.#ownsPglite || isInMemoryDataDir(dataDir);
43
+ // Skip `pglite.close()` (called by kysely's `PGliteDriver.destroy()`) only
44
+ // when the user owns the instance closing it is their responsibility, and
45
+ // patching `close` on it directly would orphan it (its real `close` would
46
+ // stay neutered after `orm.close()`). Instances we own (in-memory or
47
+ // file/IDB-backed) get really closed so the underlying WASM / file handle /
48
+ // IDB resources are released; we drop our cached promise in `close()` below
49
+ // so the next dialect-construction rebuilds the PGlite instance. In-memory
50
+ // data does not survive `orm.close()`, consistent with other in-memory
51
+ // drivers (e.g. SQLite `:memory:`).
52
+ this.#neuterClose = !this.#ownsPglite;
51
53
  if (!this.#pglite) {
52
54
  if (userPglite) {
53
55
  this.#pglite = typeof userPglite === 'function' ? Promise.resolve(userPglite()) : Promise.resolve(userPglite);
@@ -88,9 +90,9 @@ export class PgliteConnection extends AbstractSqlConnection {
88
90
  }
89
91
  async close(force) {
90
92
  await super.close(force);
91
- // Persistent backings (file/IDB) we own get really closed by kysely — drop
92
- // the cached promise so a subsequent reconnect rebuilds a fresh instance
93
- // (which then re-reads the persisted data from disk / IDB).
93
+ // Instances we own get really closed by kysely — drop the cached promise so a
94
+ // subsequent reconnect rebuilds a fresh instance (file/IDB backings re-read the
95
+ // persisted data; in-memory starts empty, matching other in-memory drivers).
94
96
  if (this.#ownsPglite && !this.#neuterClose) {
95
97
  this.#pglite = undefined;
96
98
  }
@@ -1,11 +1,15 @@
1
1
  import { type IPostgresInterval } from 'postgres-interval';
2
- import { BasePostgreSqlPlatform } from '@mikro-orm/sql';
2
+ import { BasePostgreSqlPlatform, type EntityManager, type IDatabaseDriver, type MikroORM } from '@mikro-orm/sql';
3
3
  import { PgliteSchemaHelper } from './PgliteSchemaHelper.js';
4
+ import { PgliteSchemaGenerator } from './PgliteSchemaGenerator.js';
5
+ import type { PgliteDriver } from './PgliteDriver.js';
4
6
  /** Platform implementation for PGlite (PostgreSQL in WASM, single-database). */
5
7
  export declare class PglitePlatform extends BasePostgreSqlPlatform {
6
8
  protected readonly schemaHelper: PgliteSchemaHelper;
7
9
  /** PGlite uses the extended query protocol — one statement per `query()` call. */
8
10
  supportsMultipleStatements(): boolean;
11
+ lookupExtensions(orm: MikroORM<PgliteDriver>): void;
12
+ getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): PgliteSchemaGenerator;
9
13
  convertIntervalToJSValue(value: string): unknown;
10
14
  convertIntervalToDatabaseValue(value: IPostgresInterval): unknown;
11
15
  unmarshallArray(value: string): string[];
package/PglitePlatform.js CHANGED
@@ -3,6 +3,7 @@ import parseDate from 'postgres-date';
3
3
  import PostgresInterval from 'postgres-interval';
4
4
  import { BasePostgreSqlPlatform, Utils } from '@mikro-orm/sql';
5
5
  import { PgliteSchemaHelper } from './PgliteSchemaHelper.js';
6
+ import { PgliteSchemaGenerator } from './PgliteSchemaGenerator.js';
6
7
  /** Platform implementation for PGlite (PostgreSQL in WASM, single-database). */
7
8
  export class PglitePlatform extends BasePostgreSqlPlatform {
8
9
  schemaHelper = new PgliteSchemaHelper(this);
@@ -10,6 +11,13 @@ export class PglitePlatform extends BasePostgreSqlPlatform {
10
11
  supportsMultipleStatements() {
11
12
  return false;
12
13
  }
14
+ lookupExtensions(orm) {
15
+ PgliteSchemaGenerator.register(orm);
16
+ }
17
+ /* v8 ignore next: kept for type inference only */
18
+ getSchemaGenerator(driver, em) {
19
+ return new PgliteSchemaGenerator(em ?? driver);
20
+ }
13
21
  convertIntervalToJSValue(value) {
14
22
  return PostgresInterval(value);
15
23
  }
@@ -0,0 +1,17 @@
1
+ import { type MikroORM, SchemaGenerator } from '@mikro-orm/sql';
2
+ import type { PgliteDriver } from './PgliteDriver.js';
3
+ /**
4
+ * In the default (single-database) setup a PGlite instance maps 1:1 to its
5
+ * `dataDir`, so there are no separate databases to create or drop and both
6
+ * operations are no-ops. The inherited implementation would otherwise switch
7
+ * `dbName` and reconnect, rebuilding the instance with the new name as its
8
+ * `dataDir` — materializing a stray on-disk data directory. Named-database mode
9
+ * (`driverOptions.dataDir` set) keeps the real `CREATE DATABASE` lifecycle.
10
+ */
11
+ export declare class PgliteSchemaGenerator extends SchemaGenerator {
12
+ static register(orm: MikroORM<PgliteDriver>): void;
13
+ createDatabase(name?: string, options?: {
14
+ skipOnConnect?: boolean;
15
+ }): Promise<void>;
16
+ dropDatabase(name?: string): Promise<void>;
17
+ }
@@ -0,0 +1,26 @@
1
+ import { SchemaGenerator } from '@mikro-orm/sql';
2
+ /**
3
+ * In the default (single-database) setup a PGlite instance maps 1:1 to its
4
+ * `dataDir`, so there are no separate databases to create or drop and both
5
+ * operations are no-ops. The inherited implementation would otherwise switch
6
+ * `dbName` and reconnect, rebuilding the instance with the new name as its
7
+ * `dataDir` — materializing a stray on-disk data directory. Named-database mode
8
+ * (`driverOptions.dataDir` set) keeps the real `CREATE DATABASE` lifecycle.
9
+ */
10
+ export class PgliteSchemaGenerator extends SchemaGenerator {
11
+ static register(orm) {
12
+ orm.config.registerExtension('@mikro-orm/schema-generator', () => new PgliteSchemaGenerator(orm.em));
13
+ }
14
+ async createDatabase(name, options) {
15
+ if (!this.helper.getManagementDbName()) {
16
+ return;
17
+ }
18
+ return super.createDatabase(name, options);
19
+ }
20
+ async dropDatabase(name) {
21
+ if (!this.helper.getManagementDbName()) {
22
+ return;
23
+ }
24
+ return super.dropDatabase(name);
25
+ }
26
+ }
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './PgliteConnection.js';
3
3
  export * from './PgliteDriver.js';
4
4
  export * from './PglitePlatform.js';
5
5
  export * from './PgliteSchemaHelper.js';
6
+ export * from './PgliteSchemaGenerator.js';
6
7
  export { PgliteMikroORM as MikroORM, type PgliteOptions as Options, definePgliteConfig as defineConfig, } from './PgliteMikroORM.js';
7
8
  export { raw } from './raw.js';
8
9
  import { type AbstractSqlDriver, BasePostgreSqlEntityManager } from '@mikro-orm/sql';
package/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './PgliteConnection.js';
3
3
  export * from './PgliteDriver.js';
4
4
  export * from './PglitePlatform.js';
5
5
  export * from './PgliteSchemaHelper.js';
6
+ export * from './PgliteSchemaGenerator.js';
6
7
  export { PgliteMikroORM as MikroORM, definePgliteConfig as defineConfig, } from './PgliteMikroORM.js';
7
8
  export { raw } from './raw.js';
8
9
  import { BasePostgreSqlEntityManager } from '@mikro-orm/sql';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/pglite",
3
- "version": "7.1.5-dev.2",
3
+ "version": "7.1.5-dev.20",
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",
@@ -48,8 +48,8 @@
48
48
  "copy": "node ../../scripts/copy.mjs"
49
49
  },
50
50
  "dependencies": {
51
- "@electric-sql/pglite": "0.5.1",
52
- "@mikro-orm/sql": "7.1.5-dev.2",
51
+ "@electric-sql/pglite": "0.5.3",
52
+ "@mikro-orm/sql": "7.1.5-dev.20",
53
53
  "kysely": "0.29.2",
54
54
  "postgres-array": "3.0.4",
55
55
  "postgres-date": "2.1.0",
@@ -59,7 +59,7 @@
59
59
  "@mikro-orm/core": "^7.1.4"
60
60
  },
61
61
  "peerDependencies": {
62
- "@mikro-orm/core": "7.1.5-dev.2"
62
+ "@mikro-orm/core": "7.1.5-dev.20"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">= 22.17.0"