Renamed Database->TansuDB
Getty Ritter
9 years ago
| 4 | 4 | import Data.ByteString (ByteString) |
| 5 | 5 | import System.Directory (createDirectoryIfMissing) |
| 6 | 6 | |
| 7 |
import Database.Tansu.Internal ( |
|
| 7 | import Database.Tansu.Internal (TansuDb(..)) | |
| 8 | 8 | |
| 9 | 9 | bdbSet :: Db -> ByteString -> ByteString -> IO () |
| 10 | 10 | bdbSet db key val = |
| 14 | 14 | bdbGet db key = |
| 15 | 15 | db_get [] db Nothing key |
| 16 | 16 | |
| 17 |
withBerkeleyDb :: FilePath -> ( |
|
| 17 | withBerkeleyDb :: FilePath -> (TansuDb -> IO a) -> IO a | |
| 18 | 18 | withBerkeleyDb path comp = do |
| 19 | 19 | createDirectoryIfMissing True path |
| 20 | 20 | env <- dbEnv_create [] |
| 21 | 21 | dbEnv_open [DB_CREATE,DB_INIT_MPOOL,DB_INIT_TXN] 0 env path |
| 22 | 22 | db <- db_create [] env |
| 23 | 23 | db_open [DB_CREATE] DB_HASH 0 db Nothing path Nothing |
| 24 | result <- comp $ Database { dbGet = bdbGet db | |
| 25 | , dbSet = bdbSet db | |
| 26 | , dbRunTransaction = id | |
| 27 | } | |
| 24 | result <- comp $ TansuDb { dbGet = bdbGet db | |
| 25 | , dbSet = bdbSet db | |
| 26 | , dbRunTransaction = id | |
| 27 | } | |
| 28 | 28 | db_close [] db |
| 29 | 29 | dbEnv_close [] env |
| 30 | 30 | return result |