Normalized and immutable data model

一个人想着一个人 提交于 2019-12-04 23:53:04

The problem is you are storing data and relationships in the same type. To normalise, you need to separate. Relational databases 101.

newtype Id a = Id Int -- Type-safe ID.
data Person = Person { id :: Id Person, name :: String }
data Ex = Ex { personId :: Id Person, exId :: Id Person }

Now if a person changes their name, only a single Person value is affected. The Ex entries don't care about peoples' names.

Project M63 comes pretty close to what I was looking for. It is written in Haskell.

A more lightweight Haskell solution is outlined in Gabriel Gonzalez's post "A very general API for relational joins".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!