tokyocabinet-haskell-0.0.5: Haskell binding of Tokyo CabinetContentsIndex
Database.TokyoCabinet.TDB
Description
Interface to the table database. See also, http://tokyocabinet.sourceforge.net/spex-en.html#tctdbapi for details
Synopsis
data TDB
data ECODE
= ESUCCESS
| ETHREAD
| EINVALID
| ENOFILE
| ENOPERM
| EMETA
| ERHEAD
| EOPEN
| ECLOSE
| ETRUNC
| ESYNC
| ESTAT
| ESEEK
| EREAD
| EWRITE
| EMMAP
| ELOCK
| EUNLINK
| ERENAME
| EMKDIR
| ERMDIR
| EKEEP
| ENOREC
| EMISC
data OpenMode
= OREADER
| OWRITER
| OCREAT
| OTRUNC
| ONOLCK
| OLCKNB
| OTSYNC
data TuningOption
= TLARGE
| TDEFLATE
| TBZIP
| TTCBS
| TEXCODEC
data IndexType
= ITLEXICAL
| ITDECIMAL
| ITOPT
| ITVOID
| ITKEEP IndexType
newtype AssocList k v = AssocList {
unAssocList :: [(k, v)]
}
new :: IO TDB
delete :: TDB -> IO ()
ecode :: TDB -> IO ECODE
errmsg :: ECODE -> String
tune :: TDB -> Int64 -> Int8 -> Int8 -> [TuningOption] -> IO Bool
setcache :: TDB -> Int32 -> Int32 -> Int32 -> IO Bool
setxmsiz :: TDB -> Int64 -> IO Bool
open :: TDB -> String -> [OpenMode] -> IO Bool
close :: TDB -> IO Bool
put :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
put' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
putkeep :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
putkeep' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
putcat :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
putcat' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
out :: Storable k => TDB -> k -> IO Bool
get :: (Storable k, Storable v, Associative m) => TDB -> k -> IO (m k v)
get' :: (Storable k, Storable v) => TDB -> k -> IO (Maybe v)
vsiz :: Storable k => TDB -> k -> IO (Maybe Int)
iterinit :: TDB -> IO Bool
iternext :: Storable k => TDB -> IO (Maybe k)
fwmkeys :: (Storable k1, Storable k2, Sequence q) => TDB -> k1 -> Int -> IO (q k2)
addint :: Storable k => TDB -> k -> Int -> IO (Maybe Int)
adddouble :: Storable k => TDB -> k -> Double -> IO (Maybe Double)
sync :: TDB -> IO Bool
optimize :: TDB -> Int64 -> Int8 -> Int8 -> [TuningOption] -> IO Bool
vanish :: TDB -> IO Bool
copy :: TDB -> String -> IO Bool
tranbegin :: TDB -> IO Bool
trancommit :: TDB -> IO Bool
tranabort :: TDB -> IO Bool
path :: TDB -> IO (Maybe String)
rnum :: TDB -> IO Word64
fsiz :: TDB -> IO Word64
setindex :: TDB -> String -> IndexType -> IO Bool
genuid :: TDB -> IO (Maybe Int64)
Documentation

Example

  import Control.Monad (unless)
  import Database.TokyoCabinet.TDB
  import Database.TokyoCabinet.TDB.Query hiding (new)
  import qualified Database.TokyoCabinet.Map as M
  import qualified Database.TokyoCabinet.TDB.Query as Q (new)
  data Profile = Profile { name :: String
                         , age  :: Int } deriving Show
  insertProfile :: TDB -> Profile -> IO Bool
  insertProfile tdb profile =
      do m <- M.new
         M.put m "name" (name profile)
         M.put m "age" (show . age $ profile)
         Just pk <- genuid tdb
         put tdb (show pk) m
  main :: IO ()
  main = do t <- new
            open t "foo.tct" [OWRITER, OCREAT] >>= err t
            mapM_ (insertProfile t) [ Profile "tom" 23
                                    , Profile "bob" 24
                                    , Profile "alice" 20 ]
            q <- Q.new t
            addcond q "age" QCNUMGE "23"
            setorder q "name" QOSTRASC
            proc q $ pk cols -> do
              Just name <- M.get cols "name"
              putStrLn name
              M.put cols "name" (name ++ "!")
              return (QPPUT cols)
            close t >>= err t
            return ()
      where
        err tdb = flip unless $ ecode tdb >>= error . show
data TDB
show/hide Instances
data ECODE
Represents error
Constructors
ESUCCESSsuccess
ETHREADthreading error
EINVALIDinvalid operation
ENOFILEfile not found
ENOPERMno permission
EMETAinvalid meta data
ERHEADinvalid record header
EOPENopen error
ECLOSEclose error
ETRUNCtrunc error
ESYNCsync error
ESTATstat error
ESEEKseek error
EREADread error
EWRITEwrite error
EMMAPmmap error
ELOCKlock error
EUNLINKunlink error
ERENAMErename error
EMKDIRmkdir error
ERMDIRrmdir error
EKEEPexisting record
ENORECno record found
EMISCmiscellaneous error
show/hide Instances
data OpenMode
Represents open mode
Constructors
OREADERread only mode
OWRITERwrite mode
OCREATif this value is included in open mode list, `open function' creates a new database if not exist.
OTRUNCcreates a new database regardless if one exists
ONOLCKopen the database file without file locking
OLCKNBopen the database file with locking performed without blocking.
OTSYNCevery transaction synchronizes updated contents with the device
show/hide Instances
data TuningOption
Constructors
TLARGE
TDEFLATE
TBZIP
TTCBS
TEXCODEC
show/hide Instances
data IndexType
Represents the index type
Constructors
ITLEXICALfor lexical string
ITDECIMALfor decimal string
ITOPTthe index is optimized
ITVOIDthe index is removed
ITKEEP IndexTypeif the index exists, setindex function merely returns failure
show/hide Instances
newtype AssocList k v
Constructors
AssocList
unAssocList :: [(k, v)]
show/hide Instances
Associative AssocList
(Eq k, Eq v) => Eq (AssocList k v)
(Ord k, Ord v) => Ord (AssocList k v)
(Show k, Show v) => Show (AssocList k v)
new :: IO TDB
Create the new table database object.
delete :: TDB -> IO ()
Free object resource forcibly.
ecode :: TDB -> IO ECODE
Get the last happened error code.
errmsg :: ECODE -> String
Convert error code to message string.
tune
:: TDBTDB object
-> Int64the number of elements of the bucket array
-> Int8the size of record alignment by power of 2
-> Int8the maximum number of elements of the free block pool by power of 2
-> [TuningOption]options
-> IO Boolif successful, the return value is True.
Set the tuning parameters.
setcache
:: TDBTDB object
-> Int32the maximum number of records to be cached
-> Int32the maximum number of leaf nodes to be cached
-> Int32the maximum number of non-leaf nodes to be cached
-> IO Boolif successful, the return value is True.
Set the caching parameters of a table database object.
setxmsiz
:: TDBTDB object
-> Int64the size of the extra mapped memory
-> IO Boolif successful, the return value is True.
Set the size of the extra mapped memory of a table database object.
open :: TDB -> String -> [OpenMode] -> IO Bool
Open the table database file
close :: TDB -> IO Bool
Open the database file
put :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
Store a record into a table database object.
put' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
Store a string record into a table database object with a zero separated column string.
putkeep :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
Store a new record into a table database object.
putkeep' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
Store a new string record into a table database object with a zero separated column string.
putcat :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
Concatenate columns of the existing record in a table database object.
putcat' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
Concatenate columns in a table database object with a zero separated column string.
out :: Storable k => TDB -> k -> IO Bool
Remove a record of a table database object.
get :: (Storable k, Storable v, Associative m) => TDB -> k -> IO (m k v)
Retrieve a record in a table database object.
get' :: (Storable k, Storable v) => TDB -> k -> IO (Maybe v)
Retrieve a record in a table database object as a zero separated column string.
vsiz :: Storable k => TDB -> k -> IO (Maybe Int)
Get the size of the value of a record in a table database object.
iterinit :: TDB -> IO Bool
Initialize the iterator of a table database object.
iternext :: Storable k => TDB -> IO (Maybe k)
Get the next primary key of the iterator of a table database object.
fwmkeys :: (Storable k1, Storable k2, Sequence q) => TDB -> k1 -> Int -> IO (q k2)
Get forward matching primary keys in a table database object.
addint :: Storable k => TDB -> k -> Int -> IO (Maybe Int)
Add an integer to a column of a record in a table database object.
adddouble :: Storable k => TDB -> k -> Double -> IO (Maybe Double)
Add a real number to a column of a record in a table database object.
sync :: TDB -> IO Bool
Synchronize updated contents of a table database object with the file and the device.
optimize
:: TDBTDB object
-> Int64the number of elements of the bucket array
-> Int8the size of record alignment by power of 2
-> Int8the maximum number of elements of the free block pool by power of 2
-> [TuningOption]options
-> IO Boolif successful, the return value is True.
Optimize the file of a table database object.
vanish :: TDB -> IO Bool
Remove all records of a table database object.
copy
:: TDBTDB object
-> Stringnew file path
-> IO Boolif successful, the return value is True
Copy the database file of a table database object.
tranbegin :: TDB -> IO Bool
Begin the transaction of a table database object.
trancommit :: TDB -> IO Bool
Commit the transaction of a table database object.
tranabort :: TDB -> IO Bool
Abort the transaction of a table database object.
path :: TDB -> IO (Maybe String)
Get the file path of a table database object.
rnum :: TDB -> IO Word64
Get the number of records of a table database object.
fsiz :: TDB -> IO Word64
Get the size of the database file of a table database object.
setindex :: TDB -> String -> IndexType -> IO Bool
Set a column index to a table database object.
genuid :: TDB -> IO (Maybe Int64)
Generate a unique ID number of a table database object.
Produced by Haddock version 2.4.2