Skip to content

Instantly share code, notes, and snippets.

@yeyuguo
Forked from evantahler/bad.js
Created April 8, 2017 09:04
Show Gist options
  • Save yeyuguo/a47430687fd4fe5cb68b98781d0294ad to your computer and use it in GitHub Desktop.
Save yeyuguo/a47430687fd4fe5cb68b98781d0294ad to your computer and use it in GitHub Desktop.
pg-action.js
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();
});
});
}
};
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