https://github.com/ihoro/rough-rx-pg
Rough implementation of rxified wrapper of node-postgres lib
https://github.com/ihoro/rough-rx-pg
javascript nodejs postgres reactive-extensions rxjs sql wrapper
Last synced: 12 months ago
JSON representation
Rough implementation of rxified wrapper of node-postgres lib
- Host: GitHub
- URL: https://github.com/ihoro/rough-rx-pg
- Owner: ihoro
- License: mit
- Created: 2019-01-17T23:55:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-02T08:36:58.000Z (almost 5 years ago)
- Last Synced: 2024-12-16T21:35:34.986Z (over 1 year ago)
- Topics: javascript, nodejs, postgres, reactive-extensions, rxjs, sql, wrapper
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rx'ified node-postgres (pg)
[](https://travis-ci.com/ihoro/rough-rx-pg)
[](https://badge.fury.io/js/%40rough%2Frx-pg)
Rough implementation of [rxified](https://npmjs.com/rxjs) wrapper of [node-postgres](https://npmjs.com/pg) lib.
## Getting started
Installation
```
$ npm i pg @rough/rx-pg
```
A simple query
```js
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
```js
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));
```