分享 推播通知
目前身份: 訪客

定義好連線參數後,要進行連線測試,你可以用 .authenticate() 來測試

可以用await的方法 

try {
  await sequelize.authenticate();
  console.log('連線成功.');
} catch (error) {
  console.error('連線失敗:', error);
}

 

用then的寫法

sequelize
  .authenticate()
  .then(() => {
    console.log('Connection has been established successfully.');
  })
  .catch(err => {
    console.error('Unable to connect to the database:', err);
  });

 

用Promise的寫法

return new Promise(function(resolve, reject){
  Models.sequelize.authenticate().then(function(err) {
    return resolve(true);
  }, function(err){
    return reject(err);
  });
});

 

人氣 2377
程式設計 發表在 留言 (0) 人氣 (2377)
第01章 入門初階
分享給朋友
網址

想對外分享這則貼文嗎?運用網址更方便呦~

台灣 一週天氣
OnceHit© 2024
載入中...