Skip to content
Permalink
Browse files

Create database.json file and Return tasks API call

May end up deleting databas.json
  • Loading branch information...
kevinsuh
kevinsuh committed Jun 10, 2016
1 parent f82f73f commit e1cd97a485ebe32e7b4c15a92bec19bcd45cb653
Showing with 61 additions and 0 deletions.
  1. +28 −0 database.json
  2. +33 −0 src/app/api/v1/tasks.js
@@ -0,0 +1,28 @@
{
"dev": {
"driver": "sqlite3",
"filename": "~/dev.db"
},

"test": {
"driver": "sqlite3",
"filename": ":memory:"
},

"prod": {
"driver": "pg",
"user": {"ENV": "PRODUCTION_USERNAME"},
"password": {"ENV": "PRODUCTION_PASSWORD"}
},

"pg": {
"driver": "pg",
"user": "test",
"password": "test",
"host": "localhost",
"database": "mydb",
"schema": "my_schema"
},

"other": "postgres://uname:pw@server.com/dbname"
}
@@ -15,6 +15,20 @@ import { controller } from '../../../bot/controllers';

// index
router.get('/', (req, res) => {

// make connect for call
pg.connect(dbConnectionString, (err, client, done) => {

if (err) {
done();
console.log(err);
return res.status(500).json({ success: false, data: err});
}

return returnTasks(client, res);

})

});

// create
@@ -82,5 +96,24 @@ router.put('/:id', (req, res) => {
router.delete('/:id', (req, res) => {
});;

var returnTasks = (client, res) => {

var results = [];

// make SQL call
var query = client.query("SELECT * FROM tasks ORDER by id ASC");

// read in data through buffer
query.on('row', (row) => {
results.push(row);
})

// return in JSON format when done
query.on('end', ()=> {
return res.json(results);
});

}


export default router;

0 comments on commit e1cd97a

Please sign in to comment.
You can’t perform that action at this time.