Open Flamenco opened 6 years ago
It's interesting, I actually have a test written, running, and passing that should account for this scenario: https://github.com/kylefarris/node-querybuilder/blob/58f1f714a6391cd67da80c515f5399f1152918d4/test/mysql/tests-insert_batch.js#L51
I'll have to do some research...
@Flamenco I found the issue--it didn't really have anything to do with the callback, per se... strange/hard bug to track down.
Problem is that when its fixed, it runs the expected a query: INSERT INTO [some_table] () VALUES ()
. Seems good, but, then if any columns do not have a default value (the case with my mock_db for testing), you'll get errors anyways.
I could simply return the response object with affected_rows: 0
if the dataset is empty but there could conceivably be a reason for seeding a database with a bunch of rows of default data (with, say, only an incrementing primary key).
I'm not really sure there is a great way to get around this issue other than simply not allowing empty arrays in the insert_batch()
method. Do you have any suggestions?
I suggest to return affected_rows: 0
and also add another property bypassed:true
. We can use that property to signal here, and in other instances, that the database was not hit.
Also, in the main configuration, there can be an option to allow bypassing the database. (allowBypass:true). That will make it very clear that some requests, such as this, will not hit the wire.
driver: mysql
Expected behavior would be to simply invoke the callback. If the server response with 0 affected rows is needed, then to actually call the DB with no rows to insert.