Skip to content

Commit

Permalink
made some changes, now using a promise based mysql library, importing…
Browse files Browse the repository at this point in the history
… the dotenv files the es7 way where I can.
  • Loading branch information
johndatserakis committed Jul 19, 2017
1 parent 1ec799f commit 98f855f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 198 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

require('dotenv').config();

const env = process.env.NODE_ENV || 'development';
const port = process.env.PORT || 4000;
const src = env === 'production' ? './build/app' : './src/app';
Expand Down
51 changes: 8 additions & 43 deletions models/Message.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
// var method = Message.prototype;

// function Message(age) {
// this._age = age;
// }

// method.getAge = function() {
// return this._age;
// };

// module.exports = Message;
import pool from '../src/db';

class Message {
constructor() {}

getAllMessages() {
var data = [
{
'id': 1,
'title': 'Here is the first title',
'content': 'Here is the first content.',
'approved': 0
},
{
'id': 2,
'title': 'Here is the second title',
'content': 'Here is the second content.',
'approved': 1
},
];

// var data = {
// 'messages': [
// {
// 'title': 'Here is the first title',
// 'content': 'Here is the first content.'
// },
// {
// 'title': 'Here is the second title',
// 'content': 'Here is the second content.'
// },
// ]
// }



return data;
async getAllMessages() {
try {
let messages = await pool.query('select * from test_table');
return messages;
} catch (err) {
throw new Error('Internal Server Error');
}
}
}

Expand Down
156 changes: 38 additions & 118 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
"test": "npm run build; mocha --require 'babel-polyfill' --compilers js:babel-register",
"build": "babel src -d build"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/OrKoN/koa2-example-app.git"
},
"keywords": [
"data",
"node"
],
"license": "MIT",
"homepage": "https://github.com/OrKoN/koa2-example-app#readme",
"dependencies": {
Expand All @@ -28,8 +20,8 @@
"koa": "^2.0.0-alpha.3",
"koa-bodyparser": "^3.0.0",
"koa-router": "^7.0.1",
"mysql2": "^1.2.0",
"objection": "^0.8.4",
"promise-mysql": "^3.0.2",
"promise-redis": "0.0.5",
"redis": "^2.4.2"
},
Expand Down
Loading

0 comments on commit 98f855f

Please sign in to comment.