A way of storing your data by Id
Short for "Database", it stores data by unique identifiers
empty : Db item
An empty Db
with no entries
insert : Id -> item -> Db item -> Db item
Insert an item into the Db
under the given Id
insertMany : List ( Id, item ) -> Db item -> Db item
Insert many items into the Db
under their given Id
s
insertWithoutId : Random.Seed -> item -> Db item -> ( Db item, Random.Seed )
Insert an item into a Db
without an Id
. This function takes a Random.Seed
because it generates a random Id
for the item you are inserting into the Db
. This function gaurantees no id collisions; if the id it generates already exists, it simply tries again with a different id.
update : Id -> (Maybe item -> Maybe item) -> Db item -> Db item
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.
remove : Id -> Db item -> Db item
Remove the item at the given Id
, if it exists
get : Db item -> Id -> Maybe item
Get the item under the provided Id
getMany : Db item -> List Id -> List item
Get many items from a Db
from a list of Ids
. Elements not in the Db
simply wont appear in the return result.
getWithId : Db item -> Id -> ( Id, Maybe item )
Just like get
, except it comes with the Id
, for those cases where you dont want the item separated from its Id
getManyWithId : Db item -> List Id -> List ( Id, Maybe item )
Get many items from a Db
, but dont filter out missing results, and pair results with their Id
member : Id -> Db item -> Basics.Bool
Determine if a certain Id
is in a Db
toList : Db item -> List ( Id, item )
Turn your Db
into a list
fromList : List ( Id, item ) -> Db item
Initialize a Db
from a list of id-value pairs
toDict : Db item -> Dict String item
turn a Db item
into a Dict String item
map : (a -> b) -> Db a -> Db b
Map a Db
to a different data type.
mapItem : Id -> (item -> item) -> Db item -> Db item
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.