Short for "Database", Db item is basically a glorified Dict String item. It takes Id item, and it if has an item under that Id item, it gives it to you.
users : Db User
users =
--
maybeBob : (Id User, Maybe User)
maybeBob =
Db.get users (Id.fromString "bob")The functions in the Db module are much like those of Dict, but they are specialized for the use case of a relational database.
Insert many items into the Db under their given Ids
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, Nothing) 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 Nothing. If a Nothing 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.
Take a List of items, presumably ones you just retrieved using getMany, and filter out
the ones that werent present in the Db
myFriendsList
|> Db.getMany people
|> Db.filterMissing
-->: List (Row Person)Verify that all the items are present, and if not, fail with a list of the items that are missing
allPresent [ (id1, Just user1), (id2, Just user2) ]
--> Ok [ (id1, user1), (id2, user2) ]
allPresent [ (id1, Nothing), (id2, Just user2), (id3, Nothing) ]
--> Err [ id1, id3 ]
Short for "Database", it stores data by unique identifiers