hasql/profiling/Main.hs

98 lines
2.7 KiB
Haskell
Raw Normal View History

2017-04-14 00:46:59 +03:00
module Main where
import Prelude
import qualified Hasql.Connection as A
import qualified Hasql.Session as B
2018-05-23 13:33:34 +03:00
import qualified Hasql.Statement as C
2017-04-14 00:46:59 +03:00
import qualified Hasql.Decoders as D
import qualified Hasql.Encoders as E
import qualified Data.Vector as F
main =
do
Right connection <- acquireConnection
traceEventIO "START Session"
Right result <- B.run sessionWithManySmallResults connection
traceEventIO "STOP Session"
return ()
where
acquireConnection =
A.acquire settings
where
settings =
A.settings host port user password database
where
host = "localhost"
port = 5432
user = "postgres"
password = ""
database = "postgres"
-- * Sessions
-------------------------
sessionWithManySmallParameters :: Vector (Int64, Int64) -> B.Session ()
sessionWithManySmallParameters =
2021-03-23 15:06:42 +03:00
error "TODO: sessionWithManySmallParameters"
2017-04-14 00:46:59 +03:00
sessionWithSingleLargeResultInVector :: B.Session (Vector (Int64, Int64))
sessionWithSingleLargeResultInVector =
2018-05-23 13:33:34 +03:00
B.statement () statementWithManyRowsInVector
2017-04-14 00:46:59 +03:00
sessionWithSingleLargeResultInList :: B.Session [(Int64, Int64)]
2017-04-14 00:46:59 +03:00
sessionWithSingleLargeResultInList =
2018-05-23 13:33:34 +03:00
B.statement () statementWithManyRowsInList
2017-04-14 00:46:59 +03:00
sessionWithManySmallResults :: B.Session (Vector (Int64, Int64))
sessionWithManySmallResults =
2018-05-23 13:33:34 +03:00
F.replicateM 1000 (B.statement () statementWithSingleRow)
2017-04-14 00:46:59 +03:00
-- * Statements
-------------------------
2018-05-23 13:33:34 +03:00
statementWithManyParameters :: C.Statement (Vector (Int64, Int64)) ()
statementWithManyParameters =
2021-03-23 15:06:42 +03:00
error "TODO: statementWithManyParameters"
2017-04-14 00:46:59 +03:00
2018-05-23 13:33:34 +03:00
statementWithSingleRow :: C.Statement () (Int64, Int64)
statementWithSingleRow =
C.Statement template encoder decoder True
2017-04-14 00:46:59 +03:00
where
template =
"SELECT 1, 2"
encoder =
conquer
decoder =
D.singleRow row
where
row =
2019-05-21 01:20:57 +03:00
tuple <$> (D.column . D.nonNullable) D.int8 <*> (D.column . D.nonNullable) D.int8
2017-04-14 00:46:59 +03:00
where
tuple !a !b =
(a, b)
2018-05-23 13:33:34 +03:00
statementWithManyRows :: (D.Row (Int64, Int64) -> D.Result result) -> C.Statement () result
statementWithManyRows decoder =
C.Statement template encoder (decoder rowDecoder) True
2017-04-14 00:46:59 +03:00
where
template =
"SELECT generate_series(0,1000) as a, generate_series(1000,2000) as b"
encoder =
conquer
rowDecoder =
2019-05-21 01:20:57 +03:00
tuple <$> (D.column . D.nonNullable) D.int8 <*> (D.column . D.nonNullable) D.int8
2017-04-14 00:46:59 +03:00
where
tuple !a !b =
(a, b)
2018-05-23 13:33:34 +03:00
statementWithManyRowsInVector :: C.Statement () (Vector (Int64, Int64))
statementWithManyRowsInVector =
statementWithManyRows D.rowVector
2017-04-14 00:46:59 +03:00
statementWithManyRowsInList :: C.Statement () [(Int64, Int64)]
2018-05-23 13:33:34 +03:00
statementWithManyRowsInList =
statementWithManyRows D.rowList