Portability | portable |
---|---|
Stability | provisional |
Maintainer | John Goerzen <jgoerzen@complete.org> |
Safe Haskell | None |
Written by John Goerzen, jgoerzen@complete.org
This module provides a generic infrastructure for supporting storage of hash-like items with String -> String mappings. It can be used for in-memory or on-disk items.
- class AnyDBM a where
- closeA :: a -> IO ()
- flushA :: a -> IO ()
- insertA :: a -> String -> String -> IO ()
- deleteA :: a -> String -> IO ()
- hasKeyA :: a -> String -> IO Bool
- lookupA :: a -> String -> IO (Maybe String)
- forceLookupA :: a -> String -> IO String
- insertListA :: a -> [(String, String)] -> IO ()
- toListA :: a -> IO [(String, String)]
- keysA :: a -> IO [String]
- valuesA :: a -> IO [String]
- mapA :: AnyDBM a => a -> ((String, String) -> IO b) -> IO [b]
- strFromA :: AnyDBM a => a -> IO String
- strToA :: AnyDBM a => a -> String -> IO ()
The AnyDBM class
The main class for items implementing this interface.
People implementing this class should provide methods for:
Close the object, writing out any unsaved data to disk if necessary.
If you implement this, make sure your implementation calls flushA
.
Note: if you have an object opened for writing, you MUST call closeA on it when you are done. Implementations are not required to preserve your data otherwise.
Flush the object, saving any un-saved data to disk but not closing
it. Called automatically by closeA
.
Insert the given data into the map. Existing data with the same key will be overwritten.
deleteA :: a -> String -> IO ()Source
Delete the data referenced by the given key. It is not an error if the key does not exist.
hasKeyA :: a -> String -> IO BoolSource
True if the given key is present.
lookupA :: a -> String -> IO (Maybe String)Source
Find the data referenced by the given key.
forceLookupA :: a -> String -> IO StringSource
Look up the data and raise an exception if the key does not exist. The exception raised is PatternMatchFail, and the string accompanying it is the key that was looked up.
insertListA :: a -> [(String, String)] -> IO ()Source
Call insertA
on each pair in the given association list, adding
them to the map.
toListA :: a -> IO [(String, String)]Source
Return a representation of the content of the map as a list.
keysA :: a -> IO [String]Source
Returns a list of keys in the AnyDBM
object.
valuesA :: a -> IO [String]Source
Returns a list of values in the AnyDBM
object.
AnyDBM utilities
mapA :: AnyDBM a => a -> ((String, String) -> IO b) -> IO [b]Source
Similar to MapM, but for AnyDBM
objects.