Skip to content

Commit

Permalink
Update Sendam using Sequelize (As ORM) and Mysql2 as Database
Browse files Browse the repository at this point in the history
  • Loading branch information
Ejiro-Edwin committed Aug 19, 2019
1 parent 8320c2a commit ef4c0d3
Show file tree
Hide file tree
Showing 17 changed files with 898 additions and 270 deletions.
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var path = require('path');

module.exports = {
'config': path.resolve('./', 'server/config/config.js'),
'migrations-path': path.resolve('./', 'server/migrations'),
'seeders-path': path.resolve('./', 'server/seeders'),
'models-path': path.resolve('./', 'server/models')
};
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Send-IT
# Send-AM
SendAM is a courier service that helps users deliver parcels to different destinations. SendIT provides courier quotes based on weight categories.

## Feature
Expand Down
21 changes: 4 additions & 17 deletions Server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,23 @@ const bodyParser = require('body-parser');
const path = require('path');
const cors = require('cors');
const mysql=require('mysql');
const db = require('./config/db');

// const swagger = require("swagger-ui-express");
// import swaggerDocument from "../swagger.js";

let app = express();

const db = mysql.createConnection ({
host: 'localhost',
user: 'root',
password: '',
database: 'sendam'
});

// connect to database
db.connect((err) => {
if (err) {
throw err;
}
console.log('Connected to new database');
});
global.db = db;


const parcelRoute = require('./routes/parcels');
const userRoute = require('./routes/users');
const authRoute = require('./routes/auth');

app.set('views', path.join(__dirname, 'views'));

app.use(bodyParser.urlencoded({ extended: false }))
// app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));


app.use(
Expand Down
22 changes: 22 additions & 0 deletions Server/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
development: {
host: '127.0.0.1',
database: 'SendIt',
dialect: 'mysql',
username: 'root',
password: '',
port: 3306
},
production: {
url: process.env.DATABASE_URL,
dialect: 'mysql'
},
staging: {
url: process.env.DATABASE_URL,
dialect: 'mysql'
},
test: {
url: process.env.DATABASE_URL || '',
dialect: 'mysql'
}
};
33 changes: 17 additions & 16 deletions Server/config/db.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// const mysql=require('mysql');
const Sequelize = require('sequelize')
const db = {}
const sequelize = new Sequelize('sendit', 'root', '', {
host: 'localhost',
dialect: 'mysql',
operatorsAliases: false,

// const connection=mysql.createConnection({
// host:process.env.HOST,
// user:process.env.USER,
// password:'',
// database:process.env.DATABASE
// });
// connection.connect(function(error){
// if(!!error){
// console.log(error);
// }else{
// console.log('Database Connected!:)');
// }
// });
// global.connection = connection;
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
})

// module.exports = connection;
db.sequelize = sequelize
db.Sequelize = Sequelize

module.exports = db
Loading

0 comments on commit ef4c0d3

Please sign in to comment.