From 5ac529f2e0078b81d638c507cb70f458bd640926 Mon Sep 17 00:00:00 2001 From: Aravind Gopal Mallapureddy Date: Tue, 9 Mar 2021 14:42:10 +0530 Subject: [PATCH 1/8] Converted the time to milliseconds --- .../Database/Beam/Postgres/Connection.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/beam-postgres/Database/Beam/Postgres/Connection.hs b/beam-postgres/Database/Beam/Postgres/Connection.hs index 0fd13526..a561d2a8 100644 --- a/beam-postgres/Database/Beam/Postgres/Connection.hs +++ b/beam-postgres/Database/Beam/Postgres/Connection.hs @@ -61,7 +61,7 @@ import qualified Control.Monad.Fail as Fail import Data.ByteString (ByteString) import Data.ByteString.Builder (toLazyByteString, byteString) import qualified Data.ByteString.Lazy as BL -import Data.Maybe (listToMaybe, fromMaybe) +import Data.Maybe (listToMaybe, fromMaybe, fromJust) import Data.Proxy import Data.String import Data.Text (Text) @@ -202,15 +202,18 @@ withPgDebug dbg conn (Pg action) = end <- getTime Monotonic (, Just (end - start)) <$> next x PgStreamDone (Left err) -> pure (Left err, Nothing) - PgStreamContinue nextStream -> - let finishUp (PgStreamDone (Right x)) = (, Nothing) <$> next x + PgStreamContinue nextStream -> do + start <- getTime Monotonic + let finishUp (PgStreamDone (Right x)) = (\x y -> (x, Just $ y - start )) <$> next x <*> getTime Monotonic finishUp (PgStreamDone (Left err)) = pure (Left err, Nothing) finishUp (PgStreamContinue next') = next' Nothing >>= finishUp columnCount = fromIntegral $ valuesNeeded (Proxy @Postgres) (Proxy @x) - in do resp <- Pg.queryWith_ (Pg.RP (put columnCount >> ask)) conn (Pg.Query query) - foldM runConsumer (PgStreamContinue nextStream) resp >>= finishUp - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show extime) <> " seconds ") >> return res + resp <- Pg.queryWith_ (Pg.RP (put columnCount >> ask)) conn (Pg.Query query) + foldM runConsumer (PgStreamContinue nextStream) resp >>= finishUp + when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec $ fromJust extime) `div` 1000000)) <> "milli seconds ") + when (extime == Nothing) $ dbg (decodeUtf8 query) + return res step (PgRunReturning (PgCommandSyntax PgCommandTypeDataUpdateReturning syntax) mkProcess next) = do query <- pgRenderSyntax conn syntax @@ -218,7 +221,7 @@ withPgDebug dbg conn (Pg action) = res <- Pg.exec conn query end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show extime) <> " seconds ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> "milli seconds ") sts <- Pg.resultStatus res case sts of Pg.TuplesOk -> do @@ -232,7 +235,7 @@ withPgDebug dbg conn (Pg action) = _ <- Pg.execute_ conn (Pg.Query query) end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show extime) <> " seconds ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> "milli seconds ") let Pg process = mkProcess (Pg (liftF (PgFetchNext id))) runF process next stepReturningNone From 3a3309aa74260dfe0a7348c2fa21c18c7c073fed Mon Sep 17 00:00:00 2001 From: Aravind Gopal Mallapureddy Date: Wed, 10 Mar 2021 17:21:41 +0530 Subject: [PATCH 2/8] changed to ms --- beam-postgres/Database/Beam/Postgres/Connection.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beam-postgres/Database/Beam/Postgres/Connection.hs b/beam-postgres/Database/Beam/Postgres/Connection.hs index a561d2a8..db48a282 100644 --- a/beam-postgres/Database/Beam/Postgres/Connection.hs +++ b/beam-postgres/Database/Beam/Postgres/Connection.hs @@ -211,7 +211,7 @@ withPgDebug dbg conn (Pg action) = columnCount = fromIntegral $ valuesNeeded (Proxy @Postgres) (Proxy @x) resp <- Pg.queryWith_ (Pg.RP (put columnCount >> ask)) conn (Pg.Query query) foldM runConsumer (PgStreamContinue nextStream) resp >>= finishUp - when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec $ fromJust extime) `div` 1000000)) <> "milli seconds ") + when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec $ fromJust extime) `div` 1000000)) <> " ms ") when (extime == Nothing) $ dbg (decodeUtf8 query) return res step (PgRunReturning (PgCommandSyntax PgCommandTypeDataUpdateReturning syntax) mkProcess next) = @@ -221,7 +221,7 @@ withPgDebug dbg conn (Pg action) = res <- Pg.exec conn query end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> "milli seconds ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> " ms ") sts <- Pg.resultStatus res case sts of Pg.TuplesOk -> do @@ -235,7 +235,7 @@ withPgDebug dbg conn (Pg action) = _ <- Pg.execute_ conn (Pg.Query query) end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> "milli seconds ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> " ms ") let Pg process = mkProcess (Pg (liftF (PgFetchNext id))) runF process next stepReturningNone From 1f05321e28ca999ab5b00ad35d429b45b0aabc0e Mon Sep 17 00:00:00 2001 From: Kirill Boltaev Date: Mon, 19 Apr 2021 16:50:19 +0300 Subject: [PATCH 3/8] Update euler-build --- euler.yaml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 euler.yaml diff --git a/euler.yaml b/euler.yaml new file mode 100644 index 00000000..53737f50 --- /dev/null +++ b/euler.yaml @@ -0,0 +1,50 @@ +name: beam +projects: + beam-core: + location: beam-core + allowed-paths: + - beam-core.cabal + - Database + - LICENSE + beam-migrate: + location: beam-migrate + allowed-paths: + - beam-migrate.cabal + - Database + - tools + - LICENSE + beam-migrate-cli: + location: beam-migrate-cli + allowed-paths: + - beam-migrate-cli.cabal + - Database + - BeamMigrate.hs + - LICENSE + beam-postgres: + location: beam-postgres + allowed-paths: + - beam-postgres.cabal + - Database + - test + - LICENSE + beam-sqlite: + location: beam-sqlite + allowed-paths: + - beam-sqlite.cabal + - Database + - examples + - LICENSE + +default-project: beam-core +dependencies: + euler-build: + branch: master + revision: 90f393f7f91e1bb9d7b3c0ece1aa919797d1987b +overrides: + haskell-src-exts: + source: hackage + version: 1.21.1 + sha256: 06b37iis7hfnc770gb3jn12dy3yngqcfdraynbvy3n7s0hlv2hcw + enable-profiling: true + haskell-src-meta: + enable-profiling: true From bf63c3c77f61843de902fbffff3acdb3149100b6 Mon Sep 17 00:00:00 2001 From: Aravind gopal mallapureddy Date: Thu, 17 Jun 2021 20:30:31 +0530 Subject: [PATCH 4/8] removed Nothing in executed time --- beam-postgres/Database/Beam/Postgres/Connection.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beam-postgres/Database/Beam/Postgres/Connection.hs b/beam-postgres/Database/Beam/Postgres/Connection.hs index db48a282..541201cd 100644 --- a/beam-postgres/Database/Beam/Postgres/Connection.hs +++ b/beam-postgres/Database/Beam/Postgres/Connection.hs @@ -204,7 +204,10 @@ withPgDebug dbg conn (Pg action) = PgStreamDone (Left err) -> pure (Left err, Nothing) PgStreamContinue nextStream -> do start <- getTime Monotonic - let finishUp (PgStreamDone (Right x)) = (\x y -> (x, Just $ y - start )) <$> next x <*> getTime Monotonic + let finishUp (PgStreamDone (Right x)) = do + output <- next x + end <- getTime Monotonic + pure (output, Just $ end - start) finishUp (PgStreamDone (Left err)) = pure (Left err, Nothing) finishUp (PgStreamContinue next') = next' Nothing >>= finishUp From 15a5c26d415986543dfed83168f66533d8aaf009 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 2 Apr 2022 19:38:24 +0530 Subject: [PATCH 5/8] Add TypeFamilyDependencies for GHC >8.10 --- beam-core/beam-core.cabal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beam-core/beam-core.cabal b/beam-core/beam-core.cabal index 63100ebe..f9e41a30 100644 --- a/beam-core/beam-core.cabal +++ b/beam-core/beam-core.cabal @@ -84,6 +84,8 @@ library ghc-options: -Wcompat if flag(werror) ghc-options: -Werror + if impl(ghc >= 8.10) + default-extensions: TypeFamilyDependencies flag werror description: Enable -Werror during development From ba9bc7099eba0f3c03b70b8b1f30b526f08a98c3 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 2 Jun 2023 15:48:41 +0530 Subject: [PATCH 6/8] Resolved bug while printing executed in time --- beam-postgres/Database/Beam/Postgres/Connection.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beam-postgres/Database/Beam/Postgres/Connection.hs b/beam-postgres/Database/Beam/Postgres/Connection.hs index 541201cd..838bea91 100644 --- a/beam-postgres/Database/Beam/Postgres/Connection.hs +++ b/beam-postgres/Database/Beam/Postgres/Connection.hs @@ -214,7 +214,7 @@ withPgDebug dbg conn (Pg action) = columnCount = fromIntegral $ valuesNeeded (Proxy @Postgres) (Proxy @x) resp <- Pg.queryWith_ (Pg.RP (put columnCount >> ask)) conn (Pg.Query query) foldM runConsumer (PgStreamContinue nextStream) resp >>= finishUp - when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec $ fromJust extime) `div` 1000000)) <> " ms ") + when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec $ fromJust extime) * 1000000000 + (nsec $ fromJust extime)) `div` 1000000)) <> " ms ") when (extime == Nothing) $ dbg (decodeUtf8 query) return res step (PgRunReturning (PgCommandSyntax PgCommandTypeDataUpdateReturning syntax) mkProcess next) = @@ -224,7 +224,7 @@ withPgDebug dbg conn (Pg action) = res <- Pg.exec conn query end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> " ms ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec extime) * 1000000000 + (nsec extime)) `div` 1000000)) <> " ms ") sts <- Pg.resultStatus res case sts of Pg.TuplesOk -> do @@ -238,7 +238,7 @@ withPgDebug dbg conn (Pg action) = _ <- Pg.execute_ conn (Pg.Query query) end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show ((nsec extime) `div` 1000000)) <> " ms ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec extime) * 1000000000 + (nsec extime)) `div` 1000000)) <> " ms ") let Pg process = mkProcess (Pg (liftF (PgFetchNext id))) runF process next stepReturningNone From 3676a9ac974e4f92c1bea34f8889b7e08fdc4dcc Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 9 Jun 2023 00:50:07 +0530 Subject: [PATCH 7/8] Change in approach for finding the executed in time --- beam-postgres/Database/Beam/Postgres/Connection.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beam-postgres/Database/Beam/Postgres/Connection.hs b/beam-postgres/Database/Beam/Postgres/Connection.hs index 838bea91..96fa47bd 100644 --- a/beam-postgres/Database/Beam/Postgres/Connection.hs +++ b/beam-postgres/Database/Beam/Postgres/Connection.hs @@ -214,7 +214,7 @@ withPgDebug dbg conn (Pg action) = columnCount = fromIntegral $ valuesNeeded (Proxy @Postgres) (Proxy @x) resp <- Pg.queryWith_ (Pg.RP (put columnCount >> ask)) conn (Pg.Query query) foldM runConsumer (PgStreamContinue nextStream) resp >>= finishUp - when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec $ fromJust extime) * 1000000000 + (nsec $ fromJust extime)) `div` 1000000)) <> " ms ") + when (extime /= Nothing) $ dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec (fromJust extime)) * 1000) + ((nsec (fromJust extime)) `div` 1000000)) <> " ms ")) when (extime == Nothing) $ dbg (decodeUtf8 query) return res step (PgRunReturning (PgCommandSyntax PgCommandTypeDataUpdateReturning syntax) mkProcess next) = @@ -224,7 +224,7 @@ withPgDebug dbg conn (Pg action) = res <- Pg.exec conn query end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec extime) * 1000000000 + (nsec extime)) `div` 1000000)) <> " ms ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec extime) * 1000) + ((nsec extime) `div` 1000000)) <> " ms ")) sts <- Pg.resultStatus res case sts of Pg.TuplesOk -> do @@ -238,7 +238,7 @@ withPgDebug dbg conn (Pg action) = _ <- Pg.execute_ conn (Pg.Query query) end <- getTime Monotonic let extime = end - start - dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec extime) * 1000000000 + (nsec extime)) `div` 1000000)) <> " ms ") + dbg (decodeUtf8 query <> " Executed in: " <> T.pack (show (((sec extime) * 1000) + ((nsec extime) `div` 1000000)) <> " ms ")) let Pg process = mkProcess (Pg (liftF (PgFetchNext id))) runF process next stepReturningNone From 1241b34295e9bd9d045322173eeaba13d207cdca Mon Sep 17 00:00:00 2001 From: Isaac Jacob Date: Thu, 12 Oct 2023 03:35:26 +0530 Subject: [PATCH 8/8] exposing constructors of PgCommandSyntax --- beam-postgres/Database/Beam/Postgres.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beam-postgres/Database/Beam/Postgres.hs b/beam-postgres/Database/Beam/Postgres.hs index 8dd4aa5c..d30afd8b 100644 --- a/beam-postgres/Database/Beam/Postgres.hs +++ b/beam-postgres/Database/Beam/Postgres.hs @@ -22,7 +22,7 @@ module Database.Beam.Postgres Postgres(..), Pg, liftIOWithHandle -- ** Postgres syntax - , PgCommandSyntax, PgSyntax + , PgCommandSyntax(..), PgSyntax , PgSelectSyntax, PgInsertSyntax , PgUpdateSyntax, PgDeleteSyntax