Working with the LMDB API

To get started with LMDB, we need to perform three tasks, usually in this order:

  1. Create a new environment object.
  2. Store data.
  3. Retrieve data.

Fortunately, the LMDB API makes it straightforward to do each of these tasks and wrap them in idiomatic Scala functions.

To open an environment, we’ll use the following functions and data structures:

 type​ ​Env​ = Ptr[​Byte​]
 type​ ​DB​ = UInt
 def​ mdb_env_create(env​:​​Ptr​[​Env​])​:​​Int​ = extern
 def​ mdb_env_open(env​:​​Env​, path​:​​CString​, flags​:​​Int​, mode​:​​Int​)​:​​Int​ = extern

Env here is an opaque pointer, and we have a convenient helper function mdb_env_create to allocate it for us. Once initialized, we use mdb_env_open to open ...

Get Modern Systems Programming with Scala Native now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.