2.2.0 • Published 8 years ago

livedb-postgresql v2.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

livedb-postgresql

This is a PostgreSQL adapter for livedb. It does not yet implement the livedb query interface.

Install

npm install --save livedb-postgresql

Schema

Requirements

livedb-postgresql has relatively relaxed requirements for the database it connects to. The table names can be anything, because they're set when creating an instance of livedb-postgresql.

The column names are also configuration, see the inline documentation for examples.

Snapshots Table

Column NameType
collectiontext
nametext
datajson

Operations Table

Column NameType
collection_nametext
document_nametext
versionbigint
datajson

Example

Here is an example SQL statement that will work with livedb-postgresql:

CREATE TABLE documents(
  collection_name text NOT NULL,
  name text NOT NULL,
  data json NOT NULL
);

CREATE UNIQUE INDEX documents_collection_name ON documents(collection_name, name);

CREATE TABLE operations(
  collection_name text NOT NULL,
  document_name text NOT NULL,
  version bigint NOT NULL,
  data json NOT NULL
);

CREATE UNIQUE INDEX operations_cname_docname_version ON operations(collection_name, document_name, version);

Usage

var LivePg = require('livedb-postgresql');
var livedb = require('livedb');
var redis  = require('redis');

// Redis clients
var redisURL  = require('url').parse(process.env.REDIS_URL);
var redisPass = redisURL.auth.split(':')[1];
var redis1    = redis.createClient(redisURL.port, redisURL.hostname, { auth_pass: redisPass });
var redis2    = redis.createClient(redisURL.port, redisURL.hostname, { auth_pass: redisPass });

// Postgres clients
var connString = process.env.DATABASE_URL;
var snapshotDb = new LivePg.Snapshots({ conn: connString, table: 'documents' });
var opLog      = new LivePg.OpLog({ conn: connString, table: 'operations' });

var driver     = livedb.redisDriver(opLog, redis1, redis2);
var liveClient = livedb.client({ snapshotDb: snapshotDb, driver: driver });

Testing

After creating database tables:

PG_URL=postgres://localhost:5432/livedb-postgresql_test npm test
2.2.0

8 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago