@@ -16,7 +16,7 @@
16module Database.PostgreSQL.Simple.HStore.Implementation where
16module Database.PostgreSQL.Simple.HStore.Implementation where
18import Control.Applicative
18import Control.Applicative
19−import Blaze.ByteString.Builder
19+import Blaze.ByteString.Builder as Blaze
20 ( Builder, toLazyByteString, copyByteString )
20 ( Builder, toLazyByteString, copyByteString )
21import Blaze.ByteString.Builder.Char8 (fromChar)
21import Blaze.ByteString.Builder.Char8 (fromChar)
22import qualified Data.Attoparsec.ByteString as P
22import qualified Data.Attoparsec.ByteString as P
@@ -42,6 +42,16 @@ data HStoreBuilder
42 | Comma !Builder
42 | Comma !Builder
43 deriving (Typeable)
43 deriving (Typeable)
45+toBuilder :: HStoreBuilder -> Builder
46+toBuilder x = case x of
50+toLazyByteString :: HStoreBuilder -> BL.ByteString
51+toLazyByteString x = case x of
53+ Comma x -> Blaze.toLazyByteString x
45instance Monoid HStoreBuilder where
55instance Monoid HStoreBuilder where
46 mempty = Empty
56 mempty = Empty
47 mappend Empty x = x
57 mappend Empty x = x
@@ -94,7 +104,7 @@ hstore (toHStoreText -> (HStoreText key)) (toHStoreText -> (HStoreText val)) =
95instance ToField HStoreBuilder where
105instance ToField HStoreBuilder where
96 toField Empty = toField (BS.empty)
106 toField Empty = toField (BS.empty)
97− toField (Comma x) = toField (toLazyByteString x)
107+ toField (Comma x) = toField (Blaze.toLazyByteString x)
99newtype HStoreList = HStoreList [(Text,Text)] deriving (Typeable, Show)
109newtype HStoreList = HStoreList [(Text,Text)] deriving (Typeable, Show)
@@ -108,14 +118,14 @@ instance FromField HStoreList where
108 then returnError Incompatible f ""
118 then returnError Incompatible f ""
109 else case mdat of
119 else case mdat of
110 Nothing -> returnError UnexpectedNull f ""
120 Nothing -> returnError UnexpectedNull f ""
111− Just dat ->
121+ Just dat ->
112 case P.parseOnly parseHStore dat of
122 case P.parseOnly parseHStore dat of
113− Left err ->
123+ Left err ->
114 returnError ConversionFailed f err
124 returnError ConversionFailed f err
115− Right (Left err) ->
125+ Right (Left err) ->
116 returnError ConversionFailed f "unicode exception" <|>
126 returnError ConversionFailed f "unicode exception" <|>
117 conversionError err
127 conversionError err
118− Right (Right val) ->
128+ Right (Right val) ->
119 return val
129 return val
121newtype HStoreMap = HStoreMap (Map Text Text) deriving (Eq, Ord, Typeable, Show)
131newtype HStoreMap = HStoreMap (Map Text Text) deriving (Eq, Ord, Typeable, Show)