All Projects → haoliangyu → pg-reactive

haoliangyu / pg-reactive

Licence: MIT license
PostgreSQL + RxJS = pg-reactive

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to pg-reactive

Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (+239.47%)
Mutual labels:  reactivex, rxjs
Rxjs In Action
Code sample repository
Stars: ✭ 117 (+207.89%)
Mutual labels:  reactivex, rxjs
Awesome Rxjs
A collection of awesome RxJS resources
Stars: ✭ 314 (+726.32%)
Mutual labels:  reactivex, rxjs
Awesome Reactive Programming
A repository for sharing all the resources available on Reactive Programming and Reactive Systems
Stars: ✭ 163 (+328.95%)
Mutual labels:  reactivex, rxjs
streamkit
My streaming overlay platform for YouTube https://bit.ly/3AvaoFz and Twitch https://bit.ly/37xUPAM
Stars: ✭ 15 (-60.53%)
Mutual labels:  rxjs
bassdrum
reactive, type safe components with preact and rxjs.
Stars: ✭ 44 (+15.79%)
Mutual labels:  rxjs
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-50%)
Mutual labels:  rxjs
redrock
Typesafe, reactive redux
Stars: ✭ 14 (-63.16%)
Mutual labels:  rxjs
purescript-outwatch
A functional and reactive UI framework based on Rx and VirtualDom
Stars: ✭ 33 (-13.16%)
Mutual labels:  reactivex
rx-stomp
STOMP adaptor for RxJS
Stars: ✭ 76 (+100%)
Mutual labels:  rxjs
proc-that
proc(ess)-that - easy extendable ETL tool for Node.js. Written in TypeScript.
Stars: ✭ 25 (-34.21%)
Mutual labels:  rxjs
ngx-tree
A derived version of angular-tree-component without mobx, better performance.
Stars: ✭ 13 (-65.79%)
Mutual labels:  rxjs
observable-input
angular input properties as observable streams
Stars: ✭ 49 (+28.95%)
Mutual labels:  rxjs
ngx-mobx
Mobx decorators for Angular Applications
Stars: ✭ 14 (-63.16%)
Mutual labels:  rxjs
reactorx
mv core to https://github.com/querycap/webappkit
Stars: ✭ 16 (-57.89%)
Mutual labels:  rxjs
rx-query
timdeschryver.github.io/rx-query/
Stars: ✭ 195 (+413.16%)
Mutual labels:  rxjs
rx
Reactive Extensions for D Programming Language
Stars: ✭ 52 (+36.84%)
Mutual labels:  reactivex
spellbook
Spellbook is a bookmark extension for Chrome and Firefox
Stars: ✭ 19 (-50%)
Mutual labels:  rxjs
cookbook
VueJS + NodeJS Evergreen Cookbook
Stars: ✭ 440 (+1057.89%)
Mutual labels:  rxjs
rx react native starter kit
React Native/redux/observable/auth starter kit which include immutable, rxjs, auth0 integration
Stars: ✭ 20 (-47.37%)
Mutual labels:  rxjs

pg-reactive

npm Build Status

ReactiveX

RxJS interface for PostgreSQL in node.js

Installation

npm install pg-reactive

If you are using RxJS v5, install a previous version:

npm install pg-reactive@^0.3.5

Example

import PgRx from 'pg-reactive';
import { map } from "rxjs/operators";

const db = new PgRx('postgres://postgres@$localhost/tester');

db.query('SELECT id FROM user')
  .pipe(
    map((row) => row.id)
  )
  .subscribe((id) => {
    console.log('ID: ', id);
  });

Documentation

TypeScript

pg-reactive is shipped with its type declaration file and it can be used in a TypeScript directly.

How it works?

Before using this library or reading its source code, you should know Reactive Programming & RxJS.

pg-reactive wraps the low-level pg APIs and exposes a RxJS-compatible interface. The work of pg-reactive includes the following three aspects.

Deferred Query

Unlike Promise as the final state of an asynchronous action, Observable works as a data source of asynchronous actions. When providing a observable-based API, pg-reactive cools down the original pg functions by deferring their execution using Rx.Observable.defer().

In this way, the data stream is controllable with subscribe() / unsubscribe() without worrying data leak. The data stream is generated using the row, error, end event of the query object of pg, which ensures the query result is emitted by rows.

Transaction as an Observable

The tx() function of pg-reactive accepts a callback function where the user is able to organization the data flow within a transaction, which may includes different database operations. The data flow behind this function is actually query('BEGIN') -> query('Your Command') -> query('COMMIT') and a query('ROLLBACK') will be executed in cause of any error.

Note that unlike the query observable, the tx observable doesn't emit data until the query is completely done. Therefore, the tx observable guarantees to emit nothing if error happens.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].