Sequelize.js Sequelize sync方法是否在执行之前等待连接?

Sequelize.js Sequelize sync方法是否在执行之前等待连接?,sequelize.js,Sequelize.js,在测试完这段代码后,我很困惑我的表是如何创建的。调用.sync方法时,我本以为没有连接。sync()方法是否在某种程度上等待连接建立 var Sequelize = require('sequelize'); var chalk = require('chalk'); var sequelize = new Sequelize('postgres://localhost/nfldb'); sequelize.define('team', { name: Sequelize.STRING

在测试完这段代码后,我很困惑我的表是如何创建的。调用.sync方法时,我本以为没有连接。sync()方法是否在某种程度上等待连接建立

var Sequelize = require('sequelize');
var chalk = require('chalk');

var sequelize = new Sequelize('postgres://localhost/nfldb');

sequelize.define('team', {
  name: Sequelize.STRING
});

sequelize.authenticate()
  .then(function(){
    console.log(chalk.green('connected to database ' + sequelize.config.database));
  })
  .catch(function(er){
    console.log(chalk.red(er.message));
  });


sync();

function sync(){
  sequelize.sync({force: true})
    .then(function(){
      console.log(chalk.green('database has been synced'));
    })
    .catch(function(){
      console.log(chalk.red('unable to sync database'));
    });
}

是,
sync
自动请求与数据库的连接
authenticate
用于检查是否可以在不执行实际查询的情况下连接到数据库-据我所知,
SELECT 1+1
。不需要调用
authenticate
,这只是一种方便的方法。

是的,
sync
自动请求与数据库的连接
authenticate
用于检查是否可以在不执行实际查询的情况下连接到数据库-据我所知,
SELECT 1+1
。不需要调用
身份验证
,这只是一种方便的方法