8000 GitHub - riston/livedb-postgresql: A PostgreSQL adapter for livedb
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

riston/livedb-postgresql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, as they're set when creating an instance of livedb-postgresql.

Snapshots Table

Column Name Type
collection text
name text
data json

Operations Table

Column Name Type
collection_name text
document_name text
version bigint
data json

Example

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

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

CREATE UNIQUE INDEX documents_collection_name ON documents(collection, 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 poolSize = 20; // default pool size is 10
var snapshotDb = new LivePg(connString, poolSize);
var opLog      = new LivePg(connString);

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

About

A PostgreSQL adapter for livedb

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 60.2%
  • JavaScript 39.8%
0