module Database.GP.Conn
( Conn (..),
connect,
Database (..),
ConnectionPool,
createConnPool,
withResource,
)
where
import Control.Monad ((>=>))
import Data.Pool (Pool, PoolConfig, defaultPoolConfig, newPool,
withResource)
import Database.HDBC (IConnection (..))
data Conn = forall conn.
IConnection conn =>
Conn
{
Conn -> Database
db :: Database,
Conn -> Bool
implicitCommit :: Bool,
()
connection :: conn
}
data Database = Postgres | MySQL | SQLite | Oracle | MSSQL
deriving (Int -> Database -> ShowS
[Database] -> ShowS
Database -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Database] -> ShowS
$cshowList :: [Database] -> ShowS
show :: Database -> String
$cshow :: Database -> String
showsPrec :: Int -> Database -> ShowS
$cshowsPrec :: Int -> Database -> ShowS
Show, Database -> Database -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Database -> Database -> Bool
$c/= :: Database -> Database -> Bool
== :: Database -> Database -> Bool
$c== :: Database -> Database -> Bool
Eq, Int -> Database
Database -> Int
Database -> [Database]
Database -> Database
Database -> Database -> [Database]
Database -> Database -> Database -> [Database]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Database -> Database -> Database -> [Database]
$cenumFromThenTo :: Database -> Database -> Database -> [Database]
enumFromTo :: Database -> Database -> [Database]
$cenumFromTo :: Database -> Database -> [Database]
enumFromThen :: Database -> Database -> [Database]
$cenumFromThen :: Database -> Database -> [Database]
enumFrom :: Database -> [Database]
$cenumFrom :: Database -> [Database]
fromEnum :: Database -> Int
$cfromEnum :: Database -> Int
toEnum :: Int -> Database
$ctoEnum :: Int -> Database
pred :: Database -> Database
$cpred :: Database -> Database
succ :: Database -> Database
$csucc :: Database -> Database
Enum)
connect :: forall conn. IConnection conn => Database -> conn -> Conn
connect :: forall conn. IConnection conn => Database -> conn -> Conn
connect Database
db = forall conn. IConnection conn => Database -> Bool -> conn -> Conn
Conn Database
db Bool
True
withWConn :: forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn :: forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn (Conn Database
_db Bool
_ic conn
conn) forall conn. IConnection conn => conn -> b
f = forall conn. IConnection conn => conn -> b
f conn
conn
instance IConnection Conn where
disconnect :: Conn -> IO ()
disconnect Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> IO ()
disconnect
commit :: Conn -> IO ()
commit Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> IO ()
commit
rollback :: Conn -> IO ()
rollback Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> IO ()
rollback
runRaw :: Conn -> String -> IO ()
runRaw Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String -> IO ()
runRaw
run :: Conn -> String -> [SqlValue] -> IO Integer
run Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn.
IConnection conn =>
conn -> String -> [SqlValue] -> IO Integer
run
prepare :: Conn -> String -> IO Statement
prepare Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String -> IO Statement
prepare
clone :: Conn -> IO Conn
clone w :: Conn
w@(Conn Database
db Bool
ic conn
_) = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w (forall conn. IConnection conn => conn -> IO conn
clone forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall conn. IConnection conn => Database -> Bool -> conn -> Conn
Conn Database
db Bool
ic)
hdbcDriverName :: Conn -> String
hdbcDriverName Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String
hdbcDriverName
hdbcClientVer :: Conn -> String
hdbcClientVer Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String
hdbcClientVer
proxiedClientName :: Conn -> String
proxiedClientName Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String
proxiedClientName
proxiedClientVer :: Conn -> String
proxiedClientVer Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String
proxiedClientVer
dbServerVer :: Conn -> String
dbServerVer Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> String
dbServerVer
dbTransactionSupport :: Conn -> Bool
dbTransactionSupport Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> Bool
dbTransactionSupport
getTables :: Conn -> IO [String]
getTables Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn. IConnection conn => conn -> IO [String]
getTables
describeTable :: Conn -> String -> IO [(String, SqlColDesc)]
describeTable Conn
w = forall b. Conn -> (forall conn. IConnection conn => conn -> b) -> b
withWConn Conn
w forall conn.
IConnection conn =>
conn -> String -> IO [(String, SqlColDesc)]
describeTable
type ConnectionPool = Pool Conn
createConnPool :: IConnection conn =>
Database ->
String ->
(String -> IO conn) ->
Double ->
Int ->
IO ConnectionPool
createConnPool :: forall conn.
IConnection conn =>
Database
-> String
-> (String -> IO conn)
-> Double
-> Int
-> IO ConnectionPool
createConnPool Database
db String
connectString String -> IO conn
connectFun Double
idle Int
numConns = forall a. PoolConfig a -> IO (Pool a)
newPool PoolConfig Conn
poolConfig
where
freshConnection :: IO Conn
freshConnection :: IO Conn
freshConnection = forall conn. IConnection conn => Database -> conn -> Conn
connect Database
db forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> IO conn
connectFun String
connectString
poolConfig :: PoolConfig Conn
poolConfig :: PoolConfig Conn
poolConfig = forall a. IO a -> (a -> IO ()) -> Double -> Int -> PoolConfig a
defaultPoolConfig IO Conn
freshConnection forall conn. IConnection conn => conn -> IO ()
disconnect Double
idle Int
numConns