@varasto/postgres-storage
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@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:

Property Default value Description
dropEmptyTables false If true, once an namespace is detected to be empty, it's associated table is automatically dropped.

Readme

Keywords

Package Sidebar

Install

npm i @varasto/postgres-storage

Weekly Downloads

0

Version

3.0.0

License

MIT

Unpacked Size

15.9 kB

Total Files

12

Last publish

Collaborators

  • rauli