Registry / database / sharedb-postgres

sharedb-postgres

JSON →
library5.0.1jsnpmunverified

PostgreSQL database adapter for ShareDB that can be used as both a snapshot store and oplog. Current stable version is 5.0.1. This adapter requires PostgreSQL 9.5+ due to jsonb support for high concurrency. It wraps node-postgres and supports the same configuration options via environment variables or connection object. Unlike the deprecated sharedb-mongo, this adapter is specifically for PostgreSQL environments. Note that queries are not yet supported. The project is moderately experimental but used in production by Synaptograph.

npm install sharedb-postgres
INSTALL
IMPORT
SIG · SHAREDB-POSTGRES
S
sharedb-postgres
databasejavascriptv5.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import db from 'sharedb-postgres';
const db = require('sharedb-postgres').default;
Module uses CommonJS, default export is a function. ESM import works as above.
default (CommonJS)
const db = require('sharedb-postgres');
CommonJS require works directly; no .default needed.
createPostgresDB(options)
import createPostgresDB from 'sharedb-postgres'; const db = createPostgresDB({host: 'localhost'});
const { createPostgresDB } = require('sharedb-postgres');
Default export is the factory function; named export does not exist.

Creates a ShareDB backend using the PostgreSQL adapter with environment variable configuration, then closes cleanly.

import ShareDB from 'sharedb'; import createPostgresDB from 'sharedb-postgres'; const db = createPostgresDB({ host: process.env.PGHOST || 'localhost', database: process.env.PGDATABASE || 'mydb', user: process.env.PGUSER || 'postgres', password: process.env.PGPASSWORD || '', port: parseInt(process.env.PGPORT || '5432') }); const backend = new ShareDB({db}); backend.close();
Debug
Known issues
gotchaQueries are not supported. The adapter only provides snapshot store and oplog functionality.
fix
Use a separate query mechanism (e.g., direct SQL via node-postgres) for custom queries.
affects: *
breakingVersion 3.0.0 changed how connection parameters are specified. Old API no longer works.
fix
Upgrade configuration to use environment variables or connection object as shown in the README.
affects: <3.0.0
gotchaPostgreSQL 9.5+ required due to jsonb data type usage for high concurrency.
fix
Upgrade PostgreSQL to version 9.5 or higher.
affects: *
breakingIf upgrading from an older version that used json data type, you must migrate columns to jsonb.
fix
Run ALTER TABLE statements to change data type from json to jsonb as documented in README.
affects: *
gotchaConnection via environment variables is only supported when no object argument is passed.
fix
To use environment variables, call createPostgresDB() with no arguments.
affects: *
Errors
Common errors & fixes
Error: pg client is not a function
Missing or outdated pg dependency or incorrect import
fix
Ensure pg is installed: npm install pg@^8
Cannot find module 'sharedb-postgres'
Package not installed in node_modules
fix
Run npm install sharedb-postgres
TypeError: require(...) is not a function
Calling require('sharedb-postgres') without invoking the returned function
fix
Use const db = require('sharedb-postgres')(); or pass config object
error: operator does not exist: jsonb = text
Trying to query with incompatible data types
fix
Use proper PostgreSQL casting or avoid queries (adapter doesn't support queries)
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies
pgrequiredpeer dependency for PostgreSQL connectivity; version ^8.x recommended
sharedbrequiredpeer dependency for ShareDB server
Agent activity
10 hits · last 30 days
node
8
Meta
2
Resources
sharedb-postgres — npm install sharedb-postgres · libregistry