PostgreSQL
backedabstract-leveldown
.
Experimental and WIP. Do not use.
Use together with levelup
to get a PostgreSQL
backed storage.
const levelup = require('levelup')
const PgDOWN = require('pgdown')
const uri = 'postgres://postgres:@localhost:5432/postgres'
const db = levelup(uri, {
db: PgDOWN,
keyEncoding: 'utf8',
valueEncoding: 'json'
})
db.put('foo', { bar: 'baz' }, (err) => {
db.get('foo', (err, result) => {
console.log('result %j', result)
})
})
Constructor.
Creates a PgDOWN
object with location
which can take the following forms:
postgres://<user>:<password>@<host>:<port>/<database>/<table>
/<database>/<table>
An options
object is created based on the location and passed to pg.Client
. However, pgdown
respects the default environment variables used by PostgreSQL
in favor of the ones used in pg
.
To summarize we have the following properties and their default values:
database
fromlocation
or$PGDATABASE
or'postgres'
host
fromlocation
or$PGHOSTADDR
or'localhost'
port
fromlocation
or$PGPORT
or5432
user
fromlocation
or$PGUSER
or$USERNAME
(win32) or$USER
password
fromlocation
or$PGPASSWORD
ornull
pgdown
mainly uses arrow functions and template strings from ES6 which are very useful when constructing SQL query strings. It primarily targets node 6+
but should work well with 0.10
and 0.12
together with babel-register
or babel-cli
and babel-preset-es2015
.
Note pgdown
requires at least version 9.5
of PostgreSQL
.
If you're hacking on pgdown
or just want to setup PostgreSQL
locally the easiest way is probably to use docker. We can highly recommend clkao/postgres-plv8
which is based on the official PostgreSQL
docker image but with support for plv8
.
$ docker run -d -p 5432:5432 clkao/postgres-plv8:9.5
Check out the wiki for more information.
MIT