-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prevent bind error with undefined/null parameters #375
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values
has type Statement.BindParams
, which is defined as Database.SqlValue[]|Object<string, Database.SqlValue>
so it cannot be undefined or null. If a library user passes undefined or null, it is an error on their side.
We can discuss changing the type Statement.BindParams
, but there should be a good reason for changing the API of the library, and the type definitions will also need to be updated, not just the code.
The code you are pointing to (https://github.com/typeorm/typeorm/blob/master/src/driver/sqljs/SqljsQueryRunner.ts#L44-L55) is clearly a bug in typeorm. |
Thank you for your response, i'm agree with you but the typeorm code works (in my case) with sql.js version 0.5.0...Is there any documentation about migration or breaking changes in api between 0.X and 1.X ? |
@fb64 OK, I've run a little investigation, and you're right ! The switch from coffeescript to javascript is the origin of this problem. EDIT So, the fact that the code worked for null and undefined was kind of accidental, but it looks like dependent libraries came to rely on it. So I think we should document the behavior and reimplement it. |
Thank you for your investigation @lovasoa . I'll prepare a PR on typeorm to fix this. |
To be clear: I'm ready to merge this PR. We just need to :
@fb64 are you ready to do this? |
Yes, I'll try. |
In some client library (eg: typeorm) Statement.bind function could be called with undefined or null parameters. https://github.com/typeorm/typeorm/blob/ce07824df4305cb93222959db0804a7d62218c09/src/driver/sqljs/SqljsQueryRunner.ts#L55
…bind() with null as parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this looks good ! I'll just like to change the type check, and we'll merge :)
Thank you very much @fb64 for your contribution ! |
In some client library (eg: typeorm) Statement.bind function could be called with undefined or null parameters.
https://github.com/typeorm/typeorm/blob/ce07824df4305cb93222959db0804a7d62218c09/src/driver/sqljs/SqljsQueryRunner.ts#L55