Skip to content

Instantly share code, notes, and snippets.

@brianc
Created October 7, 2014 14:39
Show Gist options
  • Save brianc/bfd6ab86eaecc93205af to your computer and use it in GitHub Desktop.
Save brianc/bfd6ab86eaecc93205af to your computer and use it in GitHub Desktop.
var http = require('http')
var pg = require('pg')
//creating a single, global client
//will potentially cause two requests two issue queries
//interleaved within one another...
//do not do this!
var client = new Client()
client.connect()
var server = http.createServer(function(req, res) {
client.query('BEGIN', function(err) {
if(err) throw err;
client.query('DO SOMETHING', function(err) {
if(err) throw err;
client.query('COMMIT', function(err) {
if(err) throw err;
res.end('okay')
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment