module Database.TokyoCabinet.ADB
(
ADB
, ECODE(..)
, new
, delete
, open
, close
, put
, putkeep
, putcat
, out
, get
, vsiz
, iterinit
, iternext
, fwmkeys
, addint
, adddouble
, sync
, optimize
, vanish
, copy
, tranbegin
, trancommit
, tranabort
, path
, rnum
, size
, misc
) where
import Data.Word
import Foreign.C.String
import Foreign.ForeignPtr
import Database.TokyoCabinet.ADB.C
import Database.TokyoCabinet.Error
import Database.TokyoCabinet.Internal
import Database.TokyoCabinet.Storable
import Database.TokyoCabinet.Sequence
data ADB = ADB { unTCADB :: !(ForeignPtr ADB') }
new :: IO ADB
new = ADB `fmap` (c_tcadbnew >>= newForeignPtr tcadbFinalizer)
delete :: ADB -> IO ()
delete adb = finalizeForeignPtr (unTCADB adb)
open :: ADB -> String -> IO Bool
open adb name = withForeignPtr (unTCADB adb) $ (withCString name) . c_tcadbopen
close :: ADB -> IO Bool
close adb = withForeignPtr (unTCADB adb) c_tcadbclose
put :: (Storable k, Storable v) => ADB -> k -> v -> IO Bool
put = putHelper c_tcadbput unTCADB
putkeep :: (Storable k, Storable v) => ADB -> k -> v -> IO Bool
putkeep = putHelper c_tcadbputkeep unTCADB
putcat :: (Storable k, Storable v) => ADB -> k -> v -> IO Bool
putcat = putHelper c_tcadbputcat unTCADB
out :: (Storable k) => ADB -> k -> IO Bool
out = outHelper c_tcadbout unTCADB
get :: (Storable k, Storable v) => ADB -> k -> IO (Maybe v)
get = getHelper c_tcadbget unTCADB
vsiz :: (Storable k) => ADB -> k -> IO (Maybe Int)
vsiz = vsizHelper c_tcadbvsiz unTCADB
iterinit :: ADB -> IO Bool
iterinit adb = withForeignPtr (unTCADB adb) c_tcadbiterinit
iternext :: (Storable k) => ADB -> IO (Maybe k)
iternext = iternextHelper c_tcadbiternext unTCADB
fwmkeys :: (Storable k1, Storable k2, Sequence q) =>
ADB -> k1 -> Int -> IO (q k2)
fwmkeys = fwmHelper c_tcadbfwmkeys unTCADB
addint :: (Storable k) => ADB -> k -> Int -> IO (Maybe Int)
addint = addHelper c_tcadbaddint unTCADB fromIntegral fromIntegral (== cINT_MIN)
adddouble :: (Storable k) => ADB -> k -> Double -> IO (Maybe Double)
adddouble = addHelper c_tcadbadddouble unTCADB realToFrac realToFrac isNaN
sync :: ADB -> IO Bool
sync adb = withForeignPtr (unTCADB adb) c_tcadbsync
optimize :: ADB -> String -> IO Bool
optimize adb params =
withForeignPtr (unTCADB adb) $ (withCString params) . c_tcadboptimize
vanish :: ADB -> IO Bool
vanish adb = withForeignPtr (unTCADB adb) c_tcadbvanish
copy :: ADB -> String -> IO Bool
copy = copyHelper c_tcadbcopy unTCADB
tranbegin :: ADB -> IO Bool
tranbegin adb = withForeignPtr (unTCADB adb) c_tcadbtranbegin
trancommit :: ADB -> IO Bool
trancommit adb = withForeignPtr (unTCADB adb) c_tcadbtrancommit
tranabort :: ADB -> IO Bool
tranabort adb = withForeignPtr (unTCADB adb) c_tcadbtranabort
path :: ADB -> IO (Maybe String)
path = pathHelper c_tcadbpath unTCADB
rnum :: ADB -> IO Word64
rnum adb = withForeignPtr (unTCADB adb) c_tcadbrnum
size :: ADB -> IO Word64
size adb = withForeignPtr (unTCADB adb) c_tcadbsize
misc :: (Storable a, Storable b, Sequence q1, Sequence q2) =>
ADB -> String -> q1 a -> IO (q2 b)
misc adb name args =
withForeignPtr (unTCADB adb) $ \adb' ->
withCString name $ \name' ->
withList args $ \args' -> do
ret <- c_tcadbmisc adb' name' args'
peekList' ret