Skip to content

using with node, how do i perform an initdb? #114

Closed Answered by sombriks
sombriks asked this question in Q&A
Discussion options

You must be logged in to vote

ok i've read the docs more carefully and found the issue, i must ensure that only one pglite instance is available for the process:

// database.js
import { PGlite } from '@electric-sql/pglite';

const defaultDatabaseConfig = { dataDir: process.env.PG_DATA };

let database

export const prepareDatabase = async (config = defaultDatabaseConfig) => {
  // https://github.com/sombriks/pglite/tree/main?tab=readme-ov-file#limitations
  if (!database || database.closed) {
    database = new PGlite(config.dataDir);
    // ...
    const test = await database.query("select 1 + 1 as result")
    console.log(test)
  }
  return database;
};

that way i can call the prepare function as many times i want w…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sombriks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant