Skip to content

Commit cdb6fc4

Browse files
committed
non-hacky
1 parent 865613c commit cdb6fc4

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

Diff for: app.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
const inquirer = require('inquirer');
2+
//connection available to all
3+
const connection = require('./connection');
24

35
const app = {};
46

5-
app.initialize = (connection) => {
6-
//makes connection assessible to the rest of the app
7-
app.connection = connection;
8-
app.startQuestion(() => {
9-
app.connection.end();
10-
})
11-
12-
}
13-
147
app.startQuestion = (closeConnectionCallback) => {
15-
168
inquirer.prompt({
179
type: 'list',
1810
message: 'What action would you like to do?',

Diff for: connection.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//require packages
2+
const mysql = require("mysql");
3+
const mySqlKey = require('./keys').mySql;
4+
5+
//create MySQL connection
6+
const connection = mysql.createConnection({
7+
host: "localhost",
8+
port: 3306,
9+
user: "root",
10+
password: mySqlKey,
11+
database: "eventonica"
12+
});
13+
14+
module.exports = connection;

Diff for: index.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
//require packages
2-
const mysql = require("mysql");
3-
const mySqlKey = require('./keys').mySql;
4-
const app = require('./app')
5-
6-
//create MySQL connection
7-
const connection = mysql.createConnection({
8-
host: "localhost",
9-
port: 3306,
10-
user: "root",
11-
password: mySqlKey,
12-
database: "eventonica"
13-
});
1+
const connection = require('./connection');
2+
const app = require('./app');
143

154
const mySqlConnect = () => {
165
connection.connect((err) =>{
@@ -19,7 +8,7 @@ const mySqlConnect = () => {
198
console.log('Welcome to Eventonica')
209
console.log("connected as Administrator");
2110

22-
app.initialize(connection);
11+
app.startQuestion(()=>{ connection.end() });
2312
})
2413
}
2514

0 commit comments

Comments
 (0)