【问题标题】:What is the correct way to execute a custom query with NestJS?使用 NestJS 执行自定义查询的正确方法是什么?
【发布时间】:2021-04-11 23:35:33
【问题描述】:

我刚刚开始使用 NestJS。我在这里遵循了 sequelize 数据库示例https://docs.nestjs.com/recipes/sql-sequelize。这在使用模型时很棒,但是执行与此类似的自定义查询的 NestJS 方法是什么。

res = await this.sequelize.query(
      `
     select * from my_table where id=$id
      `,
      {
        bind: {
          id: id,
        },
        type: QueryTypes.SELECT,
        transaction,
      },

【问题讨论】:

    标签: sql postgresql sequelize.js nestjs


    【解决方案1】:

    你有 Sequelize 连接实例作为提供者,所以你可以尝试这样的事情:

    return this.catsRepository.query('select * from my_table where id=$id',
       {
         bind: {
           id: id,
         },
         type: QueryTypes.SELECT,
         transaction,
      });
    

    【讨论】:

      猜你喜欢
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多