AI-Tennis-Coach/server/loaders/db/index.js
2025-02-11 11:23:59 +05:30

24 lines
784 B
JavaScript
Executable file

import { Sequelize, DataTypes } from 'sequelize';
import { privateKey } from '../../config/privateKeys.js'; // Make sure your DB string is stored here
// Create a new Sequelize instance with the PostgreSQL connection string
const sequelize = new Sequelize(privateKey.DB_STRING_DEV, {
dialect: 'postgres', // The database dialect
logging: false, // Disable logging (optional)
});
// Test the connection to ensure it's working
const connectDb = async () => {
try {
await sequelize.authenticate();
console.log('Database connection established');
} catch (err) {
console.error('Error connecting to the database:', err);
}
};
connectDb();
// Export the Sequelize instance to use in other parts of the application
export { sequelize };