-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb.js
26 lines (20 loc) · 836 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require('dotenv').config();
const Sequelize = require("sequelize");
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: 'mariadb',
define: {
timestamps: false
}
});
const db = {};
db.Sequelize = Sequelize;
db.sequelize = sequelize;
db.customers = require("./models/customer.model.js")(sequelize, Sequelize);
db.products = require("./models/product.model.js")(sequelize, Sequelize);
db.orders = require("./models/order.model.js")(sequelize, Sequelize);
db.customers.hasMany(db.orders,{ as: 'orders', foreignKey: 'customer_id' });
db.orders.belongsTo(db.products,{ as: 'product', foreignKey: 'product_id' });
db.orders.belongsTo(db.customers,{ as: 'customer', foreignKey: 'customer_id' });
module.exports = db;