mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-28 04:57:14 +03:00
parse -> parseRow
This commit is contained in:
parent
e787181618
commit
d47e98e9a3
@ -293,4 +293,4 @@ hoistBackendStream :: RowParser b r => Backend.ResultsStream b -> ResultsStream
|
|||||||
hoistBackendStream (w, s) =
|
hoistBackendStream (w, s) =
|
||||||
TransactionListT $ hoist (Transaction . lift) $ do
|
TransactionListT $ hoist (Transaction . lift) $ do
|
||||||
row <- ($ s) $ ListT.slice $ fromMaybe ($bug "Invalid row width") $ ListT.positive w
|
row <- ($ s) $ ListT.slice $ fromMaybe ($bug "Invalid row width") $ ListT.positive w
|
||||||
either (lift . throwIO . ResultParsingError) return $ RowParser.parse row
|
either (lift . throwIO . ResultParsingError) return $ RowParser.parseRow row
|
||||||
|
@ -7,13 +7,13 @@ import qualified Hasql.Backend as Backend
|
|||||||
|
|
||||||
|
|
||||||
class RowParser b r where
|
class RowParser b r where
|
||||||
parse :: [Backend.Result b] -> Either Text r
|
parseRow :: [Backend.Result b] -> Either Text r
|
||||||
|
|
||||||
instance RowParser b () where
|
instance RowParser b () where
|
||||||
parse = \case [] -> Right (); _ -> Left $ "Row is not empty"
|
parseRow = \case [] -> Right (); _ -> Left $ "Row is not empty"
|
||||||
|
|
||||||
instance Backend.Mapping b v => RowParser b (Identity v) where
|
instance Backend.Mapping b v => RowParser b (Identity v) where
|
||||||
parse l = do
|
parseRow l = do
|
||||||
h <- maybe (Left $ "Empty row") Right $ headMay l
|
h <- maybe (Left $ "Empty row") Right $ headMay l
|
||||||
Identity <$> Backend.parseResult h
|
Identity <$> Backend.parseResult h
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ instance Backend.Mapping b v => RowParser b (Identity v) where
|
|||||||
let
|
let
|
||||||
inst :: Int -> Dec
|
inst :: Int -> Dec
|
||||||
inst arity =
|
inst arity =
|
||||||
InstanceD constraints head [parseDec]
|
InstanceD constraints head [parseRowDec]
|
||||||
where
|
where
|
||||||
varNames =
|
varNames =
|
||||||
[1 .. arity] >>= \i -> return (mkName ('_' : show i))
|
[1 .. arity] >>= \i -> return (mkName ('_' : show i))
|
||||||
@ -33,8 +33,8 @@ let
|
|||||||
map (\t -> ClassP ''Backend.Mapping [backendType, t]) varTypes
|
map (\t -> ClassP ''Backend.Mapping [backendType, t]) varTypes
|
||||||
head =
|
head =
|
||||||
AppT (AppT (ConT ''RowParser) backendType) (foldl AppT (TupleT arity) varTypes)
|
AppT (AppT (ConT ''RowParser) backendType) (foldl AppT (TupleT arity) varTypes)
|
||||||
parseDec =
|
parseRowDec =
|
||||||
FunD 'parse [c1, c2]
|
FunD 'parseRow [c1, c2]
|
||||||
where
|
where
|
||||||
c1 =
|
c1 =
|
||||||
Clause [ListP (map VarP varNames)] (NormalB e) []
|
Clause [ListP (map VarP varNames)] (NormalB e) []
|
||||||
|
Loading…
Reference in New Issue
Block a user