To handle cases where an insert statement is created with empty insert data#197
Conversation
|
Nice! Thanks @Hiteshm01 Would you be able to put together a test case for this? |
|
@brianc I found the root cause of it but could only manage a hackish handling in code. Could you please have a look at my latest commit? |
|
@brianc , Were you able to verify it? |
|
Sorry I missed this earlier! Your code looks good to me - there's a merge conflict currently. :( Once you get that resolved I'll happily pull it in! 👍 |
Conflicts: package.json
|
@brianc , conflict resolved. |
|
Awesome! Thanks! Merging & pushing new patch version now. |
To handle cases where an insert statement is created with empty insert data
|
This doesn't always work in pg; will produce a test case edit: it does actually work, it generates @Hiteshm01 I don't think this behavior is correct - if an empty array is passed, the query should not try to insert anything at all... At the very least, this requires a major version bump as it causes existing code that did nothing to try and insert data. |
|
@spion , I agree. It should not. But earlier implementation was returning a "select * from table" in this case which was disastrous in any production table. My fix isn't ideal as it is only avoiding trouble. |
|
@Hiteshm01 a harmless query like In any case, major version (in terms of npm i.e. 0.44) should definitely be bumped. |
|
@spion , That will be a better fix but do you think returning a select statement when requested for an insert statement is correct behavior? |
|
Well, not really - its just backward-compatible behavior. The correct backward-incompatible behavior would be to not generate a query. |
|
Agreed. I will try to implement it over the weekend. |
|
Attempted fix @ #203 |
Fix for insert statement with empty array without object i.e. []. currently it is issuing select * from table_name in this case.
For array with empty object, it will behave as default.