Immudb bindings
- OCaml 97.7%
- Dune 1.6%
- Makefile 0.7%
| caqti-driver-immudb | ||
| examples/sqlgg_demo | ||
| lib | ||
| test | ||
| .gitignore | ||
| .ocamlformat | ||
| caqti-driver-immudb.opam | ||
| dune-project | ||
| immudb.opam | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
ocaml-immudb
OCaml client library for immudb, providing type-safe bindings for KV store, SQL, and cryptographic verification.
Features
- KV store —
set,get,delete,set_all,get_all,scan,history - SQL —
execandquerywith named parameters - Verified operations —
verified_set/verified_getvia immudb's REST API - Functor-based design — swap the HTTP backend by implementing
Http.S cohttp-lwt-unixtransport — 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-immudbdoes not register for theimmudb://URI scheme globally — useDriver.connectorDriver.with_connectiondirectly.
TODO
- Local Merkle proof verification (SHA-256 tree) in
verification.ml - gRPC transport (port 3322) — native protocol, required for streaming and binary proofs