【问题标题】:TypeORM find where clause, how to add where in multiple parameterTypeORM查找where子句,如何在多个参数中添加where
【发布时间】:2020-10-27 11:30:16
【问题描述】:
this.sampleRepo.find (
            {
                where: {
                    id: In ["1","7","13"]

                  }
                order: {
                    id: "DESC"
                },
                select: ['id','group']
                
                
            }

    );

如何在此处添加 where 子句,以便我只能找到用户 ID 为 1 或 7 或 13 的记录。

【问题讨论】:

    标签: mysql node.js typeorm


    【解决方案1】:

    您错过了圆括号,并且可能错过了导入 In 运算符:

    import { In } from 'typeorm';
    
    ...
    ...
    ...
    
    this.sampleRepo.find({
        where: {
          id: In(['1', '7', '13'])
        },
        order: {
          id: 'DESC'
        },
        select: ['id', 'group']
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多