Od najnowszej wersji Sequelize
(np. 3.3.2 ), authenticate
można użyć do sprawdzenia połączenia:
var sequelize = new Sequelize("db", "user", "pass");
sequelize.authenticate().then(function(errors) { console.log(errors) });
authenticate po prostu uruchamia SELECT 1+1 AS result zapytanie, aby sprawdzić połączenie z bazą danych.
AKTUALIZUJ :
Błędy najnowszego API
muszą być obsługiwane w catch :
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
AKTUALIZACJA 2 :
Nie testowałem tego, ale logiczne jest, że to samo można osiągnąć za pomocą async/await :
try {
await sequelize.authenticate()
} catch (err) {
console.error('Unable to connect to the database:', err)
}