首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在续写QueryInterface中回报承诺?

如何在续写QueryInterface中回报承诺?
EN

Stack Overflow用户
提问于 2022-07-12 01:47:41
回答 2查看 108关注 0票数 0

我很抱歉,如果这是一个天真的问题,但我是新的后遗症,我正在尝试与数据库使用QueryInterface。

代码语言:javascript
复制
module.exports = {
  up: function (queryInterface, Sequelize) {
    queryInterface.addIndex(
      'entry',
      ['create_date', 'username'],
      {
        indexName: 'create_date_username'
      }
    );

    queryInterface.addIndex(
      'entry',
      ['username'],
      {
        indexName: 'username'
      }
    );

    queryInterface.addIndex(
      'entry',
      ['source_id', 'source_type'],
      {
        indexName: 'source_id_source_type'
      }
    ) 
    .then(() =>
    Promise (
      ????
    )
  ); 
 }, 

  down: function (queryInterface, Sequelize) {
    queryInterface.removeIndex('entry', 'create_date_username');
    queryInterface.removeIndex('entry', 'username');
    queryInterface.removeIndex('entry', 'source_id_source_type');
  }
};

但我得到了一个ERROR: Migration 20112-Add-Indices.js (or wrapper) didn't return a promise.,但我是新的,不知道如何确切地回报一个承诺。有人能帮我做一下吗。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-12 02:22:16

你忘了返回声明了。试着做这样的事情:

代码语言:javascript
复制
up: function (queryInterface, Sequelize) {
    return Promise.all([
        queryInterface.addIndex(
          'entry',
          ['create_date', 'username'],
          {
            indexName: 'create_date_username'
          }
        ),
        queryInterface.addIndex(
          'entry',
          ['username'],
          {
            indexName: 'username'
          }
        ),
        queryInterface.addIndex(
          'entry',
          ['source_id', 'source_type'],
          {
            indexName: 'source_id_source_type'
          }
        )
    ])
    .then(() => ...
票数 0
EN

Stack Overflow用户

发布于 2022-07-13 12:14:11

试试看

代码语言:javascript
复制
module.exports = {
    async up(queryInterface, Sequelize) {
        await queryInterface.addIndex('entry', ['create_date', 'username'], {
            indexName: 'create_date_username'
        });

        await queryInterface.addIndex('entry', ['username'], {
            indexName: 'username'
        });

        await queryInterface.addIndex('entry', ['source_id', 'source_type'], {
            indexName: 'source_id_source_type'
        });
    },

    async down(queryInterface, Sequelize) {
        await queryInterface.removeIndex('entry', 'create_date_username');
        await queryInterface.removeIndex('entry', 'username');
        await queryInterface.removeIndex('entry', 'source_id_source_type');
    }
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72946240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档