Skip to content

Instantly share code, notes, and snippets.

@danrasmuson
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save danrasmuson/7a98a563ab053e79dcc1 to your computer and use it in GitHub Desktop.

Select an option

Save danrasmuson/7a98a563ab053e79dcc1 to your computer and use it in GitHub Desktop.
// conneect to database
heroku addons:add heroku-postgresql:dev
// add dependcy
"dependencies": {
"pg": "2.x",
"express": "~4.9.x",
"cool-ascii-faces": "~1.3.x"
}
// add to your app
var pg = require('pg');
app.get('/db', function (request, response) {
pg.connect(process.env.DATABASE_URL, function(err, client, done) {
client.query('SELECT * FROM test_table', function(err, result) {
done();
if (err)
{ console.error(err); response.send("Error " + err); }
else
{ response.send(result.rows); }
});
});
})
// make a sample database base in console
heroku pg:psql
psql (9.3.2, server 9.3.3)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.
=> create table test_table (id integer, name text);
CREATE TABLE
=> insert into test_table values (1, 'hello database');
INSERT 0 1
=> \q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment