Skip to content

syedtaz/scorch-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caliburn

Persistent, embedded key-value store in pure OCaml. Work in progress.

Inspired by rocksdb and sled.

Installation

You can add a pin to the either the main branch or one of the releases. I plan to add Caliburn to the OPAM registry once the library is somewhat stable.

$ opam pin caliburn https://github.com/syedtaz/caliburn.git#main

Quickstart

Let's say we want to store a mapping between integers and strings. So we need a module that represents the type of the key-value pairs we will parameterize the database over which we will pass into the Make functor. This gives us a module for handling id -> name "databases".

open Caliburn

module Id_db = DB.Make (struct
  type key = int [@@deriving bin_io, compare]
  type value = string [@@deriving bin_io, compare]
end)

This module can we used to interact with any int-string database. So let's create one! After that, you can insert, delete or get key-values at your discretion. You need to remember to close the DB connection once you're done -- otherwise the file handlers won't be cleaned up.

let%expect_test _ =
  let db = Id_db.open_db "some/database" in
  [%defer Id_db.close db];
  let open Result.Let_syntax in
  let _ =
    let%bind _ = Int_DB.insert db ~key:1912 ~value:"Titanic sinks!" in
    let%bind res = Int_DB.get db 1912 in
    match res with
    | Some v -> return (Format.printf "we found the value : %s" v)
    | None -> return (Format.print_string "we couldn't find a value?")
  in
  ();
[%expect {| we found the value : Titanic sinks! |}]

References

About

Key-value store. [WIP]

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published