dacr / zio-lmdb   2.8.1

Apache License 2.0 GitHub

Lightning Memory Database (LMDB) for scala ZIO

Scala versions: 3.x

ZIO-LMDB

scaladoc docs

Embedded, ACID, key-value database for ZIO — zero infrastructure, zero ops, just a file.

Built on lmdb-java with a type-safe, ZIO-native API:

  • Three collection kindsLMDBCollection (1 key → 1 value), LMDBMulti (1 key → N values), LMDBIndex (1 key → N keys)
  • JSON by defaultderives LMDBCodecJson is all it takes; custom codecs are supported
  • Honest types — every function signature tells you exactly what can fail
  • Atomic transactions — single-collection or cross-collection, always consistent
  • Lexicographic ordering — keys are sorted; range scans and pagination come for free
  • Scala-CLI friendly — add one dependency line and run

Install

// sbt
libraryDependencies += "fr.janalyse" %% "zio-lmdb" % "2.8.1"

// scala-cli
//> using dep fr.janalyse::zio-lmdb:2.8.1
//> using javaOpt --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED

Quick example

import zio.*, zio.lmdb.*, zio.lmdb.json.*
import java.util.UUID

case class Person(name: String, age: Int) derives LMDBCodecJson

object Example extends ZIOAppDefault:
  def run = (for {
    people <- LMDB.collectionCreate[UUID, Person]("people", failIfExists = false)
    id     <- Random.nextUUID
    _      <- people.upsertOverwrite(id, Person("Alice", 30))
    _      <- people.upsert(id, _.map(p => p.copy(age = p.age + 1)).getOrElse(Person("Alice", 30)))
    result <- people.fetch(id)
    _      <- Console.printLine(result)
  } yield ()).provide(LMDB.liveWithDatabaseName("my-app"), Scope.default)

Documentation

Full API reference, transactions, codecs, indexes, query DSL and configuration:
dacr.github.io/zio-lmdb

Real-world usage

Runnable snippets (scala-cli)