This module combines (Kris Jenkin's RemoteData package) with the Db type in this package. The kinds of things you store in a relational database are usually fetched from a remote source, and the RemoteData type represents whether your data is loading, loaded, or failed to load. By storing data as RemoteData, this module can make the assumption that Id that are missing from the Dbare RemoteData.NotAsked. This assumption permits our get function to return a RemoteData error item instead of a Maybe item or even a Maybe (RemoteData error item).
A single row in the Db; an Id, corresponding to either an item or the error that happend when attempting to load it.
Insert an item into a Db, when it has been successfully loaded
Insert many items into a Db, such as when you loaded many items successfully.
Mark the Id as Loading. After this function is used on a Db, it will return Loading for that Id
-- if the id is not in the `Db`
Remote.Db.get db id
--> RemoteData.NotAsked
-- but if it is..
Remote.Db.get (Remote.Db.loading id db) id
--> RemoteData.LoadingMark a List of Id as Loading in a Db
When data fails to load, set it as Failure in the Db
Fail many Id, representing them as failing to load in the Db
A general insert function into Db. You can insert a RemoteData error item into a Db
-- if the id is not in the `Db`
Remote.Db.get db id
--> RemoteData.NotAsked
-- but if it is..
Remote.Db.get
(Remote.Db.insert (id, RemoteData.Failure "Could not load") db)
id
--> RemoteData.Failure "Could not load"Get an item out of a Db. Notice how it does not return a Maybe like Dict do. An Id that is not present in the Db is returned as RemoteData.NotAsked.
Just like get, except it comes with the Id, for those cases where you dont want the item separated from its Id
Get many items from a Db. The (id, RemoteData.NotAsked) case represents the item under that Id being absent.
Update an item in a Db, using an update function. If the item doesnt exist in the Db, it comes into the update as RemoteData.NotAsked. If a RemoteData.NotAsked comes out of the update function, the value under that id will be removed.
Apply a change to just one item in the Db, assuming the item is in the Db in the first place. This function is just like update except deleting the item is not possible.
Short for "Database", it stores data by unique identifiers. The
erroris for loading errors, such as if an http request fails.