@@ -53,7 +53,6 @@ import Data.Word
5353import Generics.SOP
5454import GHC.TypeLits
5555import Network.IP.Addr
56−import Text.Read (readMaybe)
5756
5857import qualified Data.ByteString.Lazy as Lazy
5958import qualified Data.ByteString as Strict hiding (pack, unpack)
@@ -126,18 +125,17 @@ instance
126125 ) => ToParam x ('PGenum labels) where
127126 toParam =
128127 let
129− gcons :: forall y. (HasDatatypeInfo y, Generic y) => y -> String
130− gcons = gconstructor (constructorInfo (datatypeInfo (Proxy @y))) . from
131−
132− gconstructor :: NP ConstructorInfo xs -> SOP I xs -> String
133− gconstructor Nil _ = ""
134− gconstructor (Constructor name :* _) (SOP (Z _)) = name
135− gconstructor (Infix name _ _ :* _) (SOP (Z _)) = name
136− gconstructor (Record name _ :* _) (SOP (Z _)) = name
137− gconstructor (_ :* constructors) (SOP (S xs)) =
138− gconstructor constructors (SOP xs)
128+ gshowConstructor :: NP ConstructorInfo xss -> SOP I xss -> String
129+ gshowConstructor Nil _ = ""
130+ gshowConstructor (constructor :* _) (SOP (Z _)) =
131+ constructorName constructor
132+ gshowConstructor (_ :* constructors) (SOP (S xs)) =
133+ gshowConstructor constructors (SOP xs)
139134 in
140− K . Encoding.text_strict . Strict.pack . gcons
135+ K . Encoding.text_strict
136+ . Strict.pack
137+ . gshowConstructor (constructorInfo (datatypeInfo (Proxy @x)))
138+ . from
141139instance
142140 ( SListI fields
143141 , MapMaybes xs
@@ -278,10 +276,27 @@ instance FromValue pg y => FromValue ('PGfixarray n pg) (Vector (Maybe y)) where
278276 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
279277instance
280278 ( IsEnumType y
281− , Read y
279+ , HasDatatypeInfo y
282280 , SameLabels (DatatypeInfoOf y) labels
283281 ) => FromValue ('PGenum labels) y where
284− fromValue _ = Decoding.enum (readMaybe . Strict.unpack)
282+ fromValue _ =
283+ let
284+ greadConstructor
285+ :: All ((~) '[]) xss
286+ => NP ConstructorInfo xss
287+ -> String
288+ -> Maybe (SOP I xss)
289+ greadConstructor Nil _ = Nothing
290+ greadConstructor (constructor :* constructors) name =
291+ if name == constructorName constructor
292+ then Just (SOP (Z Nil))
293+ else SOP . S . unSOP <$> greadConstructor constructors name
294+ in
295+ Decoding.enum
296+ $ fmap to
297+ . greadConstructor (constructorInfo (datatypeInfo (Proxy @y)))
298+ . Strict.unpack
299+
285300instance
286301 ( SListI fields
287302 , MapMaybes ys