egg-sequelize如何连多个数据库

  config.sequelize = {
    datasources: [
      {
        delegate: 'model', // load all models to app.model and ctx.model
        baseDir: 'model', // load models from `app/model/*.js`
        dialect: 'mysql',
        database: process.env.EGG_MYSQL_DATABASE || 'seq_test_staging',
        host: process.env.EGG_MYSQL_HOST || '127.0.0.1',
        port: process.env.EGG_MYSQL_PORT || '3306',
        username: process.env.EGG_MYSQL_USERNAME,
        password: process.env.EGG_MYSQL_PASSWORD,
        operatorsAliases: Op,
        pool: {
          max: 20,
          min: 0,
          idle: 10000,
        },
     },
      {
        delegate: 'testModel', // load all models to app.adminModel and ctx.adminModel
        baseDir: 'test_model', // load models from `app/admin_model/*.js`
        dialect: 'mysql',
        database: process.env.EGG_MYSQL_DATABASE || 'test',
        host: process.env.EGG_MYSQL_HOST || '127.0.0.1',
        port: process.env.EGG_MYSQL_PORT || '3306',
        username: process.env.EGG_MYSQL_USERNAME,
        password: process.env.EGG_MYSQL_PASSWORD,
        operatorsAliases: Op,
        pool: {
          max: 20,
          min: 0,
          idle: 10000,
        },
     },
    ],
  };

在配置文件里面增加即可

你可能感兴趣的:(JS,node.js)