Conversation
The documented return value of Database.each() is the Database instance, but the implementation returned the done callback's result or undefined. Call done() and return this instead, matching the documentation and the convention used by run(), create_function(), create_aggregate(), and updateHook(). Fixes sql-js#395
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #395.
Database.eachinsrc/api.jsreturned whatever thedonecallback returned, orundefinedwhenno
donewas passed, while the documentation says it returns the database object for chaining.This changes the code rather than the documentation, which is the choice the issue leaves open, for
two reasons. The rest of the class already reads that way:
run,create_function,create_aggregateandupdateHookall returnthisand document it as chaining. And no callercan use the old value for anything, since
done's return value is not part of any documentedcontract, so the current behaviour is closer to an omission than a feature.
doneis still called, at the same point, with the same arguments. Only its return value stopsbeing forwarded.
This is a behaviour change on a public method, so it is worth saying plainly what breaks:
code doing
var x = db.each(sql, cb, function () { return something; })gets the database insteadof
something. The alternative resolution, correcting the documentation to sayundefined, isa one-line docs change and leaves that code working. This PR takes the first reading because the
documented contract is also the more useful one and matches its siblings; say the word if you
prefer the second and I will send that instead.
The test in
test/test_database.jsassertsstrictEqual(chained, db). I could not run emscriptenhere, so I checked it both ways by applying the same two-line change to the shipped unminified
dist/sql-asm-debug.jsand runningnpm run test-asm-debug: it fails on the current code withdb.each returns the database objectand passes with the change, 24 passed and 0 failed. That is apatched artefact rather than a compile of this diff, so CI is the real check.