- data TCM a
- runTCM :: TCM a -> IO a
- data OpenMode
- class TCDB a where
- new :: TCM a
- delete :: a -> TCM ()
- open :: a -> String -> [OpenMode] -> TCM Bool
- close :: a -> TCM Bool
- put :: (Storable k, Storable v) => a -> k -> v -> TCM Bool
- putkeep :: (Storable k, Storable v) => a -> k -> v -> TCM Bool
- putcat :: (Storable k, Storable v) => a -> k -> v -> TCM Bool
- get :: (Storable k, Storable v) => a -> k -> TCM (Maybe v)
- out :: Storable k => a -> k -> TCM Bool
- vsiz :: Storable k => a -> k -> TCM (Maybe Int)
- iterinit :: a -> TCM Bool
- iternext :: Storable v => a -> TCM (Maybe v)
- fwmkeys :: (Storable k, Storable v, Sequence q) => a -> k -> Int -> TCM (q v)
- addint :: Storable k => a -> k -> Int -> TCM (Maybe Int)
- adddouble :: Storable k => a -> k -> Double -> TCM (Maybe Double)
- sync :: a -> TCM Bool
- vanish :: a -> TCM Bool
- copy :: a -> String -> TCM Bool
- path :: a -> TCM (Maybe String)
- rnum :: a -> TCM Word64
- size :: a -> TCM Word64
- ecode :: a -> TCM ECODE
- defaultExtension :: a -> String
- data HDB
- data FDB
- data TDB
- data BDB
- data ECODE
- errmsg :: ECODE -> String
Documentation
Basic Usage (sample code)
import Database.TokyoCabinet import Data.ByteString.Char8
putsample :: String -> [(ByteString, ByteString)] -> TCM Bool putsample file kv = do tc <- new :: TCM HDB -- alternatively you can use BDB or FDB open tc file [OWRITER, OCREAT] mapM (uncurry $ put tc) kv close tc
getsample :: String -> ByteString -> TCM (Maybe ByteString) getsample file key = do tc <- new :: TCM HDB -- alternatively you can use BDB or FDB open tc file [OREADER] val <- get tc key close tc return val
main = runTCM (do putsample "foo.tch" [(pack "foo", pack "bar")] getsample "foo.tch" (pack "foo")) >>= maybe (return ()) (putStrLn . show)
Represent open mode for open
function.
Type class that abstract Tokyo Cabinet database.
Create a database object.
Free object resource forcibly.
:: a | database object |
-> String | path to database file |
-> [OpenMode] | open mode |
-> TCM Bool | if successful, the return value is True |
Open a database file.
Close the database file. If successful, the return value is True
:: (Storable k, Storable v) | |
=> a | database object |
-> k | key |
-> v | value |
-> TCM Bool | if successful, the return value is True |
Store a record.
:: (Storable k, Storable v) | |
=> a | database object |
-> k | key |
-> v | value |
-> TCM Bool | if successful, the return value is True |
Store a new recoed. If a record with the same key exists in the database, this function has no effect.
:: (Storable k, Storable v) | |
=> a | database object |
-> k | key |
-> v | value |
-> TCM Bool | if successful, the return value is True |
Concatenate a value at the end of the existing record.
:: (Storable k, Storable v) | |
=> a | database object |
-> k | key |
-> TCM (Maybe v) | If successful, the return value is the
value of the corresponding record wrapped
by |
Retrieve a record.
Remove a record.
:: Storable k | |
=> a | database object |
-> k | key |
-> TCM (Maybe Int) | If successful, the return value
is the size of the value of the
corresponding record wrapped by
|
Get the size of the value of a record.
iterinit :: a -> TCM BoolSource
Initialize the iterator. If successful, the return value is True.
iternext :: Storable v => a -> TCM (Maybe v)Source
Get the next key of the iterator. If successful, the return
value is the next key wrapped by Just
, else, it is Nothing.
:: (Storable k, Storable v, Sequence q) | |
=> a | database object |
-> k | search string |
-> Int | the maximum number of keys to be fetched |
-> TCM (q v) | result keys |
Get forward matching keys.
:: Storable k | |
=> a | database object |
-> k | key |
-> Int | the addtional value |
-> TCM (Maybe Int) | If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. |
Add an integer to a record.
:: Storable k | |
=> a | database object |
-> k | key |
-> Double | the additional value |
-> TCM (Maybe Double) | If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. |
Add a real number to a record.
Synchronize updated contents with the file and the device. If successful, the return value is True.
Remove all records. If successful, the return value is True.
:: a | database object |
-> String | path of the destination file |
-> TCM Bool | If successful, the return value is True. |
Copy the database file.
path :: a -> TCM (Maybe String)Source
Get the path of the database file.
Get the number of records.
Get the size of the database file.
Get the last happened error code.
defaultExtension :: a -> StringSource
Get the default extension for specified database object.
Error Code
Represents error
ESUCCESS | success |
ETHREAD | threading error |
EINVALID | invalid operation |
ENOFILE | file not found |
ENOPERM | no permission |
EMETA | invalid meta data |
ERHEAD | invalid record header |
EOPEN | open error |
ECLOSE | close error |
ETRUNC | trunc error |
ESYNC | sync error |
ESTAT | stat error |
ESEEK | seek error |
EREAD | read error |
EWRITE | write error |
EMMAP | mmap error |
ELOCK | lock error |
EUNLINK | unlink error |
ERENAME | rename error |
EMKDIR | mkdir error |
ERMDIR | rmdir error |
EKEEP | existing record |
ENOREC | no record found |
EMISC | miscellaneous error |