【问题标题】:Typeorm's Raw() , Between() not working in Find methodTypeorm 的 Raw() ,Between() 在 Find 方法中不起作用
【发布时间】:2021-08-03 16:13:48
【问题描述】:

如果我在 Find() 的选项中正常使用 Raw() 函数是可行的,但如果我在另一个函数中编写 Raw() 则调用 Find() 的选项不起作用

..
import {Raw} from 'typeorm'

-它工作的状态:

const result = await myEntity.find({
    where: {
         issueDate:Raw(alias => `${alias} >= :start AND ${alias} < :end`, 
                        {
                         start: '2021-06-01', end: '2021-06-02' 
                        }
                   )
              
 });

-它不工作的状态:

filter() {
  return Raw(alias => `${alias} >= :start AND ${alias} < :end`, {
             start: '2021-06-01', end: '2021-06-02' });
}
const result = await myEntity.find({
    where: {
         issueDate:filter(),
    }
});

【问题讨论】:

    标签: node.js nestjs typeorm


    【解决方案1】:

    简单地说,你应该使用 where out of find 方法 像这样:

    const where={ issueDate:filter()}
    const result = await myEntity.find({where});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      相关资源
      最近更新 更多