Last active
August 29, 2015 14:08
-
-
Save danrasmuson/7a98a563ab053e79dcc1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 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