2 ms·
I implemented this for Datasette. The key is to use the primary key as a "tie breaker" - so you sort by the specified column first and then by the primary key.
by simonw 6y ago
I implemented this for Datasette. The key is to use the primary key as a "tie breaker" - so you sort by the specified column first and then by the primary key.
I managed to get this working with compound primary keys too: click "next" at the bottom of this page for a demo: https://latest.datasette.io/fixtures/compound_three_primary_keys https://latest.datasette.io/fixtures/compound_three_primary_...
The code is pretty complicated - mostly here: https://github.com/simonw/datasette/blob/0.53/datasette/views/table.py#L535-L594 https://github.com/simonw/datasette/blob/0.53/datasette/view...