ForrestJS service which keeps a pooled connection to a PostgreSQL database. It's a wrapper around pg library.
You can run the $PG_READY
extension to execute SQL logic at boot time:
const myFeature = {
target: '$PG_READY',
handler: async ({ query }) => {
const res = await query('SELECT NOW()');
console.log(res.rows);
},
};
Or you can get a reference to the query
function or the pool
object from the context:
const myFeature = {
target: '$START_FEATURE',
handler: async ({ getContext }) => {
const query = getContext('pg.query');
await query('CREATE TABLE IF NOT EXISTS...');
},
};
Falls back on env PGSTRING
.
Falls back on env SERVICE_PG_EXIT_ON_ERROR
.
Falls back on env SERVICE_PG_MAX_CONNECTIONS
.
Any configuration that you can give to the library pg
.
Standard connectivity string for PostgreSQL
PGSTRING=postgres://postgres:postgres@localhost:5432/postgres
If set to true
the library will crash the project in case connectivity is lost. Default is false
.
Max number of pooled connections to the database server. Default is 10
.