1.1.0 • Published 3 years ago

@rough/rx-pg v1.1.0

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago

Rx'ified node-postgres (pg)

Build Status npm version

Rough implementation of rxified wrapper of node-postgres lib.

Getting started

Installation

$ npm i pg @rough/rx-pg

A simple query

const { finalize } = require('rxjs/operators');
const { Pool } = require('pg');
const RxPg = require('@rough/rx-pg');

const pool = new Pool({
  host: 'localhost',
  user: 'root',
  password: 'root',
  database: 'myproject',
  max: 50,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000
});

const rxpg = new RxPg(pool);

rxpg
  .query('select * from users')
  .pipe(finalize(_ => pool.end()))
  .subscribe(result => console.log(result));

A simple transaction

rxpg
  .transaction(
    (rxpg, prevResult) => rxpg.query('select * from users where id = ? for update', 42),
    (rxpg, prevResult) => rxpg.query('delete from deals where user_scope_id = ?', prevResult[0].user_scope_id),
    (rxpg, prevResult) => rxpg.query('delete from inventory where user_id = ?', 42),
  )
  .pipe(finalize(_ => pool.end()))
  .subscribe(result => console.log(result));
1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago