@@ -16,7 +16,7 @@
1616module Database.PostgreSQL.Simple.HStore.Implementation where
1717
1818import Control.Applicative
19−import Blaze.ByteString.Builder
19+import Blaze.ByteString.Builder as Blaze
2020 ( Builder, toLazyByteString, copyByteString )
2121import Blaze.ByteString.Builder.Char8 (fromChar)
2222import qualified Data.Attoparsec.ByteString as P
@@ -42,6 +42,16 @@ data HStoreBuilder
4242 | Comma !Builder
4343 deriving (Typeable)
4444
45+toBuilder :: HStoreBuilder -> Builder
46+toBuilder x = case x of
47+ Empty -> mempty
48+ Comma x -> x
49+
50+toLazyByteString :: HStoreBuilder -> BL.ByteString
51+toLazyByteString x = case x of
52+ Empty -> BL.empty
53+ Comma x -> Blaze.toLazyByteString x
54+
4555instance Monoid HStoreBuilder where
4656 mempty = Empty
4757 mappend Empty x = x
@@ -94,7 +104,7 @@ hstore (toHStoreText -> (HStoreText key)) (toHStoreText -> (HStoreText val)) =
94104
95105instance ToField HStoreBuilder where
96106 toField Empty = toField (BS.empty)
97− toField (Comma x) = toField (toLazyByteString x)
107+ toField (Comma x) = toField (Blaze.toLazyByteString x)
98108
99109newtype HStoreList = HStoreList [(Text,Text)] deriving (Typeable, Show)
100110
@@ -108,14 +118,14 @@ instance FromField HStoreList where
108118 then returnError Incompatible f ""
109119 else case mdat of
110120 Nothing -> returnError UnexpectedNull f ""
111− Just dat ->
121+ Just dat ->
112122 case P.parseOnly parseHStore dat of
113− Left err ->
123+ Left err ->
114124 returnError ConversionFailed f err
115− Right (Left err) ->
125+ Right (Left err) ->
116126 returnError ConversionFailed f "unicode exception" <|>
117127 conversionError err
118− Right (Right val) ->
128+ Right (Right val) ->
119129 return val
120130
121131newtype HStoreMap = HStoreMap (Map Text Text) deriving (Eq, Ord, Typeable, Show)