Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support for concurrent databases (node.js) #324

Open
aluxian opened this issue Sep 14, 2024 · 0 comments
Open

Support for concurrent databases (node.js) #324

aluxian opened this issue Sep 14, 2024 · 0 comments

Comments

@aluxian
Copy link

aluxian commented Sep 14, 2024

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:

// 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();
  });
  
  ...
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant