1.2.1 • Published 6 years ago

pg-doc-store v1.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

pg-doc-store

Purpose and features

Opionated solution for storing documents as entities in postgres without an ORM-solution. This package aims to use postgres as a document store (storing json data as documents) but with the benefits of Postgres as a platform and with the occasional use of SQL features such as referential integrity between identifiers.

Examples

Store a document

const db = require("pg-doc-store").crud;

const id = "12903821";
const type = "person";
const person = {
  name: "J Doe"
};

db.upsert(id, type, person, (dbErr, entity) => {
  if (dbErr) return dbErr;
  // entity.id will contain id, will be created with uuid.v4() if not set
});

Load a document

const db = require("pg-doc-store").crud;
const id = "12903821";

db.load(id, (dbErr, entity) => {
  if (dbErr) return dbErr;
  // entity will contain id, type, version and attributes
});

Versions

All updates uses upsert and stores updates to an existing entity as a new version in the entity_version table. The entity table contains a reference to the latest version. Attributes are stored in the entity_version table, i.e. the attributes column contains a specific version of the JSON document.

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago