-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query operators (Like, MoreThan) don't work if used via a 3rd party library that import TypeOrm #8579
Comments
This seem to be very similar to issue #6727 I've got similar issues in past, but I couldn't really pinpoint them to specific pattern in code. CC @imnotjames |
Yep that seems it! Given that I'm able to reproduce it 100% of the time and appears only due to the import of Typeorm via another package, I may guess that in the function that builds the query, there's some check on the Operator type but this check fails as there are 2 Operator types imported from 2 different instances of typeorm lib... just a guess |
Your library should use peer dependencies then: https://nodejs.org/es/blog/npm/peer-dependencies/ |
OK so I understood what's going on. Indeed I was already using peer dependencies, but during the development, I was linking the library package to the app package (with I ended up using https://github.com/wclr/yalc during development to avoid issues due to package linking. So, in my opinion, there are 2 options to close this issue:
|
Issue Description
I developed an NPM library to build a Typeorm find query starting from the HTTP query string (actually Koa query object...) and it works well as far as it concerns building the query object with
where
clause,take
andskip
params, etc.But when I run the query the result is wrong and actually, the generated SQL is wrong.
After some tests, I understood that the issue is due to the way I import typeorm.
On 1 side I have
my-utils-library
that imports Typeorm and implements a function to build a query.On the other side I have my HTTP app where I declare Typeorm entities, init the DB and where I also import
my-utils-library
to use thebuildTypeormQuery()
function.Now if I just move the code for
buildTypeormQuery
to the main package, the issue disappears.The same happens with several other libraries that do the same job, like https://github.com/rjlopezdev/typeorm-express-query-builder
Expected Behavior
I expect that operators just work regardless of how the library is imported.
Actual Behavior
If I run this query:
this is the executed SQL (logged by typeorm), please notice the
= $1
where it should beILIKE $1
:Steps to Reproduce
You need 2 npm packages, in 1 package run the following
In another package implement the
buildQuery()
function that returns a TypeOrm query, or use a library like https://github.com/rjlopezdev/typeorm-express-query-builderMy Environment
Additional Context
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: