Skip to content

Instantly share code, notes, and snippets.

@fxg42
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save fxg42/90c814a737d3713242f9 to your computer and use it in GitHub Desktop.

Select an option

Save fxg42/90c814a737d3713242f9 to your computer and use it in GitHub Desktop.
Postgresql + Highland
_ = 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