Last active
April 8, 2017 09:04
-
-
Save evantahler/163ca7da7a517b1c42977ee512a4347f to your computer and use it in GitHub Desktop.
pg-action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.randomRow = { | |
name: 'randomFirstName', | |
description: 'I will return a random first name from the users table', | |
outputExample: {}, | |
run: function(api, data, next){ | |
pg.connect(api.config.pg.url, function(error, client, done){ | |
if(error){ return next(error); } | |
var query = 'select * from usersorer by random() limit 1'; | |
client.query(query, function(error, results){ | |
if(error){ return next(error); } | |
data.connection.response.randomFirstName = results.rows[0].firstName; | |
done(); | |
next(); | |
}); | |
}); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.randomRow = { | |
name: 'randomFirstName', | |
description: 'I will return a random first name from the users table', | |
outputExample: {}, | |
run: function(api, data, next){ | |
pg.connect(api.config.pg.url, function(error, client, done){ | |
if(error){ | |
done(); | |
return next(error); | |
} | |
var query = 'select * from usersorer by random() limit 1'; | |
client.query(query, function(error, results){ | |
if(error){ | |
done(); | |
return next(error); | |
} | |
data.connection.response.randomFirstName = results.rows[0].firstName; | |
done(); | |
next(); | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment