zio / zio-rocksdb   0.4.4

Apache License 2.0 Website GitHub

A ZIO-based interface to RocksDB.

Scala versions: 3.x 2.13 2.12

Project stage Release Artifacts

zio-rocksdb

A ZIO-based interface to RocksDB.

Installation

Add the following dependencies to your build.sbt file:

libraryDependencies ++= Seq(
  "dev.zio" %% "zio-rocksdb" % "<version>"
)

Using RocksDB

Use the provided RocksDB wrapper:

import java.nio.charset.StandardCharsets

import zio.rocksdb
import zio.rocksdb.{ RocksDB }

val UTF_8 = StandardCharsets.UTF_8
val key   = "key".getBytes(UTF_8)
val value = "value".getBytes(UTF_8)

val database  = RocksDB.live("/data/state")
val readWrite = RocksDB.put(key, value) *> RocksDB.get(key)
val result    = readWrite.provideCustomLayer(database)

Using TransactionDB

zio-rocksdb provides transactional capabilities using RocksDB Transaction API.

import java.nio.charset.StandardCharsets

import zio.rocksdb
import zio.rocksdb.{ TransactionDB, Transaction }

val key0   = "key0".getBytes(UTF_8)
val key1   = "key1".getBytes(UTF_8)
val value0 = "value0".getBytes(UTF_8)
val value1 = "value1".getBytes(UTF_8)

val database      = TransactionDB.live("/data/state")
val write0        = Transaction.put(key0, value0)
val write1        = Transaction.put(key1, value1)
val writeTogether = TransactionDB.atomically {
  write0 <&> write1
}
val result        = readWrite.provideCustomLayer(database)

Getting help

Join us on the ZIO Discord server.

Legal

Copyright 2019 Itamar Ravid and the zio-rocksdb contributors. All rights reserved.