@@ -15,25 +15,24 @@ module Squeel.PostgreSQL.Value where
1515
1616import Control.Arrow (left)
1717import Data.Aeson (FromJSON, ToJSON, eitherDecodeStrict, encode)
18−import Data.Bits (Bits)
1918import Data.ByteString (ByteString)
20−import qualified Data.ByteString.Lazy as Lazy (ByteString, toStrict)
2119import Data.Int (Int16,Int32,Int64)
2220import Data.Proxy
2321import Data.Vinyl
2422import Data.Vinyl.Functor
2523import PostgreSQL.Binary.Decoder (Decoder)
26−import qualified PostgreSQL.Binary.Decoder as Decoder
2724import PostgreSQL.Binary.Encoder (Encoder)
28−import qualified PostgreSQL.Binary.Encoder as Encoder
2925import Data.Proxy (Proxy)
3026import Data.Scientific (Scientific)
3127import Data.Text (Text)
3228import Data.Time (Day, TimeOfDay, TimeZone, LocalTime, UTCTime, DiffTime)
29+import Data.UUID (UUID)
30+
31+import qualified Data.ByteString.Lazy as Lazy (ByteString, toStrict)
3332import qualified Data.Text as Text (pack)
3433import qualified Data.Text.Lazy as Lazy (Text)
35−import Data.UUID (UUID)
36−import Data.Word (Word16, Word32, Word64)
34+import qualified PostgreSQL.Binary.Decoder as Decoder
35+import qualified PostgreSQL.Binary.Encoder as Encoder
3736
3837import Squeel.PostgreSQL.Type
3938
@@ -42,94 +41,92 @@ decodeValue = Decoder.run . fromValue
4241
4342class FromValue (pg :: PGType) x where
4443 fromValue :: Proxy pg -> Decoder x
45−instance (Integral x, Bits x) => FromValue ('PGType "int") x where
44+instance FromValue 'PGInt2 Int16 where
45+ fromValue _ = Decoder.int
46+instance FromValue 'PGInt4 Int32 where
47+ fromValue _ = Decoder.int
48+instance FromValue 'PGInt8 Int64 where
4649 fromValue _ = Decoder.int
47−instance FromValue ('PGType "float4") Float where
50+instance FromValue 'PGFloat4 Float where
4851 fromValue _ = Decoder.float4
49−instance FromValue ('PGType "float8") Double where
52+instance FromValue 'PGFloat8 Double where
5053 fromValue _ = Decoder.float8
51−instance FromValue ('PGType "bool") Bool where
54+instance FromValue 'PGBool Bool where
5255 fromValue _ = Decoder.bool
53−instance FromValue ('PGType "bytea") ByteString where
56+instance FromValue 'PGBytea ByteString where
5457 fromValue _ = Decoder.bytea_strict
55−instance FromValue ('PGType "bytea") Lazy.ByteString where
58+instance FromValue 'PGBytea Lazy.ByteString where
5659 fromValue _ = Decoder.bytea_lazy
57−instance FromValue ('PGType "text") Text where
60+instance FromValue 'PGText Text where
5861 fromValue _ = Decoder.text_strict
59−instance FromValue ('PGType "text") Lazy.Text where
62+instance FromValue 'PGText Lazy.Text where
6063 fromValue _ = Decoder.text_lazy
61−instance FromValue ('PGType "char") Char where
64+instance FromValue ('PGChar 1) Char where
6265 fromValue _ = Decoder.char
63−instance FromValue ('PGType "numeric") Scientific where
66+instance FromValue 'PGNumeric Scientific where
6467 fromValue _ = Decoder.numeric
65−instance FromValue ('PGType "uuid") UUID where
68+instance FromValue 'PGUuid UUID where
6669 fromValue _ = Decoder.uuid
67−instance FromJSON x => FromValue ('PGType "json") x where
70+instance FromJSON x => FromValue 'PGJson x where
6871 fromValue _ = Decoder.json_bytes (left Text.pack . eitherDecodeStrict)
69−instance FromJSON x => FromValue ('PGType "jsonb") x where
72+instance FromJSON x => FromValue 'PGJsonb x where
7073 fromValue _ = Decoder.jsonb_bytes (left Text.pack . eitherDecodeStrict)
71−instance FromValue ('PGType "date") Day where
74+instance FromValue 'PGDate Day where
7275 fromValue _ = Decoder.date
73−instance FromValue ('PGType "time") TimeOfDay where
76+instance FromValue 'PGTime TimeOfDay where
7477 fromValue _ = Decoder.time_int
75−instance FromValue ('PGType "timetz") (TimeOfDay, TimeZone) where
78+instance FromValue 'PGTimeTZ (TimeOfDay, TimeZone) where
7679 fromValue _ = Decoder.timetz_int
77−instance FromValue ('PGType "timestamp") LocalTime where
80+instance FromValue 'PGTimestamp LocalTime where
7881 fromValue _ = Decoder.timestamp_int
79−instance FromValue ('PGType "timestamptz") UTCTime where
82+instance FromValue 'PGTimestampTZ UTCTime where
8083 fromValue _ = Decoder.timestamptz_int
81−instance FromValue ('PGType "interval") DiffTime where
84+instance FromValue 'PGInterval DiffTime where
8285 fromValue _ = Decoder.interval_int
8386
8487class ToValue x (pg :: PGType) where
8588 toValue :: Proxy pg -> Encoder x
86−instance ToValue Int16 ('PGType "int2") where
89+instance ToValue Int16 'PGInt2 where
8790 toValue _ = Encoder.int2_int16
88−instance ToValue Int32 ('PGType "int4") where
91+instance ToValue Int32 'PGInt4 where
8992 toValue _ = Encoder.int4_int32
90−instance ToValue Int64 ('PGType "int8") where
93+instance ToValue Int64 'PGInt8 where
9194 toValue _ = Encoder.int8_int64
92−instance ToValue Word16 ('PGType "word2") where
93− toValue _ = Encoder.int2_word16
94−instance ToValue Word32 ('PGType "word4") where
95− toValue _ = Encoder.int4_word32
96−instance ToValue Word64 ('PGType "word8") where
97− toValue _ = Encoder.int8_word64
98−instance ToValue Float ('PGType "float4") where
95+instance ToValue Float 'PGFloat4 where
9996 toValue _ = Encoder.float4
100−instance ToValue Double ('PGType "float8") where
97+instance ToValue Double 'PGFloat8 where
10198 toValue _ = Encoder.float8
102−instance ToValue Bool ('PGType "bool") where
99+instance ToValue Bool 'PGBool where
103100 toValue _ = Encoder.bool
104−instance ToValue ByteString ('PGType "bytea") where
101+instance ToValue ByteString 'PGBytea where
105102 toValue _ = Encoder.bytea_strict
106−instance ToValue Lazy.ByteString ('PGType "bytea") where
103+instance ToValue Lazy.ByteString 'PGBytea where
107104 toValue _ = Encoder.bytea_lazy
108−instance ToValue Text ('PGType "text") where
105+instance ToValue Text 'PGText where
109106 toValue _ = Encoder.text_strict
110−instance ToValue Lazy.Text ('PGType "text") where
107+instance ToValue Lazy.Text 'PGText where
111108 toValue _ = Encoder.text_lazy
112−instance ToValue Char ('PGType "char") where
109+instance ToValue Char ('PGChar 1) where
113110 toValue _ = Encoder.char
114−instance ToValue Scientific ('PGType "numeric") where
111+instance ToValue Scientific 'PGNumeric where
115112 toValue _ = Encoder.numeric
116−instance ToValue UUID ('PGType "uuid") where
113+instance ToValue UUID 'PGUuid where
117114 toValue _ = Encoder.uuid
118−instance ToJSON x => ToValue x ('PGType "json") where
115+instance ToJSON x => ToValue x 'PGJson where
119116 toValue _ = Encoder.json_bytes . Lazy.toStrict . encode
120−instance ToJSON x => ToValue x ('PGType "jsonb") where
117+instance ToJSON x => ToValue x 'PGJsonb where
121118 toValue _ = Encoder.jsonb_bytes . Lazy.toStrict . encode
122−instance ToValue Day ('PGType "date") where
119+instance ToValue Day 'PGDate where
123120 toValue _ = Encoder.date
124−instance ToValue TimeOfDay ('PGType "time") where
121+instance ToValue TimeOfDay 'PGTime where
125122 toValue _ = Encoder.time_int
126−instance ToValue (TimeOfDay, TimeZone) ('PGType "timetz") where
123+instance ToValue (TimeOfDay, TimeZone) 'PGTimeTZ where
127124 toValue _ = Encoder.timetz_int
128−instance ToValue LocalTime ('PGType "timestamp") where
125+instance ToValue LocalTime 'PGTimestamp where
129126 toValue _ = Encoder.timestamp_int
130−instance ToValue UTCTime ('PGType "timestamptz") where
127+instance ToValue UTCTime 'PGTimestampTZ where
131128 toValue _ = Encoder.timestamptz_int
132−instance ToValue DiffTime ('PGType "interval") where
129+instance ToValue DiffTime 'PGInterval where
133130 toValue _ = Encoder.interval_int
134131
135132class ToValues xs pgs where