Repository navigation
sqlite: add database.createCollation() - #67772
Open
vedchaudhari wants to merge 1 commit into
Open
vedchaudhari wants to merge 1 commit into
vedchaudhari wants to merge 1 commit into
Conversation
Expose sqlite3_create_collation_v2() so that SQL can sort and compare text with a JavaScript function, and so that databases whose schema uses a custom collation can be read. SQLite has no way for a collation to report an error. If the compare function throws, the statement is interrupted and the exception is thrown once the statement returns. If the statement was writing, its changes are rolled back, the same as SQLite does for any interrupted write. Fixes: nodejs#63316 Signed-off-by: vedchaudhari <vedc2853@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67772 +/- ##
==========================================
- Coverage 90.54% 90.51% -0.04%
==========================================
Files 803 805 +2
Lines 285302 285859 +557
Branches 55074 55186 +112
==========================================
+ Hits 258324 258740 +416
- Misses 17104 17204 +100
- Partials 9874 9915 +41
🚀 New features to boost your workflow:
|
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 #63316
node:sqlitehas no way to register a custom collation, so you can't sort or compare text with your own rules in SQL, and a database whose schema uses a custom collation (for example one made by another app) can't be read:This adds
database.createCollation(name, compare), a wrapper aroundsqlite3_create_collation_v2():The result of
compareis converted the same way as the compare function forArray.prototype.sort(), so NaN counts as equal.SQLite has no way for a collation to report an error. If
comparethrows, the statement is stopped withsqlite3_interrupt(), and the original exception is thrown fromall(),get(),run(),iterate(),exec()and the other methods that run statements.If the statement was writing, its changes are rolled back, the same as SQLite does for an interrupted write: a commit hook turns the commit into a rollback, and an open transaction is rolled back. Without that, an
INSERTinto an index that uses the collation could be saved with the entry in the wrong place (PRAGMA integrity_checkreported a missing index row).A few things I'd like opinions on:
sqlite3_interrupt()works, and it's documented.exec()inside a transaction, the transaction is rolled back even if the statement that threw was only reading, because there's no way to tell which statement in the string failed.cc @trivikr @araujogui
@shbernal I saw your interest in this on the issue, would be great to get your review too.
Assisted-by: an AI coding agent. Reviewed and tested locally by me.