A PostgreSQL plugin for HAPI, with a convenient key/val store abstraction layer.
Config
const defaultOptions = connectionName: 'default' url: 'postgresql://localhost' connection: ssl: true max: 10 min: 4 idleTimeoutMillis: 30000 ;
Native bindings
hapi-piggy
will use the native pg bindings if you have them installed as a peer.
Usage
This module exposes several server methods intended to make working with PostgreSQL a little easier for certain general use cases. It provides a key/val store-like abstraction layer, with a simplistic indexing model, and JSONB payloads.
/* Register server, config module... */const uuid = ;const createConnection createStore get upsert = servermethodspiggy; ;
Watching
You can easily set up a table that pushes notifications to a worker with the createWatchedTable
or createStore
with the watch
boolean true
and watchTable
methods.
Watching a store looks like this:
const createConnection createStore watchTable set = servermethodspiggy; const watcher = { // do something with parsed payload // {key: 'foo'}}; ;
Methods
There are many, take a look at index.js.
Requirements
- hapi >= 17.0.0
- node.js >= 8.0
- PostgresQL >= 9.4 (tested with 9.6)
Todo
- Tests for this plugin (libpiggy will be tested alone)