Inject Postgres connections into Hapi requests.
Wrap Hapi requests with access to a Postgres connection.
It gives you access to
request.postgres.client within your handlers which you can then use to make Postgres requests. It also takes care of cleaning up the connection after the request.
var hapiPgOpts =connectionString: 'tcp://postgres@localhost:5432/postgres';serverregisterregister: require'hapi-pg'options: hapiPgOptsif errconsole.errorerr;throw err;;
It can also take a function to dynamically resolve connection name based on the incoming request.
var hapiPgOpts =return 'tcp://postgres@localhost:5432/' + requestquerydatabase;;serverregisterregister: require'hapi-pg'options: hapiPgOptsif errconsole.errorerr;throw err;;
The plugin accepts an options object with the following properties:
connectionStringdatabase connection string or function that returns the connection string and accepts the incoming request as an argument.
attach- a string representing the extension point event that attaches the pg connection to the request. Default is
detach- a string representing the extension point event where connection cleanup is performed. Default is