0 | module Oracle.Connection
2 | import Control.Monad.Elin
3 | import Control.Monad.MCancel
4 | import Data.Linear.Ref1
6 | import Oracle.FFI.Connection
7 | import Oracle.Internal.Pointer
8 | import Oracle.Types.ConnectInfo
9 | import Oracle.Types.Error
14 | connect : ConnectInfo -> IO (Either OracleError Connection)
16 | ptr <- primIO (prim__connect cfg.username cfg.password (connectString cfg))
17 | case prim__nullAnyPtr ptr == 1 of
19 | lasterr <- getLastError
22 | pure (Right (MkConnection ptr))
24 | connectString : ConnectInfo -> String
35 | disconnect : Connection -> IO ()
37 | primIO (prim__disconnect conn.ptr)
58 | withConnection : ConnectInfo -> (Connection -> IO (Either OracleError a)) -> IO (Either OracleError a)
59 | withConnection cfg action = do
60 | result <- runElinIO (withConnection' cfg)
69 | assert_total $
idris_crash "Oracle.Connection.withConnection: \{show err}"
71 | acquire : ConnectInfo -> F1 World (Either OracleError Connection)
73 | ioToF1 (connect cfg)
74 | use : Either OracleError Connection -> F1 World (Either OracleError a)
78 | ioToF1 (pure (Left err))
80 | ioToF1 (action conn')
81 | release : Either OracleError Connection -> F1' World
87 | ioToF1 (disconnect conn')
88 | withConnection' : ConnectInfo -> Elin World [] (Either OracleError a)
89 | withConnection' cfg =
91 | (runIO (acquire cfg))
92 | (\conn => runIO (use conn))
93 | (\conn => runIO (release conn))