Search code examples
node.jsnestjstypeorm

Typeorm's Raw() , Between() not working in Find method


if i use normally Raw() function in Find()'s options is work, but if i write Raw() in another function then call in Find()'s options does not work

..
import {Raw} from 'typeorm'

-the state which it works:

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

-the state which it does not works:

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(),
    }
});

Solution

  • simply ,you should use where out of find method like this:

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