module AnyDBM:sig
..end
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:
AnyDBM_String
, uses the persistent storage in Hashtblutil
AnyDBM_Dbm
, uses the system's Dbm module. Available only on systems that have the Dbm module available.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
.
type
anydbm_open_flag = {
|
read : |
(* | Whether reading is permitted | *) |
|
write : |
(* | Whether writing is permitted | *) |
|
create : |
(* | Whether to create a non-existing file | *) |
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 | *) |
class virtual t :object
..end
exception Dbm_error of string
val close : t -> unit
val find : t -> string -> string
Not_found
if the key is not present.val add : t -> string -> string -> unit
AnyDBM.Dbm_error
"Entry already exists"
if the key is already present.val replace : t -> string -> string -> unit
val remove : t -> string -> unit
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