open :: HasLogFunc e => FilePath -> RIO e EventLog
open dir = do
    logDebug $ display (pack @Text $ "Opening LMDB database: " <> dir)
    env       <- rawOpen dir
    (m, e, f) <- openTables env
    id        <- getIdent env m
    logDebug $ display (pack @Text $ "Log Identity: " <> show id)
    numEvs    <- getNumEvents env e
    EventLog env m e f id <$> newIORef numEvs
  where
    openTables env =
      rwith (writeTxn env) $ \txn -> io $
        (,,) <$> mdb_dbi_open txn (Just "META")    []
             <*> mdb_dbi_open txn (Just "EVENTS")  [MDB_INTEGERKEY]
             <*> mdb_dbi_open txn (Just "EFFECTS") [MDB_CREATE, MDB_INTEGERKEY]
open :: HasLogFunc e => FilePath -> RIO e EventLog
open dir = do
    logDebug $ display (pack @Text $ "Opening LMDB database: " <> dir)
    env       <- rawOpen dir
    (m, e, f) <- openTables env
    id        <- getIdent env m
    logDebug $ display (pack @Text $ "Log Identity: " <> show id)
    numEvs    <- getNumEvents env e
    EventLog env m e f id <$> newIORef numEvs
  where
    openTables env =
      rwith (writeTxn env) $ \txn -> io $
        (,,) <$> mdb_dbi_open txn (Just "META")    []
             <*> mdb_dbi_open txn (Just "EVENTS")  [MDB_INTEGERKEY]
             <*> mdb_dbi_open txn (Just "EFFECTS") [MDB_CREATE, MDB_INTEGERKEY]
open dir = do
    logDebug $ display (pack @Text $ "Opening LMDB database: " <> dir)
    env       <- rawOpen dir
    (m, e, f) <- openTables env
    id        <- getIdent env m
    logDebug $ display (pack @Text $ "Log Identity: " <> show id)
    numEvs    <- getNumEvents env e
    EventLog env m e f id <$> newIORef numEvs
  where
    openTables env =
      rwith (writeTxn env) $ \txn -> io $
        (,,) <$> mdb_dbi_open txn (Just "META")    []
             <*> mdb_dbi_open txn (Just "EVENTS")  [MDB_INTEGERKEY]
             <*> mdb_dbi_open txn (Just "EFFECTS") [MDB_CREATE, MDB_INTEGERKEY]