Db.Make
A DB
is the module used to interact with a data store that is parameterized over a module that represents a Serializable
type. Given such a module, a data store can created or loaded using open
and you can update the store using the various functions such as insert
, delete
, etc.
You must pass in a module that contains functions that show how to convert between the byte level representations of the types of the keys and values. A simply way to derive them is to use @@deriving bin_io
module S : Signatures.Common.Serializable
type key = S.key
type value = S.value
open_db
loads the database stored at the path into memory if it exists or creates a database at that directory and initializes a fresh instance.
val close_db : t -> unit
close_db
syncs and cleans up the internal state of the database handler. It is important that you run this function otherwise you will not close the underlying file descriptors.
Personally, I would suggest using ppx_defer.
get db k
returns the value of k
if it was set and the updated handler to the database.
insert db k v
binds v
to k
in the database and returns the previous binding if it was set alongside the updated handler to the database.
delete db k
removes k
from the database and returns the previous binding if it was set alongside the updated handler to the database.