pgd
pgdown
npm i pgdown
pgd

pgdown

PostgreSQL backed abstract-leveldown

by ralphtheninja

0.0.0 (see all)License:MITTypeScript:Not Found
npm i pgdown
Readme

pgdown

PostgreSQL backed abstract-leveldown.

npm Node version Build Status JavaScript Style Guide

Experimental and WIP. Do not use.

Usage

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)
  })
})

Api

const PgDOWN = require('pgdown')

Constructor.

const down = PgDOWN(location)

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 from location or $PGDATABASE or 'postgres'
  • host from location or $PGHOSTADDR or 'localhost'
  • port from location or $PGPORT or 5432
  • user from location or $PGUSER or $USERNAME (win32) or $USER
  • password from location or $PGPASSWORD or null

ES6

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.

PostgreSQL

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.

License

MIT

Downloads/wk

6

GitHub Stars

19

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

3

OPEN ISSUES

1

OPEN PRs

0
VersionTagPublished
0.0.0
latest
6yrs ago
No alternatives found
No tutorials found
Add a tutorial