From 2d8c8d51680fcf550cd6692dc65395eb1536e658 Mon Sep 17 00:00:00 2001 From: brianc Date: Thu, 26 May 2011 12:25:19 -0700 Subject: [PATCH] Updated FAQ (markdown) --- FAQ.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/FAQ.md b/FAQ.md index c9e5fa2..a69394c 100644 --- a/FAQ.md +++ b/FAQ.md @@ -30,7 +30,17 @@ client.query(..., function(err, result) { ### 4. (Alert! Possibly an idiot question) How do you get the count of columns in the result set ? ### -### 5. (Alert! Possibly an idiot question) If pg returns query data in JSON format, for web serivce applications, it would make sense to return that directly to the client. If this assumption is correct what is the most efficient method? ### - +### 5. If pg returns query data in JSON format, for web serivce applications, it would make sense to return that directly to the client. If this assumption is correct what is the most efficient method? ### +```js +http.CreateServer(function(req, res) { + //NOTE: pg connection boilerplate not present + pg.query(..., function(err, result) { + //NOTE: error handling not present + var json = JSON.stringify(result.rows); + res.writeHead(200, {'content-type':'application/json', 'content-length':json.length}); + res.end(json); + }); +}) +``` Thank you Brian. pg is excellent. \ No newline at end of file