Module 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

Parameters

Signature

type key = S.key
type value = S.value
type t
val open_db : string -> (t, Errors.t) Core.Result.t

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.

val get : t -> key -> (value Core.Option.t, Errors.t) Core.Result.t

get db k returns the value of k if it was set and the updated handler to the database.

val insert : t -> key:key -> value:value -> (value Core.Option.t, Errors.t) Core.Result.t

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.

val delete : t -> key -> (value Core.Option.t, Errors.t) Core.Result.t

delete db k removes k from the database and returns the previous binding if it was set alongside the updated handler to the database.

val update_fetch : t -> key -> f:(value Core.Option.t -> value) -> (value Core.Option.t, Errors.t) Core.Result.t

update_fetch bucket k f checks if the binding for k exists, applies f to the binding and returns the new value.

val fetch_update : t -> key -> f:(value Core.Option.t -> value) -> (value Core.Option.t, Errors.t) Core.Result.t

fetch_update bucket k f checks if the binding for k exists, applies f to the binding and returns the old value.