Is it possible to define collation in Convex columns?
I am building a language learning app and need to maintain an ordered list of known words per user for a variety of spoken languages.
5 Replies
unfortunately no, there is no way to have a localized sort order in Convex. ArrayBuffers are sorted lexicographically by byte, while Strings are sorted lexicographically by unicode codepoint. To define a custom sort order, you can either sort in javascript after fetching the documents, or add a field to each document that represents the sort order
Thanks @lee. How can I implement future re-Ordering in the Convex database?
I have a similar use case where the user can move the position of the elements by inserting new elements or deleting elements.
In Postgres, something like this extension could be used: https://github.com/begriffs/pg_rational, which is based on storing fractions in 64 bits.
You can store an ordering key as a field on the object. This ordering key can be a string (or a float but strings are easier to manipulate) which you can pick by finding intermediate strings between existing keys
@lee - I see, so are you saying to store the column as a string type and then insert a value like a LexoRank? do you have a recommendation of the logic using string ?
https://www.npmjs.com/package/lexorank
https://medium.com/whisperarts/lexorank-what-are-they-and-how-to-use-them-for-efficient-list-sorting-a48fc4e7849f
npm
lexorank
A reference implementation of a list ordering system like JIRA's Lexorank algorithm. Latest version: 1.0.5, last published: 2 years ago. Start using lexorank in your project by running
npm i lexorank
. There are 10 other projects in the npm registry using lexorank.Medium
LexoRank — what are they and how to use them for efficient list sor...
In this article, we will explain what LexoRank is and how we find them and how used them in our mobile app to effectively sort lists and…
oh there's a library for it! Yeah use that