module Database.TokyoCabinet.TDB
(
TDB
, ECODE(..)
, OpenMode(..)
, TuningOption(..)
, IndexType(..)
, AssocList(..)
, new
, delete
, ecode
, errmsg
, tune
, setcache
, setxmsiz
, open
, close
, put
, put'
, putkeep
, putkeep'
, putcat
, putcat'
, out
, get
, get'
, vsiz
, iterinit
, iternext
, fwmkeys
, addint
, adddouble
, sync
, optimize
, vanish
, copy
, tranbegin
, trancommit
, tranabort
, path
, rnum
, fsiz
, setindex
, genuid
) where
import Database.TokyoCabinet.Map.C
import Database.TokyoCabinet.TDB.C
import Database.TokyoCabinet.Error
import Database.TokyoCabinet.Internal
import Database.TokyoCabinet.Storable
import Database.TokyoCabinet.Associative
import Database.TokyoCabinet.Sequence
import Data.Int
import Data.Word
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.C.Types
import Foreign.C.String
new :: IO TDB
new = TDB `fmap` (c_tctdbnew >>= newForeignPtr tctdbFinalizer)
delete :: TDB -> IO ()
delete tdb = finalizeForeignPtr (unTCTDB tdb)
ecode :: TDB -> IO ECODE
ecode tdb = cintToError `fmap` withForeignPtr (unTCTDB tdb) c_tctdbecode
tune :: TDB
-> Int64
-> Int8
-> Int8
-> [TuningOption]
-> IO Bool
tune tdb bnum apow fpow opts =
withForeignPtr (unTCTDB tdb) $ \tdb' ->
c_tctdbtune tdb' bnum apow fpow (combineTuningOption opts)
setcache :: TDB
-> Int32
-> Int32
-> Int32
-> IO Bool
setcache tdb rcnum lcnum ncnum =
withForeignPtr (unTCTDB tdb) $ \tdb' ->
c_tctdbsetcache tdb' rcnum lcnum ncnum
setxmsiz :: TDB
-> Int64
-> IO Bool
setxmsiz tdb xmsiz = withForeignPtr (unTCTDB tdb) (flip c_tctdbsetxmsiz xmsiz)
open :: TDB -> String -> [OpenMode] -> IO Bool
open = openHelper c_tctdbopen unTCTDB combineOpenMode
close :: TDB -> IO Bool
close tdb = withForeignPtr (unTCTDB tdb) c_tctdbclose
type FunPut' = Ptr TDB' -> Ptr Word8 -> CInt -> Ptr MAP -> IO Bool
putHelper' :: (Storable k, Storable v, Associative m) =>
FunPut' -> TDB -> v -> m k v -> IO Bool
putHelper' c_putfunc tdb key vals =
withForeignPtr (unTCTDB tdb) $ \tdb' ->
withPtrLen key $ \(kbuf, ksize) ->
withMap vals $ c_putfunc tdb' kbuf ksize
put :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
put = putHelper' c_tctdbput
put' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
put' = putHelper c_tctdbput2 unTCTDB
putkeep :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
putkeep = putHelper' c_tctdbputkeep
putkeep' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
putkeep' = putHelper c_tctdbputkeep2 unTCTDB
putcat :: (Storable k, Storable v, Associative m) => TDB -> v -> m k v -> IO Bool
putcat = putHelper' c_tctdbputcat
putcat' :: (Storable k, Storable v) => TDB -> k -> v -> IO Bool
putcat' = putHelper c_tctdbputcat2 unTCTDB
out :: (Storable k) => TDB -> k -> IO Bool
out = outHelper c_tctdbout unTCTDB
get :: (Storable k, Storable v, Associative m) => TDB -> k -> IO (m k v)
get tdb key =
withForeignPtr (unTCTDB tdb) $ \tdb' ->
withPtrLen key $ \(kbuf, ksize) ->
c_tctdbget tdb' kbuf ksize >>= peekMap'
get' :: (Storable k, Storable v) => TDB -> k -> IO (Maybe v)
get' = getHelper c_tctdbget2 unTCTDB
vsiz :: (Storable k) => TDB -> k -> IO (Maybe Int)
vsiz = vsizHelper c_tctdbvsiz unTCTDB
iterinit :: TDB -> IO Bool
iterinit tdb = withForeignPtr (unTCTDB tdb) c_tctdbiterinit
iternext :: (Storable k) => TDB -> IO (Maybe k)
iternext = iternextHelper c_tctdbiternext unTCTDB
fwmkeys :: (Storable k1, Storable k2, Sequence q) => TDB -> k1 -> Int -> IO (q k2)
fwmkeys = fwmHelper c_tctdbfwmkeys unTCTDB
addint :: (Storable k) => TDB -> k -> Int -> IO (Maybe Int)
addint = addHelper c_tctdbaddint unTCTDB fromIntegral fromIntegral (== cINT_MIN)
adddouble :: (Storable k) => TDB -> k -> Double -> IO (Maybe Double)
adddouble = addHelper c_tctdbadddouble unTCTDB realToFrac realToFrac isNaN
sync :: TDB -> IO Bool
sync tdb = withForeignPtr (unTCTDB tdb) c_tctdbsync
optimize :: TDB
-> Int64
-> Int8
-> Int8
-> [TuningOption]
-> IO Bool
optimize tdb bnum apow fpow opts =
withForeignPtr (unTCTDB tdb) $ \tdb' ->
c_tctdboptimize tdb' bnum apow fpow (combineTuningOption opts)
vanish :: TDB -> IO Bool
vanish tdb = withForeignPtr (unTCTDB tdb) c_tctdbvanish
copy :: TDB
-> String
-> IO Bool
copy = copyHelper c_tctdbcopy unTCTDB
tranbegin :: TDB -> IO Bool
tranbegin tdb = withForeignPtr (unTCTDB tdb) c_tctdbtranbegin
trancommit :: TDB -> IO Bool
trancommit tdb = withForeignPtr (unTCTDB tdb) c_tctdbtrancommit
tranabort :: TDB -> IO Bool
tranabort tdb = withForeignPtr (unTCTDB tdb) c_tctdbtranabort
path :: TDB -> IO (Maybe String)
path = pathHelper c_tctdbpath unTCTDB
rnum :: TDB -> IO Word64
rnum tdb = withForeignPtr (unTCTDB tdb) c_tctdbrnum
fsiz :: TDB -> IO Word64
fsiz tdb = withForeignPtr (unTCTDB tdb) c_tctdbfsiz
setindex :: TDB -> String -> IndexType -> IO Bool
setindex tdb name itype =
withForeignPtr (unTCTDB tdb) $ \tdb' ->
withCString name $ \c_name ->
c_tctdbsetindex tdb' c_name (indexTypeToCInt itype)
genuid :: TDB -> IO (Maybe Int64)
genuid tdb = withForeignPtr (unTCTDB tdb) $ \tdb' -> do
uid <- c_tctdbgenuid tdb'
return $ if uid == (1) then Nothing else Just uid