electric-sql / electric-sql/pglite

Support for concurrent databases (node.js)

Open
#324 6 comments 20 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
16k
Forks
442
Avg merge
20h 19m
Merged PRs (30d)
7

Description

First of all — awesome work! Having lightweight on-the-fly instances of PostgreSQL is a game changer.

We use pglite to run our DB tests. Our test runner is AVA. Even though AVA runs test cases in the same file in parallel, we find that pglite tests always complete serially. It appears that pglite only permits 1 in-memory DB to be used at a time.

Can pglite support multiple in-mem databases being created/connected/queried at once? Specifically for node.js, as the browser might understandably have different constraints.

What would it take for this to work?

Example usage:

```js
// set up DB named neondb (required by migrations)
const db0 = await PGlite.create();
await db0.query('CREATE DATABASE neondb');
const dump0 = await db0.dumpDataDir();
await db0.close();

// apply migrations
const db1 = await PGlite.create({
loadDataDir: dump0,
database: 'neondb',
extensions: {
vector,
},
});
await applyMigrations(db1);
const dump1 = await db1.dumpDataDir();
await db1.close();

// the above runs once per test suite (reused)
// the below runs once per test case

export async function getTestSql(t) {
const db = await PGlite.create({
loadDataDir: dump1,
database: 'neondb',
extensions: {
vector,
},
});

t.teardown(async () => {
await db.close();
});

...
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.