Manual ordering of records

Not directly related to 8base, but I’m curious about others’ thought on user-ordered items. i.e. displaying rows in order of drag-and-drop.

I’ve seen implementations use numbering (0, 100, 200), insert 150, and deferred or manual normalization. It can also be done with strings (a, ab, c). You can use ‘nextId’ and build a linked list, but that seems like a penalty on performance for the query, being recursive? Another approach is using a separate table to store the ordering (using “Allow Multiple” mahybe?), but it’s not easily queryable

Another option is to sort on the client, using one of the techniques above to simply store the relations. If there are hundreds, or even thousands, it’s possible. But if there are 100,000 paged items, it must come from the query.


What up, @mike_ekim1024!

Just to clarify, are you talking about support for positioning/indexing?

For example, I have a table called Playlists and another called Songs. In a given playlist, I want to drag and drop my songs into the order of which I want them to be played.

Yes, displaying rows in a specific order. I’m trying out using string right now (a, b, c) and insert (ba) to go before ©. I like that theoretically I wouldn’t need to normalize (vs 100, 200) where you start running out of numbers, but eventually it would be good to normalize though (a, b, ba, c) => (a, b, c, d).


Yeah @mike_ekim1024 - If I were trying to do this now I’d go about it the following way.

  1. A record could ONLY belong in one list (song belongs to a playlist).
  2. Deploy a custom mutation resolver called setPosition(songId: ID!, listId: ID!, position: Int!)

The idea would be to handle the indexing logic inside of the function, so that all songs in the list get updated with new positions when rearranged.

That’s at least where I would start before doing the multiple positions in multiple lists scenario.