-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
25 lines (22 loc) · 796 Bytes
/
database.js
File metadata and controls
25 lines (22 loc) · 796 Bytes
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
const { Sequelize } = require("sequelize");
const { createPatientModel } = require("./scripts/models/models.js");
let SchemaModel = null;
const sequelize = new Sequelize("hospitalMgmSystem", "postgres", "passwd", {
host: "localhost",
dialect: "postgres",
});
const connection = async () => {
try {
await sequelize.authenticate();
SchemaModel = await createPatientModel(sequelize); // Initialize model
console.log("SchemaModel:", SchemaModel);
// await sequelize.sync({ alter: true });
await sequelize.sync();
console.log("Connection is Successful");
console.log("Synced Database");
} catch (error) {
console.log("Unable to connect to database: ", error);
}
};
const getSchemaModel = () => SchemaModel;
module.exports = { connection, getSchemaModel };