Last active
August 29, 2015 14:07
-
-
Save fxg42/90c814a737d3713242f9 to your computer and use it in GitHub Desktop.
Postgresql + Highland
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _ = require 'highland' | |
| pg = require 'pg' | |
| QueryStream = require 'pg-query-stream' | |
| CONNECTION_STRING = "postgres://postgres:postgres@localhost/contacts" | |
| rows = (stmt, params=[]) -> | |
| (push, next) -> | |
| pg.connect CONNECTION_STRING, (err, client, done) -> | |
| push err if (err) | |
| stream = client.query(new QueryStream(stmt, params)) | |
| stream.on 'end', done | |
| next _(stream) | |
| push null, _.nil | |
| _ rows 'select * from contact' | |
| .errors (err, push, next) -> console.log "ERR: #{err}" | |
| .filter (row) -> row.id > 14 | |
| .toArray (arr) -> console.log arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment