lmdb-simple-0.1.0.0: Simple API for LMDB

Safe HaskellTrustworthy
LanguageHaskell2010

Database.LMDB.Simple.Extra

Contents

Description

This module exports many functions for querying and modifying LMDB databases using common idioms (albeit in monadic form).

Synopsis

Query

null :: Database k v -> Transaction mode Bool Source #

Is the database empty?

size :: Database k v -> Transaction mode Int Source #

The number of entries in the database.

member :: Binary k => k -> Database k v -> Transaction mode Bool Source #

Is the key a member of the database? See also notMember.

notMember :: Binary k => k -> Database k v -> Transaction mode Bool Source #

Is the key not a member of the database? See also member.

lookup :: (Binary k, Binary v) => k -> Database k v -> Transaction mode (Maybe v) Source #

Lookup the value at a key in the database.

The function will return the corresponding value as (Just value), or Nothing if the key isn't in the database.

findWithDefault :: (Binary k, Binary v) => v -> k -> Database k v -> Transaction mode v Source #

The expression (findWithDefault def k db) returns the value at key k or returns default value def when the key is not in the database.

Modification

Insertion

insert :: (Binary k, Binary v) => k -> v -> Database k v -> Transaction ReadWrite () Source #

Insert a new key and value in the database. If the key is already present in the database, the associated value is replaced with the supplied value. insert is equivalent to insertWith const.

insertWith :: (Binary k, Binary v) => (v -> v -> v) -> k -> v -> Database k v -> Transaction ReadWrite () Source #

Insert with a function, combining new value and old value. insertWith f key value db will insert the pair (key, value) into db if key does not exist in the database. If the key does exist, the function will insert the pair (key, f new_value old_value).

insertWithKey :: (Binary k, Binary v) => (k -> v -> v -> v) -> k -> v -> Database k v -> Transaction ReadWrite () Source #

Insert with a function, combining key, new value and old value. insertWithKey f key value db will insert the pair (key, value) into db if key does not exist in the database. If the key does exist, the function will insert the pair (key, f key new_value old_value). Note that the key passed to f is the same key passed to insertWithKey.

insertLookupWithKey :: (Binary k, Binary v) => (k -> v -> v -> v) -> k -> v -> Database k v -> Transaction ReadWrite (Maybe v) Source #

Combines insert operation with old value retrieval. The monadic action (insertLookupWithKey f k x db) returns the same value as (lookup k db) but has the same effect as (insertWithKey f k x db).

Delete/Update

delete :: Binary k => k -> Database k v -> Transaction ReadWrite Bool Source #

Delete a key and its value from the database. If the key was not present in the database, this returns False; otherwise it returns True.

adjust :: (Binary k, Binary v) => (v -> v) -> k -> Database k v -> Transaction ReadWrite Bool Source #

Update a value at a specific key with the result of the provided function. When the key is not a member of the database, this returns False; otherwise it returns True.

adjustWithKey :: (Binary k, Binary v) => (k -> v -> v) -> k -> Database k v -> Transaction ReadWrite Bool Source #

Adjust a value at a specific key. When the key is not a member of the database, this returns False; otherwise it returns True.

update :: (Binary k, Binary v) => (v -> Maybe v) -> k -> Database k v -> Transaction ReadWrite Bool Source #

The monadic action (update f k db) updates the value x at k (if it is in the database). If (f x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.

updateWithKey :: (Binary k, Binary v) => (k -> v -> Maybe v) -> k -> Database k v -> Transaction ReadWrite Bool Source #

The monadic action (updateWithKey f k db) updates the value x at k (if it is in the database). If (f k x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.

updateLookupWithKey :: (Binary k, Binary v) => (k -> v -> Maybe v) -> k -> Database k v -> Transaction ReadWrite (Maybe v) Source #

Lookup and update. See also updateWithKey. The function returns changed value, if it is updated. Returns the original key value if the database entry is deleted.

alter :: (Binary k, Binary v) => (Maybe v -> Maybe v) -> k -> Database k v -> Transaction ReadWrite () Source #

The monadic action (alter f k db) alters the value x at k, or absence thereof. alter can be used to insert, delete, or update a value in a database.

Folds

foldr :: Binary v => (v -> b -> b) -> b -> Database k v -> Transaction mode b Source #

Fold the values in the database using the given right-associative binary operator.

foldl :: Binary v => (a -> v -> a) -> a -> Database k v -> Transaction mode a Source #

Fold the values in the database using the given left-associative binary operator.

foldrWithKey :: (Binary k, Binary v) => (k -> v -> b -> b) -> b -> Database k v -> Transaction mode b Source #

Fold the keys and values in the database using the given right-associative binary operator.

foldlWithKey :: (Binary k, Binary v) => (a -> k -> v -> a) -> a -> Database k v -> Transaction mode a Source #

Fold the keys and values in the database using the given left-associative binary operator.

foldDatabaseWithKey :: (Monoid m, Binary k, Binary v) => (k -> v -> m) -> Database k v -> Transaction mode m Source #

Fold the keys and values in the database using the given monoid.

Conversion

elems :: Binary v => Database k v -> Transaction mode [v] Source #

Return all elements of the database in the order of their keys.

keys :: Binary k => Database k v -> Transaction mode [k] Source #

Return all keys of the database in the order they are stored on disk.

toList :: (Binary k, Binary v) => Database k v -> Transaction mode [(k, v)] Source #

Convert the database to a list of key/value pairs. Note that this will make a copy of the entire database in memory.