@sibokdev/embedded-postgres
v15.1.0-beta.14
Published
A package to run an embedded Postgresql database right from NodeJS
Downloads
9
Maintainers
Readme
embedded-postgres
A Node package that allows you to spawn a Postgresql cluster programatically.
Usage
npm i embedded-postgres
import EmbeddedPostgres from 'embedded-postgres';
async function main() {
// Create the object
const pg = new EmbeddedPostgres({
data_dir: './data/db',
user: 'postgres',
password: 'password',
port: 5432,
persistent: true,
});
// Create the cluster config files
await pg.inititialize();
// Start the server
await pg.start();
// Create and/or drop database
await pg.createDatabase('TEST');
await pg.dropDatabase('TEST');
// Initialize a node-postgres client
const client = pg.getPgClient();
await client.connect();
const result = await client.query('SELECT datname FROM pg_database');
// Stop the server
await pg.stop();
}
main();
Credits
Embedded Postgres was created by Lei Nelissen for BMD Studio. It is based on zonky's embedded-postgres-binaries.