tekartik / sembast.dart

Simple io database
BSD 2-Clause "Simplified" License
763 stars 63 forks source link

[Question] Modeling nested data #154

Open andreierdoss opened 4 years ago

andreierdoss commented 4 years ago

Question Is it advisable to use Sembast for nested data and if so, what is the best practice on modeling it?

Description In a situation where the data looks like this: Company -> Projects -> Employees -> Tasks

I want to load and show the data tree in a single view from projects downward. Also I would like to easily add/update/delete employees and tasks.

There are a max of 50 tasks per employee, 10 employees per project and 10 projects per company.

alextekartik commented 4 years ago

A similar question could be asked for any database system and I don't have a string opinion of it. At first I would say to use a different store for each entity, each "parent" saving a list of its childen ids (company has projectIds, project has employeeIds and so so).

In a single transaction you can load a company, then all of its projects, then all employees...by id. Case by case you can decide later to embed children in their parent if needed for either performance or convenience reason. For example if project don't change often you could have them nested in company. But it is definitely bad to save everything in single map since a single change means rewriting the whole record (which could contain 5000 entities per your statement).