Packages

The Phi Programming Language

Current section

Files

Jump to
phi stdlib Database DETS.phi
Raw

stdlib/Database/DETS.phi

-----------------------------------------------------------------------------
-- |
-- Module : Database.DETS
-- Copyright : (c) 2020-2021 EMQ Technologies Co., Ltd.
-- License : BSD-style (see the LICENSE file)
--
-- Maintainer : Feng Lee, feng@emqx.io
-- Yang M, yangm@emqx.io
-- Stability : experimental
-- Portability : portable
--
-- The Erlang DETS database.
--
-----------------------------------------------------------------------------
module Database.DETS where
import Control.Monad (IO)
import Data.Maybe (Maybe)
import Data.Pid (Pid)
import Data.Unit (Unit)
import Database.ETS as ETS
import System.IO (FilePath)
import Foreign (ffiIO0, ffiIO1, ffiIO2, ffiIO3)
type TableName = Atom
type TableInfo =
{ fileSize :: Integer
, fileName :: FilePath
, keyPos :: Integer
, size :: Integer
, tableType :: ETS.TableType
}
data Option
= AccessRead
| AccessReadWrite
| AutoSaveInfinity
| AutoSave Integer
| EstimatedNoObjects Integer
| File FilePath
| MaxNoSlots Integer
| MinNoSlots Integer
| Keypos Integer
| RamFile Boolean
| RepairForce
| Repair Boolean
| Bag
| DuplicateBag
| Set
all :: IO [TableName]
all = ffiIO0 :dets :all
close :: TableName -> IO ()
close = ffiIO1 :dets :close
foreign import delete :: forall k. TableName -> k -> IO ()
foreign import deleteAllObjects :: TableName -> IO ()
foreign import deleteObject :: TableName -> IO ()
foreign import first :: TableName -> forall k. IO (Maybe k)
foreign import next :: forall k. TableName -> k -> IO (Maybe k)
foreign import fromETS :: TableName -> ETS.TableId -> IO ()
foreign import info :: TableName -> IO (Maybe TableInfo)
foreign import insert :: forall v. TableName -> [v] -> IO ()
foreign import insertNew :: forall v. TableName -> [v] -> IO Boolean
foreign import lookup :: forall k v. TableName -> k -> IO [v]
foreign import toETS :: TableName -> ETS.TableId -> IO ()
foreign import foldl :: forall v acc. (v -> acc -> acc) -> acc -> TableName -> IO acc
foreign import foldr :: forall v acc. (v -> acc -> acc) -> acc -> TableName -> IO acc
foreign import infoWith :: TableName -> Atom -> IO (Maybe TableInfo)
isCompatibleBchunkFormat :: TableName -> Binary -> IO Boolean
isCompatibleBchunkFormat = ffiIO2 :dets :is_compatible_bchunk_format
foreign import isDetsFile :: FilePath -> IO Boolean
foreign import match :: forall a v. TableName -> a -> IO [v]
foreign import data Continuation :: Type
foreign import matchContinuation :: forall v. Continuation -> IO (Maybe ([v], Continuation))
foreign import matchWithLimit :: forall a v. TableName -> a -> Integer -> IO (Maybe ([v], Continuation))
foreign import matchDelete :: forall a. TableName -> a -> IO ()
foreign import matchObject :: forall a v. TableName -> a -> IO [v]
foreign import matchObjectContinuation :: forall v. Continuation -> IO (Maybe ([v], Continuation))
foreign import matchObjectWithLimit :: forall a v. TableName -> a -> Integer -> IO (Maybe ([v], Continuation))
foreign import openFile :: TableName -> [Option] -> IO TableName
foreign import pid2Name :: Pid -> IO (Maybe TableName)
safeFixtable :: TableName -> Boolean -> IO ()
safeFixtable = ffiIO2 :dets :safe_fixtable
foreign import slot :: forall v. TableName -> Integer -> IO (Maybe [v])
foreign import sync :: TableName -> IO ()
updateCounter :: forall k. TableName -> k -> Integer -> IO Integer
updateCounter = ffiIO3 :dets :update_counter
{- TODO
bchunk/2
init_table/2
init_table/3
open_file/1
repair_continuation/2
select/1
select/2
select/3
select_delete/2
table/1
table/2
traverse/2
-}