Skip to content

Instantly share code, notes, and snippets.

@booo
Created November 19, 2012 21:06
Show Gist options
  • Select an option

  • Save booo/4113898 to your computer and use it in GitHub Desktop.

Select an option

Save booo/4113898 to your computer and use it in GitHub Desktop.
pg = require "./"
utils = require "./lib/utils"
utils.prepareValue = (val) ->
if val instanceof Date then return JSON.stringify val
if typeof val is 'undefined' then return null
if val instanceof Array then return "{#{val.join ", "}}"
val is null ? null : val.toString()
pg.connect "pg://postgres:testing@localhost/postgres", (error, connection) ->
if error
console.error error
else
callback = (error, result) ->
if error then console.error error
else console.log result.rows
connection.query "CREATE TEMP TABLE foo (a integer[])", callback
connection.query "INSERT INTO foo (a) VALUES ($1)", [[1,2,3]], callback
connection.query "SELECT * FROM foo", [], callback
pg.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment