@@ -11,16 +11,14 @@
1111
1212module Squeel.PostgreSQL.Binary where
1313
14−import Debug.Trace
15−
1614import Control.Arrow (left)
1715import Data.Aeson (FromJSON, ToJSON, eitherDecodeStrict, encode)
1816import Data.ByteString (ByteString)
1917import Data.Int (Int16,Int32,Int64)
2018import Data.Vinyl
2119import Data.Vinyl.Functor
22−import PostgreSQL.Binary.Decoder (Decoder)
23−import PostgreSQL.Binary.Encoder (Encoder)
20+import PostgreSQL.Binary.Decoding (Value)
21+import PostgreSQL.Binary.Encoding (Encoding)
2422import Data.Scientific (Scientific)
2523import Data.Text (Text)
2624import Data.Time (Day, TimeOfDay, TimeZone, LocalTime, UTCTime, DiffTime)
@@ -30,20 +28,20 @@ import GHC.Exts
3028import qualified Data.ByteString.Lazy as Lazy (ByteString, toStrict)
3129import qualified Data.Text as Text (pack)
3230import qualified Data.Text.Lazy as Lazy (Text)
33−import qualified PostgreSQL.Binary.Decoder as Decoder
34−import qualified PostgreSQL.Binary.Encoder as Encoder
31+import qualified PostgreSQL.Binary.Decoding as Decoder
32+import qualified PostgreSQL.Binary.Encoding as Encoder
3533
3634import Squeel.PostgreSQL.Schema
3735
3836decodeValue :: FromValue pg x => Proxy# pg -> ByteString -> Either Text x
39−decodeValue p = Decoder.run $ fromValue p
37+decodeValue p = Decoder.valueParser $ fromValue p
4038
4139class FromValue pg x where
42− fromValue :: Proxy# pg -> Decoder x
40+ fromValue :: Proxy# pg -> Value x
4341instance FromValue 'PGInt2 Int16 where
4442 fromValue _ = Decoder.int
4543instance FromValue 'PGInt4 Int32 where
46− fromValue _ = trace "Decoder.int" Decoder.int
44+ fromValue _ = Decoder.int
4745instance FromValue 'PGInt8 Int64 where
4846 fromValue _ = Decoder.int
4947instance FromValue 'PGFloat4 Float where
@@ -95,7 +93,7 @@ instance (FromValue pg x, FromValues pgs xs)
9593 :& decodeValues (proxy# :: Proxy# pgs) results
9694
9795class ToValue x pg where
98− toValue :: Proxy# pg -> Encoder x
96+ toValue :: Proxy# pg -> x -> Encoding
9997instance ToValue Int16 'PGInt2 where
10098 toValue _ = Encoder.int2_int16
10199instance ToValue Int32 'PGInt4 where
@@ -117,7 +115,7 @@ instance ToValue Text 'PGText where
117115instance ToValue Lazy.Text 'PGText where
118116 toValue _ = Encoder.text_lazy
119117instance ToValue Char ('PGChar 1) where
120− toValue _ = Encoder.char
118+ toValue _ = Encoder.char_utf8
121119instance ToValue Scientific 'PGNumeric where
122120 toValue _ = Encoder.numeric
123121instance ToValue UUID 'PGUuid where
@@ -145,5 +143,5 @@ instance ToValues '[] '[] where toValues _ _ = []
145143instance (ToValue x pg, ToValues xs pgs)
146144 => ToValues (x ': xs) (pg ': pgs) where
147145 toValues _ (Identity x :& xs)
148− = Encoder.run (toValue (proxy# :: Proxy# pg)) x
146+ = Encoder.encodingBytes ((toValue (proxy# :: Proxy# pg)) x)
149147 : toValues (proxy# :: Proxy# pgs) xs