3.0.0 • Published 7 months ago

@varasto/postgres-storage v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@varasto/postgres-storage

npm

Implementation of storage which stores data into PostgreSQL database. Still considered to be somewhat experimental.

The way it works is that each namespace is an table in the database, and each entry in the database is a row in that table with a key and JSON value.

Library called pg is used to communicate with the PostgreSQL server.

Installation

$ npm install --save @varasto/postgres-storage

Usage

The package provides an function called createPostgresStorage which takes an PostgreSQL client as an argument. The function then returns an storage implementation which is capable of storing JSON objects into the database, where each value is identified by namespace and key that must be valid URL slugs.

import { Client } from 'pg';
import { createPostgresStorage } from '@varasto/postgres-storage';

const client = new Client({
  user: 'dbuser',
  host: 'database.server.com',
  database: 'mydb',
  password: 'secretpassword',
  port: 3211,
});

await client.connect();

const storage = createPostgresStorage(client);

The function takes an optional configuration object, which supports these settings:

PropertyDefault valueDescription
dropEmptyTablesfalseIf true, once an namespace is detected to be empty, it's associated table is automatically dropped.
3.0.0

7 months ago

2.0.0

7 months ago

1.0.0

12 months ago