nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

WHERE clause doesnt work for mariadb #696

Open Duckybee opened 3 years ago

Duckybee commented 3 years ago

Hello, So i are facing an issue today with nestjs/crud version after May 7 for our MariaDB. The query being generated after May 7 has this format:

SELECT .... 

FROM `watchlist` `WatchSubcription` 

WHERE ("WatchSubcription"."subscriberEmail" = 'my@email.com') 

The query we had before is:

SELECT .... 

FROM `watchlist` `WatchSubcription` 
WHERE `WatchSubcription`.`subscriberEmail` = 'my@email.com'

We are running MaridDB version 10.3

I believe this is the changes that introduce that issue https://github.com/nestjsx/crud/commit/4a85b242221efa2e4f55afe876fb51aa76e4e346

protected getFieldWithAlias(field: string, sort: boolean = false) {
    /* istanbul ignore next */
    const i = this.dbName === 'mysql' ? '`' : '"';

In file: packages/crud-typeorm/src/typeorm-crud.service.ts

sgClaudia98 commented 2 years ago

Hello, I found the same issue, but requests showing this error

ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '."preferido" = true)

I ran the sql in my database manager and got the same, but when changing the sql to `preferido`=true the request finish as expected.

The problen got fixed in the same line you are pointing

const i = this.dbName === 'mysql' ? '`' : '"';

But got fixed if set like this

const i = ['mysql','mariadb'].includes(this.dbName) ? '`' : '"';