You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sqlite: support custom collations via sqlite3_create_collation_v2 #63316
This affects the ORDER BY clause. Without this feature the word Ágætis gets put after the word Zebra. I'm building a music DB and this issue comes up a lot.
What is the feature you are proposing to solve the problem?
Expose sqlite's sqlite3_create_collation_v2 API in NodeJs.
What alternatives have you considered?
This sorting can be done in code, but it is much slower than having the feature available
I’d like to work on this feature. I can start with tests for ORDER BY behavior using custom collations, then wire sqlite3_create_collation_v2 into the Node sqlite API in a way that matches existing callback/resource patterns. Please assign this to me.
One more motivation for this. In my case the missing collation does not sort rows wrongly, it stops three tables being read at all.
Anki's .apkg decks hold a SQLite file whose schema 18 declares six tables COLLATE unicase, a collation Anki registers from its own Rust and no one else has. Three of those tables are WITHOUT ROWID, so the collation is part of the b-tree key rather than something only ORDER BY reaches for. From node:sqlite those tables cannot be read at all.
On v24.19.0, against a real schema-18 collection opened read-only:
SELECT * FROM fields -> ERR_SQLITE_ERROR no such collation sequence: unicase
SELECT * FROM templates -> ERR_SQLITE_ERROR no such collation sequence: unicase
SELECT * FROM tags -> ERR_SQLITE_ERROR no query solution
The three rowid tables read, until a query picks the index keyed on the collated column. decks has CREATE UNIQUE INDEX idx_decks_name ON decks (name), and name is COLLATE unicase, so:
SELECT * FROM decks -> ok, 2 rows
SELECT count(*) FROM decks -> ERR_SQLITE_ERROR no such collation sequence: unicase
Which query fails is up to the planner, which makes this hard to work around by writing the SQL differently.
What consumers do today is copy the file, then rewrite its schema:
PRAGMA writable_schema=ON;
UPDATE sqlite_master SET sql = replace(sql, ' COLLATE unicase', '') WHERE sql LIKE'%unicase%';
PRAGMA writable_schema=RESET;
RESET rather than OFF, because OFF leaves the already-parsed schema in memory and a later query that picks an index still asks for the collation it remembers. That failure is worse than an error: a covering-index scan comes back with fewer rows than the table holds and says nothing. So reading a file someone else wrote means taking a writable copy of it and editing sqlite_master by hand, on a database opened read-only in every other respect.
sql.js cannot register one either. Its build exports create_function and create_aggregate and nothing for collations, so it needs the same rewrite.
As for scope, DatabaseSync already has function, aggregate, enableDefensive, setAuthorizer and loadExtension, so a createCollation(name, comparator) sitting next to them follows a shape the class already has, and the comparator has no arguments beyond the two strings.
Activity
puneetdixit200 commentedon May 16, 2026
I’d like to work on this feature. I can start with tests for ORDER BY behavior using custom collations, then wire sqlite3_create_collation_v2 into the Node sqlite API in a way that matches existing callback/resource patterns. Please assign this to me.
trivikr commentedon Jul 27, 2026
@puneetdixit200 Are you working on this? If yes, can you please link the pull request?
shbernal commentedon Sep 5, 2026
One more motivation for this. In my case the missing collation does not sort rows wrongly, it stops three tables being read at all.
Anki's
.apkgdecks hold a SQLite file whose schema 18 declares six tablesCOLLATE unicase, a collation Anki registers from its own Rust and no one else has. Three of those tables areWITHOUT ROWID, so the collation is part of the b-tree key rather than something onlyORDER BYreaches for. Fromnode:sqlitethose tables cannot be read at all.On v24.19.0, against a real schema-18 collection opened read-only:
The three rowid tables read, until a query picks the index keyed on the collated column.
deckshasCREATE UNIQUE INDEX idx_decks_name ON decks (name), andnameisCOLLATE unicase, so:Which query fails is up to the planner, which makes this hard to work around by writing the SQL differently.
What consumers do today is copy the file, then rewrite its schema:
RESETrather thanOFF, becauseOFFleaves the already-parsed schema in memory and a later query that picks an index still asks for the collation it remembers. That failure is worse than an error: a covering-index scan comes back with fewer rows than the table holds and says nothing. So reading a file someone else wrote means taking a writable copy of it and editingsqlite_masterby hand, on a database opened read-only in every other respect.sql.jscannot register one either. Its build exportscreate_functionandcreate_aggregateand nothing for collations, so it needs the same rewrite.As for scope,
DatabaseSyncalready hasfunction,aggregate,enableDefensive,setAuthorizerandloadExtension, so acreateCollation(name, comparator)sitting next to them follows a shape the class already has, and the comparator has no arguments beyond the two strings.I maintain a reader for these files (https://github.com/shbernal/anki-apkg-export) and am happy to test a patch against real decks if someone picks this up.