Module AnyDBM


module AnyDBM: sig .. end
Generic interface for DBM modules

This module is used to provide a generic interface to various local flat-file modules in OCaml. Various AnyDBM implementations will use these definitions.

You can use AnyDBM in your own code with code using something like this:

open AnyDBM;;
let db = AnyDBM_String.dbm "/tmp/foo" 
         {read = true; write = true; create = true} 0o644;;
add db "key" "value";;
close db;;

You can use the Dbm compatibility features like this:

open AnyDBM;;
let db = AnyDBM_Dbm.opendbm "/tmp/foo" [Dbm_rdwr; Dbm_create] 0o644;;
add db "key" "value";;
close db;;

Standard modules implementing the AnyDBM interface include:

The interface in this module is designed to be a drop-in replacement for the system's Dbm module. You can, in fact, replace open Dbm with open AnyDBM, and adjust your opendbm calls, and have a transparent replacement.

Certain modules -- most notably those that do not work with files on disk -- may not behave in the same way when created.

NOTE: You MUST call close on a database handle if you want to make sure changes are written. Database module drivers may or may not write changes to disk if you do not call close.



Typs and Exceptions


type anydbm_open_flag = {
   read : bool; (*Whether reading is permitted*)
   write : bool; (*Whether writing is permitted*)
   create : bool; (*Whether to create a non-existing file*)
}
Flags used for opening a database.

type open_flag =
| Dbm_rdonly (*Read-only mode*)
| Dbm_wronly (*Write-only mode*)
| Dbm_rdwr (*Read/write mode*)
| Dbm_create (*Create file if it doesn't exist*)
Flags for historic compatibility with Dbm.
class virtual t : object .. end
Implementations of AnyDBM must provide an implementing object of type t.
exception Dbm_error of string

Standard Functions

val close : t -> unit
Close the connection to the database, saving any unsaved changes. NOTE: AnyDBM modules are not guaranteed to write out their data unless you call close!
val find : t -> string -> string
Returns the data associated with the given key or raises Not_found if the key is not present.
val add : t -> string -> string -> unit
Adds the key/data pair given. Raises AnyDBM.Dbm_error "Entry already exists" if the key is already present.
val replace : t -> string -> string -> unit
Add the key/value pair to the database, replacing any existing pair with the same key.
val remove : t -> string -> unit
Remove the key/value pair with the given key. If there is no such key, raises AnyDBM.Dbm_error "dbm_delete".
val iter : (string -> string -> unit) -> t -> unit
iter f db applies f to each (key, data) pair in the database db. f receives key as frist argument and data as second argument.
module AnyDBMUtils: sig .. end
Utilities for AnyDBM module implementators