anyone can post an RXJS example using node.js for querying postgresql db?
google doesn't seem to have anything about this...
regards
Sean.
voilà!
var Rx = require('rx');
var pg = require('pg');
var rowObservable = Rx.Observable.create(function(observer) {
var pgClient = new pg.Client();
pgClient.connect();
var pgQuery = pgClient.query("SELECT * FROM information_schema.tables;");
pgQuery.on('error', observer.onError.bind(observer));
pgQuery.on('row', observer.onNext.bind(observer));
pgQuery.on('end', observer.onCompleted.bind(observer));
return pgClient.end.bind(pgClient);
});
var subscription = rowObservable.subscribe(function(row) {
console.log(row);
}, function(err) {
console.error(err);
}, function() {
subscription.dispose();
});
In this example, the client connection pgClient is closed when the subscription is disposed. The rest is pretty self explanatory i think :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With