presto-hdbc 0.1.0.1 → 0.1.0.2
raw patch · 5 files changed
+38/−6 lines, 5 files
Files
- presto-hdbc.cabal +2/−2
- src/Database/HDBC/Presto.hs +1/−3
- src/Database/HDBC/PrestoData.hs +1/−1
- src/JSONConventions.hs +12/−0
- src/Util.hs +22/−0
presto-hdbc.cabal view
@@ -11,7 +11,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.1.0.1+version: 0.1.0.2 -- A short (one-line) description of the package. synopsis: An HDBC connector for Presto@@ -55,7 +55,7 @@ exposed-modules: Database.HDBC.Presto -- Modules included in this library but not exported.- other-modules: Database.HDBC.PrestoData+ other-modules: Database.HDBC.PrestoData, Util, JSONConventions -- LANGUAGE extensions used by modules in this package. -- other-extensions:
src/Database/HDBC/Presto.hs view
@@ -36,9 +36,7 @@ import Network.Http.Client import qualified System.IO.Streams as Streams --- TODO: move to utility library or find in real library-maybeToEither = flip maybe Right . Left-maybeToEitherT x y = hoistEither $ maybeToEither x y+import Util instance IConnection PrestoConnection where disconnect = disconnectPresto
src/Database/HDBC/PrestoData.hs view
@@ -9,7 +9,7 @@ import Data.Text as T import Database.HDBC (SqlValue) import GHC.Generics-import Util.JSONConventions+import JSONConventions data PrestoStats = PrestoStats { state :: String , scheduled :: Bool
+ src/JSONConventions.hs view
@@ -0,0 +1,12 @@+module JSONConventions where++import Control.Lens ((%~), _head)+import Data.Aeson.TH (Options(..), SumEncoding(..), defaultOptions)+import Data.Char (toLower)++jsonOptions = defaultOptions { constructorTagModifier = _head %~ toLower+ , fieldLabelModifier = \s -> let d = dropWhile (/= '_') s in+ if null d then s else (tail d)+ , omitNothingFields = True+ , sumEncoding = ObjectWithSingleField+ }
+ src/Util.hs view
@@ -0,0 +1,22 @@+{-# LANGUAGE ScopedTypeVariables #-}+module Util where++import Control.Monad.Trans+import Control.Monad.Trans.Either+++-- mapLeft :: (a -> c) -> Either a b -> Either c b+-- mapLeft f (Left x) = Left (f x)+-- mapLeft _ (Right x) = Right x++maybeToEither :: e -> Maybe v -> Either e v+maybeToEither _ (Just x) = Right x+maybeToEither e Nothing = Left e++maybeToEitherT :: Monad m => e -> Maybe a -> EitherT e m a+maybeToEitherT x y = hoistEither $ maybeToEither x y++ioEither :: (Monad m) => m (Either l r) -> EitherT l m r+ioEither action = do+ result <- lift action+ hoistEither result