Git Product home page Git Product logo

livedb-postgresql's Introduction

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 snapshotDb = new LivePg(connString, 'documents');  // "documents" is a table
var opLog      = new LivePg(connString, '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

livedb-postgresql's People

Contributors

jclem avatar

Watchers

Simon Butler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.