ZIO-LMDB
ZIO-LMDB is an embedded, ACID, key-value database for Scala applications built on ZIO.
It wraps lmdb-java with a higher-level, type-safe API that integrates naturally with the ZIO effect system.
Why ZIO-LMDB?
- Zero infrastructure — the database lives in-process, no server to run or maintain.
- ACID guarantees — full transactional semantics backed by LMDB’s copy-on-write B+ tree.
- Type-safe API — keys and values are fully typed; codecs are resolved at compile time.
- ZIO-native — every operation returns a
ZIOeffect with precise error channels. - Honest signatures — the return type tells you exactly what can go wrong.
- JSON storage by default —
derives LMDBCodecJsonis all you need; custom codecs are supported. - Lexicographic ordering — keys are automatically sorted, enabling efficient range scans.
Collection types
| Type | Cardinality | Facade |
|---|---|---|
| Regular | one key → one value | LMDBCollection[K, T] |
| Multi | one key → many values | LMDBMulti[K, T] |
| Index | one key → many keys | LMDBIndex[FROM, TO] |
Quick install
Add the dependency to your build.sbt:
libraryDependencies += "fr.janalyse" %% "zio-lmdb" % "2.8.3"
For scala-cli scripts, add at the top of your file:
//> using dep fr.janalyse::zio-lmdb:2.8.3
//> using javaOpt --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED
The JVM options are required when running on recent JVMs (Java 17+).
Minimal example
import zio.*, zio.lmdb.*, zio.lmdb.json.*
case class User(name: String, age: Int) derives LMDBCodecJson
val program = for {
users <- LMDB.collectionCreate[String, User]("users", failIfExists = false)
_ <- users.insert("alice", User("Alice", 30))
result <- users.fetch("alice")
_ <- Console.printLine(result)
} yield ()
object Main extends ZIOAppDefault:
def run = program.provide(LMDB.liveWithDatabaseName("my-app"), Scope.default)
JVM requirements
When LMDB is used with recent JVMs, add the following options at startup:
--add-opens java.base/java.nio=ALL-UNNAMED
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
In this documentation
- Getting Started — setup, layers, and your first CRUD operations.
- LMDBCollection — one key → one value collections.
- LMDBMulti — one key → many values collections.
- LMDBIndex — key-to-key index collections.
- Transactions — atomic multi-operation transactions.
- Codecs — key codecs and value codecs reference.
- Query DSL — fluent query and join API.
- Configuration — all configuration parameters.