-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
26 lines (22 loc) · 870 Bytes
/
index.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
import sequelize from './db.js'; // Import the Sequelize connection
import Student from './student.js'; // Import the Student model
const main = async () => {
try {
// Test the connection
await sequelize.authenticate();
console.log('Database connected successfully.');
// Sync the database (creates tables if they don't exist)
await sequelize.sync({ force: false });
console.log('Database synced.');
// Example: Create a new student
const newStudent = await Student.create({ name: 'John Doe', age: 18, class: '12-A' });
console.log('New student created:', newStudent.toJSON());
} catch (error) {
console.error('Error connecting to the database:', error);
} finally {
// Close the connection
await sequelize.close();
}
};
// Run the main function
main();