KyotoCabinet-0.1: Kyoto Cabinet DB bindings

Safe HaskellNone

Database.KyotoCabinet.Db

Contents

Description

Kyoto Cabinet DB bindings. All IO monad functions can throw KcException.

This documentation is not a complete description of the Kyoto Cabinet DB interface. You will need to refer to Kyoto Cabinet DB's C API documentation for the details: http://fallabs.com/kyotocabinet/

Synopsis

Types

data KcDb Source

Polymorphic database.

data KcCur Source

Polymorphic cursor.

Instances

Eq KcCur 

data KcError Source

Error codes.

Constructors

KCESUCCESS

success

KCENOIMPL

not implemented

KCEINVALID

invalid operation

KCENOREPOS

no repository

KCENOPERM

no permission

KCEBROKEN

broken file

KCEDUPREC

record duplication

KCENOREC

no record

KCELOGIC

logical inconsistency

KCESYSTEM

system error

KCEMISC

miscellaneous error

KCUNKNOWNERROR Int 

Instances

Eq KcError 
Show KcError 

data KcTune Source

Tuning parameters for database creation.

Constructors

KcTuneType KcTuneType 
KcTuneLogger KcLogger 
KcTuneLogKinds KcLogLevel 
KcTuneLogPx String 
KcTuneOptions [KcOption]

supported by: cache hash, cache tree, file hash, file tree, directory hash, directory tree

KcTuneBuckets Int

supported by: cache hash, cache tree, file hash, file tree

KcTuneCompressor KcCompressor

supported by: cache hash, cache tree, file hash, file tree, directory hash, directory tree

KcTuneZkey String

supported by: cache hash, cache tree, file hash, file tree, directory hash, directory tree

KcTuneCapCount Int

supported by: cache hash

KcTuneCapSize Int

supported by: cache hash

KcTunePage Int

supported by: cache tree, file tree, directory tree

KcTuneComparator KcComparator

supported by: cache tree, file tree, directory tree

KcTunePageCache Int

supported by: cache tree, file tree, directory tree

KcTuneAlignment Int

supported by: file hash, file tree

KcTuneFbp Int

supported by: file hash, file tree

KcTuneMap Int

supported by: file hash, file tree

KcTuneDefrag Int

supported by: file hash, file tree

Instances

Show KcTune 

data KcLogger Source

Instances

Show KcLogger 

data KcOpenMode Source

Open modes.

Constructors

KCOREADER

open as a reader

KCOWRITER

open as a writer

KCOCREATE

writer creating

KCOTRUNCATE

writer truncating

KCOAUTOTRAN

auto transaction

KCOAUTOSYNC

auto synchronization

KCONOLOCK

open without locking

KCOTRYLOCK

lock without blocking

KCONOREPAIR

open without auto repair

Instances

data KcMergeMode Source

Merge modes.

Constructors

KCMSET

overwrite the existing value

KCMADD

keep the existing value

KCMREPLACE

modify the existing record only

KCMAPPEND

append the new value

Instances

data KcException Source

An exception indicating an error in a KC operation.

Constructors

KcException String KcError String 

Instances

Eq KcException 
Show KcException 
Typeable KcException 
Exception KcException 

data KcVisitAction Source

Return one of these from KcVisitFull, KcVisitEmpty or KcFileProc to update the database after a visitor access.

Constructors

KCVISNOP 
KCVISSET ByteString 
KCVISREMOVE 

type KcVisitFull = ByteString -> ByteString -> IO KcVisitActionSource

Type of a visitor function when key-value is present.

type KcVisitEmpty = ByteString -> IO KcVisitActionSource

Type of a visitor function when key-value is absent.

type KcFileProc = FilePath -> Int64 -> Int64 -> IO BoolSource

Type of a database synchronization callback.

Utilities

Most of these routines are probably not needed by haskell users, but are included for completeness.

kcversion :: IO StringSource

Current KC version.

kcmalloc :: Int -> IO (Ptr a)Source

Allocate a region on memory.

kcfree :: Ptr a -> IO ()Source

Release a region allocated in the library.

kctime :: IO DoubleSource

Get the time of day in seconds.

kcatoi :: String -> IO Int64Source

Convert a string to an integer.

kcatoix :: String -> IO Int64Source

Convert a string with a metric prefix to an integer.

kcatof :: String -> IO DoubleSource

Convert a string to a real number.

kchashmurmur :: ByteString -> IO Int64Source

Get the hash value by MurMur hashing.

kchashfnv :: ByteString -> IO Int64Source

Get the hash value by FNV hashing.

kcnan :: IO DoubleSource

Get the quiet Not-a-Number value.

kcinf :: IO DoubleSource

Get the positive infinity value.

kcchknan :: Double -> IO BoolSource

Check a number is a Not-a-Number value.

kcchkinf :: Double -> IO BoolSource

Check a number is an infinity value.

kcecodename :: Int -> IO StringSource

Get the readable string of an error code.

DB Operations

kcdbnew :: IO KcDbSource

Create a polymorphic database object.

kcdbdel :: KcDb -> IO ()Source

Destroy a database object.

kcdbopenSource

Arguments

:: KcDb

db - a database object.

-> String

path - the path of a database file.

  • 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 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.
  • Otherwise, this function fails.
-> [KcTune]

tune - tuning parameters.

-> [KcOpenMode]

mode - the connection mode flags. KCOWRITER as a writer, KCOREADER as a reader. The following flags may be added to the writer mode:

  • KCOCREATE, which means it creates a new database if the file does not exist,
  • KCOTRUNCATE, which means it creates a new database regardless if the file exists,
  • KCOAUTOTRAN, which means each updating operation is performed in implicit transaction,
  • KCOAUTOSYNC, which means each updating operation is followed by implicit synchronization with the file system.

The following flags may be added to both of the reader mode and the writer mode:

  • KCONOLOCK, which means it opens the database file without file locking,
  • KCOTRYLOCK, which means locking is performed without blocking,
  • KCONOREPAIR, which means the database file is not repaired implicitly even if file destruction is detected.
-> IO ()

Returns () on success, throws KcException on failure.

Every opened database must be closed by the kcdbclose method when it is no longer in use. It is not allowed for two or more database objects in the same process to keep their connections to the same database file at the same time.

Open a database file.

kcdbclose :: KcDb -> IO ()Source

Close the database file.

kcdbecode :: KcDb -> IO KcErrorSource

Get the code of the last happened error.

kcdbemsg :: KcDb -> IO StringSource

Get the supplement message of the last happened error.

kcdbacceptSource

Arguments

:: KcDb 
-> ByteString

key

-> KcVisitFull 
-> KcVisitEmpty 
-> Bool

writable

-> IO () 

Accept a visitor to a record.

kcdbacceptbulkSource

Arguments

:: KcDb 
-> [ByteString]

keys

-> KcVisitFull 
-> KcVisitEmpty 
-> Bool

writable

-> IO () 

Accept a visitor to multiple records at once.

kcdbiterateSource

Arguments

:: KcDb 
-> KcVisitFull 
-> Bool

writable

-> IO () 

Iterate to accept a visitor for each record.

kcdbsetSource

Arguments

:: KcDb 
-> ByteString

key

-> ByteString

value

-> IO () 

Set the value of a record.

kcdbaddSource

Arguments

:: KcDb 
-> ByteString

key

-> ByteString

value

-> IO () 

Add a record.

kcdbreplaceSource

Arguments

:: KcDb 
-> ByteString

key

-> ByteString

value

-> IO () 

Replace the value of a record.

kcdbappendSource

Arguments

:: KcDb 
-> ByteString

key

-> ByteString

value

-> IO () 

Append the value of a record.

kcdbincrintSource

Arguments

:: KcDb 
-> ByteString

key

-> Int64

increment amount

-> IO Int64 

Add a number to the numeric value of a record.

kcdbincrdoubleSource

Arguments

:: KcDb 
-> ByteString

key

-> Double

increment amount

-> IO Double 

Add a number to the numeric value of a record.

kcdbcasSource

Arguments

:: KcDb 
-> ByteString

key

-> ByteString

old value

-> ByteString

new value

-> IO () 

Perform compare-and-swap.

kcdbremoveSource

Arguments

:: KcDb 
-> ByteString

key

-> IO () 

Remove a record.

kcdbgetSource

Arguments

:: KcDb 
-> ByteString

key

-> IO (Maybe ByteString) 

Retrieve the value of a record.

kcdbgetbufSource

Arguments

:: KcDb 
-> ByteString

key

-> Int

max chars to retrieve

-> IO (Maybe ByteString) 

Retrieve the value of a record.

kcdbsetbulkSource

Arguments

:: KcDb 
-> [(ByteString, ByteString)]

records to store

-> Bool

atomic

-> IO Int64

returns number of records stored

Store records at once.

kcdbremovebulkSource

Arguments

:: KcDb 
-> [ByteString]

keys of records to remove

-> Bool

atomic

-> IO Int64

returns number of records removed

Remove records at once.

kcdbgetbulkSource

Arguments

:: KcDb 
-> [ByteString]

keys of the records to retrieve

-> Bool

atomic

-> IO [(ByteString, ByteString)] 

Retrieve records at once.

kcdbclear :: KcDb -> IO ()Source

Remove all records.

kcdbsyncSource

Arguments

:: KcDb 
-> Bool

True for physical synchronization, False for logical synchronization

-> KcFileProc

postprocessor callback

-> IO () 

Synchronize updated contents with the file and the device.

kcdbcopySource

Arguments

:: KcDb 
-> FilePath

path to the destination file

-> IO () 

Create a copy of the database file.

kcdbbegintranSource

Arguments

:: KcDb 
-> Bool

True for physical synchronization, False for logical synchronization

-> IO () 

Begin transaction.

kcdbbegintrantrySource

Arguments

:: KcDb 
-> Bool

True for physical synchronization, False for logical synchronization

-> IO () 

Try to begin transaction.

kcdbendtranSource

Arguments

:: KcDb 
-> Bool

True to commit, False to abort

-> IO () 

End transaction.

kcdbdumpsnapSource

Arguments

:: KcDb 
-> FilePath

destination file

-> IO () 

Dump records into a file.

kcdbloadsnapSource

Arguments

:: KcDb 
-> FilePath

source file

-> IO () 

Load records from a file.

kcdbcount :: KcDb -> IO Int64Source

Get the number of records.

kcdbsize :: KcDb -> IO Int64Source

Get the size of the database file.

kcdbpath :: KcDb -> IO StringSource

Get the path of the database file.

kcdbstatus :: KcDb -> IO StringSource

Get the miscellaneous status information.

kcdbmatchprefixSource

Arguments

:: KcDb 
-> ByteString

prefix

-> Int

max elements to return

-> IO [ByteString] 

Get keys matching a prefix string.

kcdbmatchregexSource

Arguments

:: KcDb 
-> ByteString

regexp

-> Int

max elements to return

-> IO [ByteString] 

Get keys matching a regular expression string.

kcdbmergeSource

Arguments

:: KcDb 
-> [KcDb]

database sources

-> KcMergeMode

merge mode:

  • KCMSET to overwrite the existing value,
  • KCMADD to keep the existing value,
  • KCMREPLACE to modify the existing record only,
  • KCMAPPEND to append the new value.
-> IO () 

Merge records from other databases.

Cursor Operations

kcdbcursor :: KcDb -> IO KcCurSource

Create a cursor object.

kccurdel :: KcCur -> IO ()Source

Destroy a cursor object.

kccuracceptSource

Arguments

:: KcCur 
-> KcVisitFull 
-> Bool

writable

-> Bool

step

-> IO () 

Accept a visitor to the current record.

kccurremove :: KcCur -> IO ()Source

Remove the current record.

kccurgetkeySource

Arguments

:: KcCur 
-> Bool

step

-> IO ByteString 

Get the key of the current record.

kccurgetvalueSource

Arguments

:: KcCur 
-> Bool

step

-> IO ByteString 

Get the value of the current record.

kccurgetSource

Arguments

:: KcCur 
-> Bool

step

-> IO (ByteString, ByteString) 

Get a pair of the key and the value of the current record.

kccurjump :: KcCur -> IO ()Source

Jump the cursor to the first record for forward scan.

kccurjumpkey :: KcCur -> ByteString -> IO ()Source

Jump the cursor to a record for forward scan.

kccurjumpback :: KcCur -> IO ()Source

Jump the cursor to the last record for backward scan.

kccurjumpbackkey :: KcCur -> ByteString -> IO ()Source

Jump the cursor to a record for backward scan.

kccurstep :: KcCur -> IO ()Source

Step the cursor to the next record.

kccurstepback :: KcCur -> IO ()Source

Step the cursor to the previous record.

kccurdb :: KcCur -> IO KcDbSource

Get the database object.

kccurecode :: KcCur -> IO KcErrorSource

Get the code of the last happened error.

kccuremsg :: KcCur -> IO StringSource

Get the supplement message of the last happened error.

Scoped Operations

kcwithdbopen :: FilePath -> [KcTune] -> [KcOpenMode] -> (KcDb -> IO a) -> IO aSource

Brackets a db command between kcdbnew, kcdbopen, kcdbclose, and kcdbdel calls.

kcwithdbcursor :: KcDb -> (KcCur -> IO a) -> IO aSource

Brackets a cursor command between kcdbcursor and kccurdel calls.

kcwithdbtranSource

Arguments

:: KcDb 
-> Bool

True for physical synchronization, False for logical synchronization

-> IO a

db command

-> IO a 

Brackets a db command between kcdbbegintran and kcdbendtran calls, committing on successful completion of the command, and aborting on exception.