Skip to content

Instantly share code, notes, and snippets.

@brianc
Forked from iToto/users.js
Created November 6, 2012 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianc/4022262 to your computer and use it in GitHub Desktop.
Save brianc/4022262 to your computer and use it in GitHub Desktop.
Get all users
/**
+ \brief readUsers
+
+ This function will return all user objects to the client
+
+ \author Salvatore D'Agostino
+ \date 2012-11-05 20:47
+ \param response The response to return to the client
+ \param client (PSQL) PSQL client object
+
+ \return JSON ARRAY of all user objects, False otherwise
**/
function readUsers(response,client)
{
console.log('Getting all users');
var query, result;
query = client.query({
name: 'read users',
text: "SELECT * from users"
});
// return the user retrieved
query.on('row', function(row,result) {
result.addRow(row);
});
query.on('end', function() {
console.dir(result);
var json = JSON.stringify(result);
console.log(json);
response.writeHead(200, {'content-type':'application/json', 'content-length':json.length});
response.end(json);
});
}// END function readUsers
exports.readUsers = readUsers;
@iToto
Copy link

iToto commented Nov 6, 2012

didn't work :(
Here's what I get:

Getting all users

undefined
undefined
user.js:33
eHead(200, {'content-type':'application/json', 'content-length':json.length});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment