@@ -46,6 +46,7 @@ module Squeal.PostgreSQL.Binary
4646
4747import BinaryParser
4848import Data.Aeson hiding (Null)
49+import Data.Char (toUpper)
4950import Data.Int
5051import Data.Kind
5152import Data.Scientific
@@ -56,6 +57,7 @@ import Data.Word
5657import Generics.SOP
5758import GHC.TypeLits
5859import Network.IP.Addr
60+import Text.Read (readMaybe)
5961
6062import qualified Data.ByteString.Lazy as Lazy
6163import qualified Data.ByteString as Strict hiding (unpack)
@@ -203,6 +205,21 @@ instance FromValue pg y => FromValue ('PGfixarray n pg) (Vector (Maybe y)) where
203205 fromValue _ = Decoding.array
204206 (Decoding.dimensionArray Vector.replicateM
205207 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
208+instance
209+ ( IsEnumType y
210+ , Read y
211+ -- , SameLabels (DatatypeInfoOf y) labels
212+ --
213+ -- uncomment above constraint when GHC issue #11671 is fixed
214+ -- Allow labels starting with uppercase with OverloadedLabels
215+ -- https://ghc.haskell.org/trac/ghc/ticket/11671?cversion=0&cnum_hist=8
216+ ) => FromValue ('PGenum labels) y where
217+ fromValue _ =
218+ let
219+ upper "" = ""
220+ upper (ch:chs) = toUpper ch : chs
221+ in
222+ Decoding.enum (readMaybe . upper . Strict.unpack)
206223instance
207224 ( SListI fields
208225 , IsMaybes ys