packages feed

potoki-hasql (empty) → 1

raw patch · 9 files changed

+251/−0 lines, 9 filesdep +basedep +bytestringdep +hasqlsetup-changed

Dependencies added: base, bytestring, hasql, potoki, potoki-core, profunctors, text, vector

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2018, Metrix.AI++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ library/PotokiHasql/Error/Hasql.hs view
@@ -0,0 +1,21 @@+{-| Hasql errors interpretation -}+module PotokiHasql.Error.Hasql+where++import           PotokiHasql.Prelude+import           PotokiHasql.Error.Types+import qualified Hasql.Session            as A+import qualified Hasql.Connection         as C+++connectionError :: C.ConnectionError -> Error+connectionError details =+  ConnectionError (maybe "" lenientUtf8ByteStringText details)++sessionError :: A.Error -> Error+sessionError =+  \ case+    A.ClientError details ->+      ConnectionError (maybe "" lenientUtf8ByteStringText details)+    A.ResultError details ->+      InteractionError ((stringText . show) details)
+ library/PotokiHasql/Error/Instances.hs view
@@ -0,0 +1,8 @@+module PotokiHasql.Error.Instances+where++import PotokiHasql.Prelude+import PotokiHasql.Error.Types+++deriving instance Show Error
+ library/PotokiHasql/Error/Types.hs view
@@ -0,0 +1,14 @@+module PotokiHasql.Error.Types+where++import PotokiHasql.Prelude+++{-| Error, which can be produced during interaction with the Requests database.+    Comes packed with the detailed description of the problems. -}+data Error =+  {-| Connection error. Can be interpreted as a signal for reconnecting. -}+  ConnectionError Text |+  {-| Some form of an interaction error.+      Can happen for many reasons related to improper suppositions about the state of the database. -}+  InteractionError Text
+ library/PotokiHasql/Potoki/Consume.hs view
@@ -0,0 +1,44 @@+module PotokiHasql.Potoki.Consume+where++import           PotokiHasql.Prelude   +import qualified Hasql.Connection        as B+import qualified Hasql.Query             as E+import qualified Hasql.Session           as D+import qualified Potoki.Consume          as O+import           Potoki.Core.Consume+import qualified Potoki.Core.Fetch       as C+import qualified Potoki.Transform        as F+import qualified PotokiHasql.Error.Hasql as G+import           PotokiHasql.Error.Types  +++executeBatchQuery :: E.Query (Vector params) () -> Int -> B.Settings -> Consume params (Either Error ())+executeBatchQuery query batchSize settings =+  transform+    (F.consume (transform (F.take batchSize) O.vector))+    (executeQuery query settings)++executeQuery :: E.Query params () -> B.Settings -> Consume params (Either Error ())+executeQuery query =+  executeSession (\ params -> D.query params query)++executeSession :: (params -> D.Session ()) -> B.Settings -> Consume params (Either Error ())+executeSession session connectionSettings =+  Consume $ \ (C.Fetch fetchIO) -> do+    acquisitionResult <- B.acquire connectionSettings+    case acquisitionResult of+      Left error -> return (Left (G.connectionError error))+      Right connection ->+        let+          loop =+            join $+            fetchIO+              (return (Right ()))+              (\ params ->+                do+                  result <- D.run (session params) connection+                  case result of+                    Right () -> loop+                    Left error -> return (Left (G.sessionError error)))+          in loop <* B.release connection
+ library/PotokiHasql/Potoki/Produce.hs view
@@ -0,0 +1,54 @@+module PotokiHasql.Potoki.Produce (+  vectorStatefulSession,+  statefulSession+) where++import           PotokiHasql.Prelude+import qualified Hasql.Connection        as F+import qualified Hasql.Session           as G+import qualified Potoki.Core.Fetch       as A+import           Potoki.Core.Produce+import qualified Potoki.Produce          as K+import qualified Potoki.Transform        as J+import qualified PotokiHasql.Error.Hasql as I+import           PotokiHasql.Error.Types+++vectorStatefulSession :: (state -> G.Session (Vector a, state)) -> state -> F.Settings -> Produce (Either Error a)+vectorStatefulSession vectorSession initialState connectionSettings =+  K.transform+    (right' J.vector)+    (statefulSession vectorSession initialState connectionSettings)+++statefulSession :: (state -> G.Session (a, state)) -> state -> F.Settings -> Produce (Either Error a)+statefulSession session initialState =+  havingConnection $ \ connection -> do+    stateRef <- newIORef initialState+    return $ A.Fetch $ \ nil just -> do+      state <- readIORef stateRef+      sessionResult <- G.run (session state) connection+      case sessionResult of+        Left error -> return (just (Left (I.sessionError error)))+        Right (result, newState) -> do+          writeIORef stateRef newState+          return (just (Right result))+++havingConnection :: (F.Connection -> IO (A.Fetch (Either Error a))) -> F.Settings -> Produce (Either Error a)+havingConnection cont connectionSettings =+  Produce $ do+    errorOrConnection <- F.acquire connectionSettings+    case errorOrConnection of+      Left error ->+        let+          fetch =+            A.Fetch $ \ stop yield -> return (yield (Left (I.connectionError error)))+          kill =+            return ()+          in return (fetch, kill)+      Right connection -> do+        fetch <- cont connection+        let+          kill = F.release connection+          in return (fetch, kill)
+ library/PotokiHasql/Prelude.hs view
@@ -0,0 +1,27 @@+module PotokiHasql.Prelude+(+  module Exports,+  stringText,+  lenientUtf8ByteStringText,+)+where++import           Prelude                  as Exports+import           Control.Monad            as Exports (join)+import           Data.Profunctor          as Exports (right')+import           Data.IORef               as Exports+import           Data.Vector              as Exports (Vector(..))+import           Data.Text                as Exports (Text(..))+import qualified Data.Text                as A+import qualified Data.Text.Encoding       as A+import qualified Data.Text.Encoding.Error as A+import qualified Data.ByteString          as B+++stringText :: String -> A.Text+stringText =+  A.pack++lenientUtf8ByteStringText :: B.ByteString -> A.Text+lenientUtf8ByteStringText =+  A.decodeUtf8With A.lenientDecode
+ potoki-hasql.cabal view
@@ -0,0 +1,59 @@+name:+  potoki-hasql+version:+  1+synopsis:+  Integration of "potoki" and "hasql".+description:+  Utilities, which integrate Hasql and Potoki.+category:+  Streaming, Database+homepage:+  https://github.com/metrix-ai/potoki-hasql +bug-reports:+  https://github.com/metrix-ai/potoki-hasql/issues +author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Metrix.AI Ninjas <ninjas@metrix.ai>+copyright:+  (c) 2018, Metrix.AI+license:+  MIT+license-file:+  LICENSE+build-type:+  Simple+cabal-version:+  >=1.24++source-repository head+  type:+    git+  location:+    https://github.com/metrix-ai/potoki-hasql.git++library+  hs-source-dirs:+    library+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+  default-language:+    Haskell2010+  exposed-modules:+    PotokiHasql.Potoki.Consume+    PotokiHasql.Potoki.Produce+  other-modules:+    PotokiHasql.Error.Hasql+    PotokiHasql.Error.Instances+    PotokiHasql.Error.Types+    PotokiHasql.Prelude+  build-depends:+    hasql == 1.1.1,+    potoki == 0.11.1,+    potoki-core == 1.5.2,+    base == 4.10.1.0,+    text == 1.2.3.0,+    bytestring == 0.10.8.2,+    vector == 0.12.0.1,+    profunctors == 5.2.2