typeorm: LessThan and other operators doesn't work

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I’m using typeorm inside js and it seems like the query parsed incorrectly, here is my example:

const entities = await Entity.count({
      where: {
        name: 'entityName',
        updatedAt: LessThan(new Date()),
      },
    });

And here is the sql output:

SELECT COUNT(DISTINCT("Entity"."id")) as "cnt" FROM "entities" "Entity" WHERE "Entity"."name" = $1 AND "Entity"."updatedAt" = $2 AND "Entity"."deletedAt" IS NULL -- PARAMETERS: ["entityName",{"_type":"lessThan","_value":"2019-04-08T12:11:05.602Z","_useParameter":true,"_multipleParameters":false}]

It’s working great within Nest.js framework but doesn’t work inside a pure node.js file.

Another thing to mention - Methods works just fine like: Entity.find() Entity.count() etc … So I don’t think it’s something with the db connection

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 18 (4 by maintainers)

Most upvoted comments

I am experiencing the same problem with postgres:

await XXX.findOne({ id: Not(Equal(x.id)), name: x.name }))

Produces an error:

QueryFailedError: invalid input syntax for integer: "{"type":"not","_useParameter":true,"_multipleParameters":false,"_value":{"type":"equal","_useParameter":true,"_multipleParameters":false,"_value":1}}"

@Kononnable I logged the SQL query and it seems that LessThan stays an object, for example:

where: {
  updatedAt: LessThan(new Date()),
}

Will be:

UPDATE ... updatedAt = { _value: .. ...... }

instead

UPDATE ... updatedAt < new Date()

It seems that it didn’t work as a local npm installed package but when I deployed it and installed the package from github, it worked.

I believe it is something about the shared typeorm package and the connection itself, but it did worked partly in the local way…

I have the same issue, LessThan does not work with date for me

any updates?

I have the same issue with Like and other operators, the query doesn’t change the operator and the parameters contain a JSON structure.