@@ -82,7 +82,9 @@ data ResultError = Incompatible { errSQLType :: String
83instance Exception ResultError
83instance Exception ResultError
85−left :: Exception a => a -> Either SomeException b
85+type Status = Either SomeException
87+left :: Exception a => a -> Status b
86left = Left . SomeException
88left = Left . SomeException
88-- | A type that may be converted from a SQL type.
90-- | A type that may be converted from a SQL type.
@@ -151,7 +153,7 @@ instance Result LB.ByteString where
151 convert f dat = LB.fromChunks . (:[]) <$> convert f dat
153 convert f dat = LB.fromChunks . (:[]) <$> convert f dat
153unescapeBytea :: Field -> SB.ByteString
155unescapeBytea :: Field -> SB.ByteString
154− -> Either SomeException (Binary SB.ByteString)
156+ -> Status (Binary SB.ByteString)
155unescapeBytea f str = case unsafePerformIO (PQ.unescapeBytea str) of
157unescapeBytea f str = case unsafePerformIO (PQ.unescapeBytea str) of
156 Nothing -> returnError ConversionFailed f "unescapeBytea failed"
158 Nothing -> returnError ConversionFailed f "unescapeBytea failed"
157 Just str -> pure (Binary str)
159 Just str -> pure (Binary str)
@@ -224,8 +226,8 @@ okInt = ok64
226doConvert :: forall a . (Typeable a)
228doConvert :: forall a . (Typeable a)
227− => Field -> Compat -> (ByteString -> Either SomeException a)
229+ => Field -> Compat -> (ByteString -> Status a)
228− -> Maybe ByteString -> Either SomeException a
230+ -> Maybe ByteString -> Status a
229doConvert f types cvt (Just bs)
231doConvert f types cvt (Just bs)
230 | Just typ <- oid2builtin (typeOid f)
232 | Just typ <- oid2builtin (typeOid f)
231 , mkCompat typ `compat` types = cvt bs
233 , mkCompat typ `compat` types = cvt bs
@@ -235,27 +237,27 @@ doConvert f _ _ _ = returnError UnexpectedNull f ""
236returnError :: forall a err . (Typeable a, Exception err)
238returnError :: forall a err . (Typeable a, Exception err)
237 => (String -> String -> String -> err)
239 => (String -> String -> String -> err)
238− -> Field -> String -> Either SomeException a
240+ -> Field -> String -> Status a
239returnError mkErr f = left . mkErr (B.unpack (typename f))
241returnError mkErr f = left . mkErr (B.unpack (typename f))
240 (show (typeOf (undefined :: a)))
242 (show (typeOf (undefined :: a)))
242atto :: forall a. (Typeable a)
244atto :: forall a. (Typeable a)
243 => Compat -> Parser a -> Field -> Maybe ByteString
245 => Compat -> Parser a -> Field -> Maybe ByteString
244− -> Either SomeException a
246+ -> Status a
245atto types p0 f dat = doConvert f types (go p0) dat
247atto types p0 f dat = doConvert f types (go p0) dat
247− go :: Parser a -> ByteString -> Either SomeException a
249+ go :: Parser a -> ByteString -> Status a
249 case parseOnly p s of
251 case parseOnly p s of
250 Left err -> returnError ConversionFailed f err
252 Left err -> returnError ConversionFailed f err
251 Right v -> Right v
253 Right v -> Right v
253atto' :: forall a. (Typeable a)
255atto' :: forall a. (Typeable a)
254− => Compat -> Parser (Either SomeException a) -> Field -> Maybe ByteString
256+ => Compat -> Parser (Status a) -> Field -> Maybe ByteString
255− -> Either SomeException a
257+ -> Status a
256atto' types p0 f dat = doConvert f types (go p0) dat
258atto' types p0 f dat = doConvert f types (go p0) dat
258− go :: Parser (Either SomeException a) -> ByteString -> Either SomeException a
260+ go :: Parser (Status a) -> ByteString -> Status a
260 case parseOnly p s of
262 case parseOnly p s of
261 Left err -> returnError ConversionFailed f err
263 Left err -> returnError ConversionFailed f err