Skip to content

Add fromFieldRange :: Typeable a => FieldParser a -> FieldParser (PGR… #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Database/PostgreSQL/Simple/Range.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Database.PostgreSQL.Simple.Range
, empty
, isEmpty, isEmptyBy
, contains, containsBy
, fromFieldRange
) where

import Control.Applicative hiding (empty)
Expand Down Expand Up @@ -189,7 +190,10 @@ rangeToBuilderBy cmp f x =


instance (FromField a, Typeable a) => FromField (PGRange a) where
fromField f mdat = do
fromField = fromFieldRange fromField

fromFieldRange :: Typeable a => FieldParser a -> FieldParser (PGRange a)
fromFieldRange fromField' f mdat = do
info <- typeInfo f
case info of
Range{} ->
Expand All @@ -199,8 +203,8 @@ instance (FromField a, Typeable a) => FromField (PGRange a) where
Just "empty" -> pure $ empty
Just bs ->
let parseIt NegInfinity = pure NegInfinity
parseIt (Inclusive v) = Inclusive <$> fromField f' (Just v)
parseIt (Exclusive v) = Exclusive <$> fromField f' (Just v)
parseIt (Inclusive v) = Inclusive <$> fromField' f' (Just v)
parseIt (Exclusive v) = Exclusive <$> fromField' f' (Just v)
parseIt PosInfinity = pure PosInfinity
in case parseOnly pgrange bs of
Left e -> returnError ConversionFailed f e
Expand Down