libmdbx-0.2.1.1: Bindings for libmdbx, an embedded key/value store
Copyright(c) 2021 Francisco Vallarino
LicenseBSD-3-Clause (see the LICENSE file)
Maintainerfjvallarino@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Mdbx.Types

Description

Types used by the library. Mainly re exports the types generated by c2hs in the FFI module, while it also adds some types used by the high level interface.

Synopsis

Re-exported from FFI

data MdbxEnv Source #

Environment object, needed for all the operations.

Instances

Instances details
Storable MdbxEnv Source # 
Instance details

Defined in Mdbx.FFI

data MdbxTxn Source #

Transaction instance. Needed for all operations with data, even reading.

Instances

Instances details
Storable MdbxTxn Source # 
Instance details

Defined in Mdbx.FFI

type MdbxDbi = CUInt Source #

Database instance. Represents a logical table in the database.

data MdbxCursor Source #

Cursor instance. Used for efficient navigation in a database.

Instances

Instances details
Storable MdbxCursor Source # 
Instance details

Defined in Mdbx.FFI

data MdbxVal Source #

Binary blob representing a key or value in the database.

Constructors

MdbxVal 

Fields

Instances

Instances details
Eq MdbxVal Source # 
Instance details

Defined in Mdbx.FFI

Methods

(==) :: MdbxVal -> MdbxVal -> Bool #

(/=) :: MdbxVal -> MdbxVal -> Bool #

Show MdbxVal Source # 
Instance details

Defined in Mdbx.FFI

Storable MdbxVal Source # 
Instance details

Defined in Mdbx.FFI

type MdbxEnvMode = CUInt Source #

UNIX permissions to set on created files. Zero value means to open existing, but do not create.

data MdbxEnvFlags Source #

Flags for opening an environment.

data MdbxCursorOp Source #

Flags for cursor operations.

High level interface

data MdbxEnvGeometry Source #

Geometry of the database. The most important parameter is the maximum size, that defaults to 1024Mb. All other values default to -1, meaning the current value will be kept.

Constructors

MdbxEnvGeometry 

Fields

  • envSizeMin :: Int

    Minimum DB size in bytes.

  • envSizeNow :: Int

    Current DB size in bytes.

  • envSizeMax :: Int

    Maximum DB size in bytes.

  • envGrowthStep :: Int

    Step growth size of the database in bytes. Must be greater than zero to allow for growth.

  • envShrinkThreshold :: Int

    Step shrink size of the database in bytes. Must be greater than zero to allow for shrinkage and lower than envGrowthStep to avoid immediate shrinking after growth.

  • envPageSize :: Int

    Page size of the database in bytes. In general it should not be changed after the database was created.

Instances

Instances details
Eq MdbxEnvGeometry Source # 
Instance details

Defined in Mdbx.Types

Show MdbxEnvGeometry Source # 
Instance details

Defined in Mdbx.Types

Default MdbxEnvGeometry Source # 
Instance details

Defined in Mdbx.Types

class MdbxItem i where Source #

Converts an instance to/from the representation needed by libmdbx. This type is used for both keys and values. The fields on the type must be strict, otherwise unexpected crashes due to lazy IO delaying low level memory access may happen.

Only ByteString, Text instances are provided, since they are commonly used as the key when storing/retrieving a value.

For your own types, in general, you will want to use a serialization library such as binary, and apply the newtype deriving via trick.

MdbxItemBinary is provided to simplify using Binary instances as keys or values with libmdbx, while MdbxItemStore provides the same functionality for Store instances. With those helpers, creating custom types compatible with libmdbx is easy:

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.

Methods

fromMdbxVal :: MdbxVal -> IO i Source #

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.

toMdbxVal :: i -> (MdbxVal -> IO b) -> IO b Source #

Converts a user data type to a block of memory.

Instances

Instances details
MdbxItem ByteString Source # 
Instance details

Defined in Mdbx.Types

MdbxItem Text Source # 
Instance details

Defined in Mdbx.Types

Methods

fromMdbxVal :: MdbxVal -> IO Text Source #

toMdbxVal :: Text -> (MdbxVal -> IO b) -> IO b Source #

MdbxItem NullText Source # 
Instance details

Defined in Mdbx.Binary

MdbxItem NullByteString Source # 
Instance details

Defined in Mdbx.Binary

Store a => MdbxItem (MdbxItemStore a) Source # 
Instance details

Defined in Mdbx.Store

Binary a => MdbxItem (MdbxItemBinary a) Source # 
Instance details

Defined in Mdbx.Binary

Helper types

newtype NullByteString Source #

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.

Instances

Instances details
Eq NullByteString Source # 
Instance details

Defined in Mdbx.Types

Ord NullByteString Source # 
Instance details

Defined in Mdbx.Types

Show NullByteString Source # 
Instance details

Defined in Mdbx.Types

IsString NullByteString Source # 
Instance details

Defined in Mdbx.Types

Binary NullByteString Source # 
Instance details

Defined in Mdbx.Binary

Store NullByteString Source # 
Instance details

Defined in Mdbx.Store

MdbxItem NullByteString Source # 
Instance details

Defined in Mdbx.Binary

newtype NullText Source #

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.

Constructors

NullText 

Fields

Instances

Instances details
Eq NullText Source # 
Instance details

Defined in Mdbx.Types

Ord NullText Source # 
Instance details

Defined in Mdbx.Types

Show NullText Source # 
Instance details

Defined in Mdbx.Types

IsString NullText Source # 
Instance details

Defined in Mdbx.Types

Binary NullText Source # 
Instance details

Defined in Mdbx.Binary

Methods

put :: NullText -> Put #

get :: Get NullText #

putList :: [NullText] -> Put #

Store NullText Source # 
Instance details

Defined in Mdbx.Store

MdbxItem NullText Source # 
Instance details

Defined in Mdbx.Binary