mardi 21 janvier 2020

Most efficient way to Manage an Ordered List in a Relational Database

I'm in the process of building a simple todo app and am looking for advice in terms of how I should approach my DB architecture.

The point is question is how I handle the tasks in a user's todo list, more specifically the order of that list.

My initial thought was to go down the good old fashioned relational DB and just have a tabled called tasks, with a column called order. This will obviously work but means that each time an item is re-ordered I need to loop through ALL of the tasks and update their respective order value. This seems very inefficient to me especially as the app is asynchronous.

My second thought was to simply store the entire list as a JSON object/array, that way I don't need to worry about updating individual records, I can overwrite the entire object each time the list changes. However, this might mean that I lose other features/advantages of having a "proper" relational DB.

My question is simply, what's best practise, am I on the right track, are there other patterns I should explore? I'm simply looking for a second (more qualified) point of view.

Cheers, Mikael

Aucun commentaire:

Enregistrer un commentaire