memdb-1.0.0.3: Efficient in memory indexed database

Safe HaskellNone
LanguageHaskell2010

Database.Immutable.Read

Contents

Synopsis

Construction / reading

createDB Source #

Arguments

:: Serialize a 
=> InsertIndex indexes a 
=> ByteString

Serialised elements

-> Int

Element count

-> Maybe (Int -> Int -> IO ())

Progress indicating function, called with the number of elements currently read and the total count of elements

-> Indexes indexes a

Indexes description

-> IO (Either String (DB indexes a))

Resulting database or a parse/deserializiation error

Create a database from a ByteString and build up in-memory indexes according to the Indexes description.

readDB Source #

Arguments

:: Serialize a 
=> InsertIndex indexes a 
=> FilePath

File path to database

-> Maybe (Int -> Int -> IO ())

Progress indicating function, called with the number of elements currently read and the total count of elements

-> Indexes indexes a

Indexes description

-> IO (Either String (DB indexes a))

Resulting database or a parse/deserializiation error

Read a database from a file path and build up in-memory indexes according to the Indexes description.

Indexes

data Name (a :: Symbol) Source #

Type tying a typelevel Symbol to a value.

Name has an IsLabel instance and can thus be created by using the overloaded labels syntax (i.e. #someName) when the OverloadedLabels GHC extension is enabled.

Instances
l ~ l' => IsLabel l (Name l') Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

fromLabel :: Name l' #

data Indexes (indexes :: [(Symbol, *)]) a Source #

Indexes description. Currently, there are two supported index types: Word32 and ByteString. Both can be specified using the utility functions word32Index and byteStringIndex, respectively.

For example, one might define indexes over a datatype in the following way:

data Person = Person
  { name :: String
  , age  :: Int
  } deriving (Generic, Serialize)

personIndexes
  = byteStringIndex #nameIndex (pack . name)
  $ word32Index     #ageIndex  (fromIntegral . age)
    unindexed

Composite or computed indexes can be built by supplying an appropriate function to byteStringIndex or word32Index, e.g:

personIndexes
  = byteStringIndex #nameAndAgePlusOneIndex
      (\p -> pack (name p <> show (age p + 1)))
    unindexed

unindexed :: Indexes '[] a Source #

Default Indexes description, specifying an unindexed database.

byteStringIndex Source #

Arguments

:: KnownSymbol s 
=> Name s

Index name

-> (a -> b)

Projecting function

-> (b -> ByteString)

Index computing function

-> Indexes indexes a

Indexes description

-> Indexes ('(s, ByteStringIndex b) ': indexes) a

Resulting Indexes desctiption, inlcuding the new ByteString index

Add a ByteString index to an Indexes description to be built when reading a database.

word32Index Source #

Arguments

:: KnownSymbol s 
=> Name s

Index name

-> (a -> b)

Projecting function

-> (b -> Word32)

Index computing function

-> Indexes indexes a

Indexes description

-> Indexes ('(s, Word32Index b) ': indexes) a

Resulting Indexes desctiption, inlcuding the new Word32 index

Add a Word32 index to an Indexes description to be built when reading a database.