Immudb bindings
  • OCaml 97.7%
  • Dune 1.6%
  • Makefile 0.7%
Find a file
2026-06-08 08:47:00 +00:00
caqti-driver-immudb small refactor + format 2026-06-08 08:47:00 +00:00
examples/sqlgg_demo small refactor + format 2026-06-08 08:47:00 +00:00
lib small refactor + format 2026-06-08 08:47:00 +00:00
test small refactor + format 2026-06-08 08:47:00 +00:00
.gitignore Initial commit 2026-06-05 11:35:59 +01:00
.ocamlformat small refactor + format 2026-06-08 08:47:00 +00:00
caqti-driver-immudb.opam caqti opam file 2026-06-05 16:26:02 +00:00
dune-project add caqti support 2026-06-05 16:25:58 +00:00
immudb.opam initial implementation of ocaml-immudb REST client 2026-06-05 16:25:47 +00:00
LICENSE Initial commit 2026-06-05 11:35:59 +01:00
Makefile initial implementation of ocaml-immudb REST client 2026-06-05 16:25:47 +00:00
README.md add caqti support 2026-06-05 16:25:58 +00:00

ocaml-immudb

OCaml client library for immudb, providing type-safe bindings for KV store, SQL, and cryptographic verification.

Features

  • KV storeset, get, delete, set_all, get_all, scan, history
  • SQLexec and query with named parameters
  • Verified operationsverified_set / verified_get via immudb's REST API
  • Functor-based design — swap the HTTP backend by implementing Http.S
  • cohttp-lwt-unix transport — included out of the box with a 5s request timeout

Usage

module Db = Immudb.Make(Immudb.Http_cohttp_lwt)

let () = Lwt_main.run begin
  let open Lwt.Syntax in
  let* conn = Db.Client.connect Immudb.Types.default_config >|= Result.get_ok in

  (* KV *)
  let* _ = Db.Kv.set conn ~key:"hello" ~value:(Bytes.of_string "world") in
  let* entry = Db.Kv.get conn ~key:"hello" >|= Result.get_ok in
  Printf.printf "%s\n" (Bytes.to_string entry.Immudb.Types.value);

  (* SQL *)
  let* _ = Db.Sql.exec conn ~sql:"CREATE TABLE ..." ~params:[] in
  let* result = Db.Sql.query conn ~sql:"SELECT ..." ~params:[] >|= Result.get_ok in
  Printf.printf "%d rows\n" (List.length result.Immudb.Types.rows);

  Db.Client.disconnect conn
end

Getting started

# Start immudb
make up

# Build
make build

# Run tests
make test

Default connection: localhost:8081 (REST), user immudb/immudb, database defaultdb.

Caqti driver

The caqti-driver-immudb package provides a Caqti connection for immudb's SQL interface.

The driver is a functor over the concurrency system. For Lwt:

module Driver = Caqti_driver_immudb.Make(Caqti_lwt.System_core)(Immudb.Http_cohttp_lwt)

open Lwt.Syntax
open Caqti_request.Infix
open Caqti_type.Std

let find_by_id =
  (int ->! tup2 int string) ~oneshot:true
    "SELECT id, name FROM users WHERE id = @p0"

let () = Lwt_main.run begin
  let uri = Uri.of_string "immudb://immudb:immudb@localhost:8081/defaultdb" in

  (* with_connection: auto-disconnect on exit *)
  Driver.with_connection uri (fun conn ->
    let (module C) = conn in

    let* () =
      C.exec
        ((unit ->. unit) ~oneshot:true
          "CREATE TABLE IF NOT EXISTS users (id INTEGER AUTO_INCREMENT, name VARCHAR, PRIMARY KEY id)")
        ()
      >|= Result.get_ok
    in

    let* row = C.find find_by_id 1 >|= Result.get_ok in
    Printf.printf "id=%d name=%s\n" (fst row) (snd row);
    Lwt.return_ok ())
end

Note

: caqti-driver-immudb does not register for the immudb:// URI scheme globally — use Driver.connect or Driver.with_connection directly.

TODO

  • Local Merkle proof verification (SHA-256 tree) in verification.ml
  • gRPC transport (port 3322) — native protocol, required for streaming and binary proofs