-
i am trying to use it with node in this sample code but getting an error saying // database.js
import { PGlite } from '@electric-sql/pglite';
const defaultDatabaseConfig = { dataDir: process.env.PG_DATA };
export const prepareDatabase = (config = defaultDatabaseConfig) => {
const database = new PGlite(config.dataDir);
// ...
return database;
}; more complete error: Node.js v20.14.0
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node -r dotenv-flow/config index.js`
http://0.0.0.0:3000
node:fs:1372
const result = binding.mkdir(
^
Error: EEXIST: file already exists, mkdir './pgdata'
at Module.mkdirSync (node:fs:1372:26)
at c.init (file:///Users/sombriks/git/node-backend-validation/01-address-book-no-validate/node_modules/@electric-sql/pglite/dist/nodefs-XHHENSNF.js:1:328)
at file:///Users/sombriks/git/node-backend-validation/01-address-book-no-validate/node_modules/@electric-sql/pglite/dist/chunk-OVRU7FYL.js:1:24570 {
errno: -17,
code: 'EEXIST',
syscall: 'mkdir',
path: './pgdata'
} complete repo (at the commit when this issue presented itself) here. |
Beta Was this translation helpful? Give feedback.
Answered by
sombriks
Jul 10, 2024
Replies: 1 comment
-
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 while providing the current valid pglite instance. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sombriks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
that way i can call the prepare function as many times i want w…