-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bindings for libmdbx, an embedded key/value store -- -- Haskell bindings for libmdbx. -- -- See documentation in the main module or check the README on -- GitHub. @package libmdbx @version 0.2.1.0 -- | Low level bindings to libmdbx functions. module Mdbx.FFI -- | Flags for opening an environment. data MdbxEnvFlags MdbxEnvDefaults :: MdbxEnvFlags MdbxSyncDurable :: MdbxEnvFlags MdbxNosubdir :: MdbxEnvFlags MdbxSafeNosync :: MdbxEnvFlags MdbxMapasync :: MdbxEnvFlags MdbxRdonly :: MdbxEnvFlags MdbxNometasync :: MdbxEnvFlags MdbxWritemap :: MdbxEnvFlags MdbxUtterlyNosync :: MdbxEnvFlags MdbxNotls :: MdbxEnvFlags MdbxExclusive :: MdbxEnvFlags MdbxNordahead :: MdbxEnvFlags MdbxNomeminit :: MdbxEnvFlags MdbxCoalesce :: MdbxEnvFlags MdbxLiforeclaim :: MdbxEnvFlags MdbxPageperturb :: MdbxEnvFlags MdbxAccede :: MdbxEnvFlags -- | Environment object, needed for all the operations. newtype MdbxEnv MdbxEnv :: Ptr MdbxEnv -> MdbxEnv -- | UNIX permissions to set on created files. Zero value means to open -- existing, but do not create. type MdbxEnvMode = (CUInt) -- | Creates an environment. Represents a database in the file system. mdbx_env_create :: IO (Int, MdbxEnv) -- | Sets geometry of an environment. All the parameters can receive -1 to -- keep the current value. Receives (expressed in bytes): size_lower, -- size_now, size_upper, growth_step, shrink_threshold, pagesize. mdbx_env_set_geometry :: MdbxEnv -> Int -> Int -> Int -> Int -> Int -> Int -> IO Int -- | Opens an environment. Receives name, flags and mode. mdbx_env_open :: MdbxEnv -> String -> [MdbxEnvFlags] -> MdbxEnvMode -> IO Int -- | Closes an environment. mdbx_env_close :: MdbxEnv -> IO Int -- | Flags for a transaction. data MdbxTxnFlags MdbxTxnReadwrite :: MdbxTxnFlags MdbxTxnNosync :: MdbxTxnFlags MdbxTxnRdonly :: MdbxTxnFlags MdbxTxnNometasync :: MdbxTxnFlags MdbxTxnRdonlyPrepare :: MdbxTxnFlags MdbxTxnTry :: MdbxTxnFlags -- | Transaction instance. Needed for all operations with data, even -- reading. newtype MdbxTxn MdbxTxn :: Ptr MdbxTxn -> MdbxTxn -- | Begins a new transaction. -- -- Arguments: -- --
-- data User = User {
-- _username :: !Text,
-- _password :: !Text
-- } deriving (Eq, Show, Generic, Store)
--
-- deriving via (MdbxItemBinary User) instance MdbxItem User
--
--
-- Note 1: if you plan on using a custom type as the key, be
-- careful if it contains Text or ByteString instances,
-- since these types have a length field which is serialized before the
-- data. This causes issues when using libmdbx, since it depends on key
-- ordering and the length field will make shorter instances lower than
-- longer ones, even if the content indicates the opposite. You can use
-- the provided NullByteString or NullText types if your
-- data type is an instance of Binary or Store. Otherwise,
-- it is simpler to use Text or ByteString as the key.
--
-- Note 2: If your key type contains Word16 or longer fields, you
-- should make it an instance of Binary, not Store, since
-- Store uses platform dependent endianess and this affects libmdbx's
-- comparison functions. Given Binary uses network order (big endian) for
-- encoding, the comparison functions will work as expected. Failing to
-- do this may cause unexpected issues when retrieving data, in
-- particular when using cursors.
--
-- Note 3: The behavior when using signed integers or floating
-- point numbers as part of the key is undefined. To be able to use these
-- types in the key, you should store them as a Word of the appropriate
-- size and convert them with the conversion functions included in
-- API.
class MdbxItem i
-- | Converts a block of memory provided by libmdbx to a user data type.
-- There are no guarantees provided by the library that the block of
-- memory matches the expected type; a crash can happen when trying to
-- deserialize an incorrect type.
fromMdbxVal :: MdbxItem i => MdbxVal -> IO i
-- | Converts a user data type to a block of memory.
toMdbxVal :: MdbxItem i => i -> (MdbxVal -> IO b) -> IO b
-- | Newtype wrapping a ByteString that provides a Binary
-- instance using NULL terminated C strings, which allows for using them
-- as part of a custom data type representing a key.
--
-- This is not possible with regular ByteString and Text
-- instances since their Binary instances are serialized with the
-- size field first. Given that libmdbx compares keys as an unstructured
-- sequence of bytes, this can cause issues since longer strings are
-- considered greater than shorter ones, even if their content indicates
-- otherwise.
newtype NullByteString
NullByteString :: ShortByteString -> NullByteString
[unNullByteString] :: NullByteString -> ShortByteString
-- | Newtype wrapping a Text that provides a Binary instance
-- using NULL terminated C strings, which allows for using them as part
-- of a custom data type representing a key.
--
-- Check NullByteString for the rationale.
newtype NullText
NullText :: Text -> NullText
[unNullText] :: NullText -> Text
instance GHC.Show.Show Mdbx.Types.MdbxEnvGeometry
instance GHC.Classes.Eq Mdbx.Types.MdbxEnvGeometry
instance GHC.Classes.Ord Mdbx.Types.NullByteString
instance GHC.Classes.Eq Mdbx.Types.NullByteString
instance GHC.Classes.Ord Mdbx.Types.NullText
instance GHC.Classes.Eq Mdbx.Types.NullText
instance GHC.Show.Show Mdbx.Types.NullText
instance Data.String.IsString Mdbx.Types.NullText
instance GHC.Show.Show Mdbx.Types.NullByteString
instance Data.String.IsString Mdbx.Types.NullByteString
instance Mdbx.Types.MdbxItem Data.Text.Internal.Text
instance Mdbx.Types.MdbxItem Data.ByteString.Internal.ByteString
instance Data.Default.Class.Default Mdbx.Types.MdbxEnvGeometry
-- | Instances and helpers to derive MdbxItem for Store
-- instances.
module Mdbx.Store
-- | Helper type to derive MdbxItem instances for types implementing
-- Store using the newtype deriving trick.
newtype MdbxItemStore a
MdbxItemStore :: a -> MdbxItemStore a
[unwrapStore] :: MdbxItemStore a -> a
-- | Deserializes a Store instance from an MdbxVal.
fromMdbxStore :: Store v => MdbxVal -> IO v
-- | Serializes a Store instance to MdbxVal, and passes it to
-- a callback.
withMdbxStore :: Store v => v -> (MdbxVal -> IO a) -> IO a
instance Data.Store.Impl.Store a => Mdbx.Types.MdbxItem (Mdbx.Store.MdbxItemStore a)
instance Data.Store.Impl.Store Mdbx.Types.NullByteString
instance Data.Store.Impl.Store Mdbx.Types.NullText
-- | Instances and helpers to derive MdbxItem for Binary
-- instances.
module Mdbx.Binary
-- | Helper type to derive MdbxItem instances for types implementing
-- Binary using the newtype deriving trick.
newtype MdbxItemBinary a
MdbxItemBinary :: a -> MdbxItemBinary a
[unwrapBinary] :: MdbxItemBinary a -> a
instance Mdbx.Types.MdbxItem Mdbx.Types.NullByteString
instance Mdbx.Types.MdbxItem Mdbx.Types.NullText
instance Data.Binary.Class.Binary a => Mdbx.Types.MdbxItem (Mdbx.Binary.MdbxItemBinary a)
instance Data.Binary.Class.Binary Mdbx.Types.NullByteString
instance Data.Binary.Class.Binary Mdbx.Types.NullText
-- | Thin wrappers over the low level API to provide MonadIO support and
-- exception based error handling.
module Mdbx.API
-- | Compares two keys and returns -1, 0 or 1 if key1 is lower, equal or
-- greater than key2.
keyCmp :: MonadIO m => MdbxTxn -> MdbxDbi -> MdbxVal -> MdbxVal -> m Int
-- | Opens an environment.
envOpen :: (MonadIO m, MonadFail m) => String -> MdbxEnvGeometry -> [MdbxEnvFlags] -> m MdbxEnv
-- | Close an environment.
envClose :: (MonadIO m, MonadFail m) => MdbxEnv -> m ()
-- | Begins a transaction.
txnBegin :: (MonadIO m, MonadFail m) => MdbxEnv -> Maybe MdbxTxn -> [MdbxTxnFlags] -> m MdbxTxn
-- | Commits a transaction.
txnCommit :: (MonadIO m, MonadFail m) => MdbxTxn -> m ()
-- | Aborts a transaction.
txnAbort :: (MonadIO m, MonadFail m) => MdbxTxn -> m ()
-- | Opens a database (table).
dbiOpen :: (MonadIO m, MonadFail m) => MdbxEnv -> Maybe String -> [MdbxDbFlags] -> m MdbxDbi
-- | Closes a database.
dbiClose :: (MonadIO m, MonadFail m) => MdbxEnv -> MdbxDbi -> m ()
-- | Saves the provided key/value pair.
itemPut :: (MonadIO m, MonadFail m) => MdbxTxn -> MdbxDbi -> MdbxVal -> MdbxVal -> [MdbxPutFlags] -> m ()
-- | Returns the value associated to the given key, if any.
itemGet :: (MonadIO m, MonadFail m) => MdbxTxn -> MdbxDbi -> MdbxVal -> m (Maybe MdbxVal)
-- | Deletes the value associated with the given key, if any.
itemDel :: (MonadIO m, MonadFail m) => MdbxTxn -> MdbxDbi -> MdbxVal -> Maybe MdbxVal -> m ()
-- | Opens a cursor.
cursorOpen :: (MonadIO m, MonadFail m) => MdbxTxn -> MdbxDbi -> m MdbxCursor
-- | Closes a cursor.
cursorClose :: (MonadIO m, MonadFail m) => MdbxCursor -> m ()
-- | Stores the provided value at the given key, positioning the cursor on
-- it.
cursorPut :: (MonadIO m, MonadFail m) => MdbxCursor -> MdbxVal -> MdbxVal -> [MdbxPutFlags] -> m ()
-- | Deletes the value at the current position.
cursorDel :: (MonadIO m, MonadFail m) => MdbxCursor -> [MdbxPutFlags] -> m ()
-- | Moves to the first key on the database.
cursorFirst :: (MonadIO m, MonadFail m) => MdbxCursor -> m (Maybe (MdbxVal, MdbxVal))
-- | Moves to the last key on the database.
cursorLast :: (MonadIO m, MonadFail m) => MdbxCursor -> m (Maybe (MdbxVal, MdbxVal))
-- | Moves to the given key.
cursorAt :: (MonadIO m, MonadFail m) => MdbxCursor -> MdbxVal -> m (Maybe (MdbxVal, MdbxVal))
-- | Moves to the given key or first greater than it. Useful for searching.
cursorRange :: (MonadIO m, MonadFail m) => MdbxCursor -> MdbxVal -> m (Maybe (MdbxVal, MdbxVal))
-- | Moves to the next key.
cursorNext :: (MonadIO m, MonadFail m) => MdbxCursor -> m (Maybe (MdbxVal, MdbxVal))
-- | Moves to the previous key.
cursorPrev :: (MonadIO m, MonadFail m) => MdbxCursor -> m (Maybe (MdbxVal, MdbxVal))
-- | Moves the cursor using the provided operation.
cursorMove :: (MonadIO m, MonadFail m) => MdbxCursor -> MdbxVal -> MdbxCursorOp -> m (Maybe (MdbxVal, MdbxVal))
-- | Converts a Float value to an unsigned Word that can be used by
-- libmdbx's compare function.
keyFromFloat :: Float -> Word32
-- | Converts a Double value to an unsigned Word that can be used by
-- libmdbx's compare function.
keyFromDouble :: Double -> Word64
-- | Converts a 32bits signed Int value to an unsigned Word that can be
-- used by libmdbx's compare function.
keyFromInt32 :: Int32 -> Word32
-- | Converts a 64bits signed Int value to an unsigned Word that can be
-- used by libmdbx's compare function.
keyFromInt64 :: Int64 -> Word64
-- | Converts an unsigned Word to a Float value.
floatFromKey :: Word32 -> Float
-- | Converts an unsigned Word to a Double value.
doubleFromKey :: Word64 -> Double
-- | Converts an unsigned Word value to a 32bits signed Int.
int32FromKey :: Word32 -> Int32
-- | Converts an unsigned Word value to a 64bits signed Int.
int64FromKey :: Word64 -> Int64
-- | High level API to create, update, delete and query an MDBX database.
module Mdbx.Database
-- | Returns the value associated with the given key, if any.
getItem :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> k -> m (Maybe v)
-- | Returns the values associated to a list of keys. Returned length may
-- not match that of provided keys in case some of them are not found.
getItems :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> [k] -> m [v]
-- | Returns the list of values whose keys lie between the provided range.
getRange :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> k -> k -> m [v]
-- | Returns the list of key/value pairs whose keys lie between the
-- provided range.
getRangePairs :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> k -> k -> m [(k, v)]
-- | Returns the minimum and maximum keys, and their respective values,
-- between the provided key range.
--
-- Both start and end keys are inclusive, thus the same key/value pairs
-- will be returned if they exist. Otherwise, the next/previous valid
-- key/value pairs will be returned respectively.
getBounds :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> k -> k -> m (Maybe ((k, v), (k, v)))
-- | Saves the given key/value pair.
putItem :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> k -> v -> m ()
-- | Saves the given key/value pairs. Runs in a single transaction.
putItems :: (MonadIO m, MonadFail m, MdbxItem k, MdbxItem v) => MdbxEnv -> MdbxDbi -> [(k, v)] -> m ()
-- | Deletes the item associated with the given key, if any.
delItem :: (MonadIO m, MonadFail m, MdbxItem k) => MdbxEnv -> MdbxDbi -> k -> m ()
-- | Deletes the items associated with the given keys, if any. Runs in a
-- single transaction.
delItems :: (MonadIO m, MonadFail m, MdbxItem k) => MdbxEnv -> MdbxDbi -> [k] -> m ()
-- | Deletes the values whose keys lie between the provided range.
delRange :: (MonadIO m, MonadFail m, MdbxItem k) => MdbxEnv -> MdbxDbi -> k -> k -> m ()
-- | Bindings for libmdbx, a high-performance, in-process, key-value store.
--
-- This is the module most applications should import.
--
-- See the Mdbx.Types module for details on how to make your data
-- types work with libmdbx. It is recommended to use a serialization
-- library such as binary to simplify this task.
--
-- For the high level API, see the Mdbx.Database module.
--
-- For the low level API, or if you want to use cursors, see
-- Mdbx.API.
--
-- Mdbx.FFI (not exported by this module) provides direct, low
-- level, bindings to libmdbx.
module Mdbx