package kyotocabinet

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type db

A key,value store database.

type cursor

A cursor used to iterate over (key,value) pairs.

exception Error of string

Exception raised when something gone wrong with the database.

type open_flag =
  1. | OREADER
  2. | OWRITER
  3. | OCREATE
  4. | OTRUNCATE
  5. | OAUTOTRAN
  6. | OAUTOSYNC
  7. | ONOLOCK
  8. | OTRYLOCK
  9. | ONOREPAIR
val opendb : string -> open_flag list -> db

Open a a database file.

The kind of the database is infered from the path, and tuning parameters can trail the path. These conventions are inherited from kyotocabinet::PolyDB::open() : http://fallabs.com/kyotocabinet/api/classkyotocabinet_1_1PolyDB.html#a09384a72e6a72a0be98c80a1856f34aa

If it is "-", the database will be a prototype hash database. If it is "+", the database will be a prototype tree database. If it is ":", the database will be a stash database. If it is "*", the database will be a cache hash database. If it is "%", the database will be a cache tree database. If its suffix is ".kch", the database will be a file hash database. If its suffix is ".kct", the database will be a file tree database. If its suffix is ".kcd", the database will be a directory hash database. If its suffix is ".kcf", the database will be a directory tree database. If its suffix is ".kcx", the database will be a plain text database.

Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=".

If the "type" parameter is specified, the database type is determined by the value in "-", "+", ":", "*", "%", "kch", "kct", "kcd", "kcf", and "kcx".

The tuning parameter "log" specifies the path of the log file, or "-" for the standard output, or "+" for the standard error.

The parameter "logkinds" specifies kinds of logged messages and the value can be "debug", "info", "warn", or "error".

"logpx" specifies the prefix of each log message.

val close : db -> unit

Close the database file.

val with_db : string -> open_flag list -> (db -> 'a) -> 'a

with_db path flags f opens a database, calls f on this db and ensures the db is finally closed.

val count : db -> int64

Return the count of key, value pairs.

val size : db -> int64

Return the size of the database file.

val path : db -> string

Return the path of the database.

val status : db -> string

Return a string status of the database.

val exists : db -> string -> bool

exists db key checks if any data is associated to the given key in the database db.

val get : db -> string -> string option

get db key returns the data associated with the given key in the database db, if any.

val find : db -> string -> string

find db key returns the data associated with the given key, or raise Not_found if none is found.

val set : db -> string -> string -> unit

set db key data inserts the pair (key, data) in the database db.

If the database already contains data associated with the key, that data is discarded and silently replaced by the new data.

val add : db -> string -> string -> unit

add db key data inserts the pair (key, data) in the database db.

If the database already contains data associated with the key, it raises Invalid_Argument("Entry already exists").

val replace : db -> string -> string -> unit

replace db key data inserts the pair (key, data) in the database db.

If the database doesn't contain any data associated with the key, it raises Not_found.

val remove : db -> string -> unit

remove db key removes the data associated to the key in the database db.

If key has no associated data, simply do nothing.

val update : db -> ('a -> string) -> (string -> 'a -> string) -> string -> 'a -> unit

update db init plus key data updates the value associated to the given key.

If a previous value v is associated to the key, then the value to be inserted is computed after plus v data.

If there is no data associated to the key, then the value to be inserted is init data.

val fold : db -> ('a -> (string * string) -> 'a) -> 'a -> 'a

fold db combiner seed folds the whole content of the database db.

val fold_prefix : db -> string -> ('a -> (string * string) -> 'a) -> 'a -> 'a

fold db prefix combiner seed folds the (key,value) pairs having a key with the given prefix.

This is meaningful only for sorted databases, i.e. tree databases.

val fold_range : db -> string -> string -> ('a -> (string * string) -> 'a) -> 'a -> 'a

fold db (Some min_key) (Some max_key) combiner seed folds the (key,value) pairs having a key in the range min_key (inclusive) .. max_key (exclusive).

This is meaningful only for sorted databases, i.e. tree databases.

val cursor_open : db -> cursor

Open a cursor and jump to the first key,value pair if any.

Jump to the first key,value pair having a key greater than the given key.

val cursor_jump : cursor -> string -> unit

Jump to the first key,value pair having a key greater than the given key.

Read the next key,value pair if any.

val cursor_next : cursor -> (string * string) option

Read the next key,value pair if any.

Close the cursor.

val cursor_close : cursor -> unit

Close the cursor.

val with_cursor : db -> (cursor -> 'a) -> 'a

with_cursor db f opens a cursor, calls f on this cursor and ensures the cursor is finally closed.

val begin_tran : db -> unit

begin a transaction with no file synchronization (safe on process crash, but not system crash).

val begin_tran_sync : db -> unit

begin a transaction with file synchronization (safe on process or system crash).

val commit_tran : db -> unit

commit the current transaction

val abort_tran : db -> unit

abort the current transaction

val with_transaction : db -> (db -> 'a) -> 'a

Execution a function within a transaction.

val with_transaction_sync : db -> (db -> 'a) -> 'a

Execution a function within a transaction with file synchronization.