npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mikro-orm-pglite

v0.5.1

Published

A driver for using PGlite with MikroORM.

Readme

MikroORM PGlite Driver

test npm version npm downloads

A driver for using PGlite with MikroORM.

Table of Contents

Language

Installation

Install with the following commands.

# using npm
npm install @electric-sql/pglite @mikro-orm/postgresql mikro-orm-pglite
# using pnpm
pnpm add @electric-sql/pglite @mikro-orm/postgresql mikro-orm-pglite

[!WARNING]
Yarn and Bun environments have not been tested yet for compatibility.

Usage

Easy initialization

Configure the driver property of MikroORM.init parameters to PGliteDriver.

The example below shows an easy initialization method.

import { MikroORM } from "@mikro-orm/core";
import { PGliteDriver } from "mikro-orm-pglite";

const orm = await MikroORM.init({
  driver: PGliteDriver,
  dbName: "postgres",
});

await orm.close();

[!WARNING]
The dbName property must be configured.

[!NOTE]
Please read the documentation below for more information on how to configure MikroORM.

Injecting a PGlite instance

When using the Easy initialization method, the PGlite instance is initialized using the In-memory ephemeral storage method. Additionally, the PGlite instance becomes owned by the MikroORM instance. In other words, the PGlite instance shares its lifecycle with the MikroORM instance.

For PGlite instances with In-memory ephemeral storage, sharing the lifecycle with a MikroORM instance may not meet your needs depending on your use case. You may also want to initialize it in a File system storage method or take advantage of the various parameters of the PGlite constructor.

Configure the driverOptions.connection.pglite property to a synchronous or asynchronous function that returns a PGlite instance. In this case, MikroORM considers the PGlite instance as borrowed. In other words, MikroORM does not manage the creation and destruction of PGlite instances, since it delegates the lifecycle of PGlite instances to an external entity.

The example below shows how to inject a PGlite instance.

import { PGlite } from "@electric-sql/pglite";
import { MikroORM } from "@mikro-orm/core";
import { PGliteConnectionConfig, PGliteDriver } from "mikro-orm-pglite";

const pglite = new PGlite();

const orm = await MikroORM.init({
  driver: PGliteDriver,
  dbName: "postgres",
  driverOptions: {
    connection: {
      pglite: () => pglite,
    } satisfies PGliteConnectionConfig,
  },
});

await orm.close();

await pglite.close();

API

Configure the following properties from the parameters of the driverOptions property:

connection

The type of the connection property is:

export interface PGliteConnectionConfig {
  pglite?: PGliteProvider;
}

The following are the properties for configuring connection.

pglite

The type of the pglite property is:

export interface PGliteProvider {
  (): MaybePromise<PGlite>; // (): PGlite | Promise<PGlite>
}

[!NOTE]
To learn more about PGlite's various features, please read the PGlite API documentation.

License

MIT