git.iko.soy/typeable/postgresql-simple
on master help sign in
Renamed Data Constructors (mostly from builtin types)
7687a3eLeon P Smith
src/Database/PostgreSQL/Simple.hs+2−2
@@ -310,7 +310,7 @@ buildQuery conn q template xs = zipParams (split template) <$> mapM sub xs
310 utf8ToString = T.unpack . TE.decodeUtf8
310 utf8ToString = T.unpack . TE.decodeUtf8
311 sub (Plain b) = pure b
311 sub (Plain b) = pure b
312 sub (Escape s) = quote <$> escapeStringConn conn s
312 sub (Escape s) = quote <$> escapeStringConn conn s
313− sub (EscapeBytea s) = quote <$> escapeByteaConn conn s
313+ sub (EscapeByteA s) = quote <$> escapeByteaConn conn s
314 sub (Many ys) = mconcat <$> mapM sub ys
314 sub (Many ys) = mconcat <$> mapM sub ys
315 split s = fromByteString h : if B.null t then [] else split (B.tail t)
315 split s = fromByteString h : if B.null t then [] else split (B.tail t)
316 where (h,t) = B.break (=='?') s
316 where (h,t) = B.break (=='?') s
@@ -678,7 +678,7 @@ fmtError msg q xs = throw FormatError {
678 }
678 }
679 where twiddle (Plain b) = toByteString b
679 where twiddle (Plain b) = toByteString b
680 twiddle (Escape s) = s
680 twiddle (Escape s) = s
681− twiddle (EscapeBytea s) = s
681+ twiddle (EscapeByteA s) = s
682 twiddle (Many ys) = B.concat (map twiddle ys)
682 twiddle (Many ys) = B.concat (map twiddle ys)
683
683
684-- $use
684-- $use
src/Database/PostgreSQL/Simple/BuiltinTypes.hs+117−117
@@ -3,7 +3,7 @@
3------------------------------------------------------------------------------
3------------------------------------------------------------------------------
4-- |
4-- |
5-- Module: Database.PostgreSQL.Simple.BuiltinTypes
5-- Module: Database.PostgreSQL.Simple.BuiltinTypes
6−-- Copyright: (c) 2011 Leon P Smith
6+-- Copyright: (c) 2011-2012 Leon P Smith
7-- License: BSD3
7-- License: BSD3
8-- Maintainer: Leon P Smith <leon@melding-monads.com>
8-- Maintainer: Leon P Smith <leon@melding-monads.com>
9-- Stability: experimental
9-- Stability: experimental
@@ -27,13 +27,13 @@ import qualified Database.PostgreSQL.LibPQ as PQ
27
27
28data BuiltinType
28data BuiltinType
29 = Bool
29 = Bool
30− | Bytea
30+ | ByteA
31 | Char
31 | Char
32 | Name
32 | Name
33 | Int8
33 | Int8
34 | Int2
34 | Int2
35 | Int4
35 | Int4
36− | Regproc
36+ | RegProc
37 | Text
37 | Text
38 | Oid
38 | Oid
39 | Tid
39 | Tid
@@ -41,7 +41,7 @@ data BuiltinType
41 | Cid
41 | Cid
42 | Xml
42 | Xml
43 | Point
43 | Point
44− | Lseg
44+ | LSeg
45 | Path
45 | Path
46 | Box
46 | Box
47 | Polygon
47 | Polygon
@@ -49,88 +49,88 @@ data BuiltinType
49 | Cidr
49 | Cidr
50 | Float4
50 | Float4
51 | Float8
51 | Float8
52− | Abstime
52+ | AbsTime
53− | Reltime
53+ | RelTime
54− | Tinterval
54+ | TInterval
55 | Unknown
55 | Unknown
56 | Circle
56 | Circle
57 | Money
57 | Money
58− | Macaddr
58+ | MacAddr
59 | Inet
59 | Inet
60− | Bpchar
60+ | BpChar
61− | Varchar
61+ | VarChar
62 | Date
62 | Date
63 | Time
63 | Time
64 | Timestamp
64 | Timestamp
65− | TimestampWithTimeZone
65+ | TimestampTZ
66 | Interval
66 | Interval
67− | TimeWithTimeZone
67+ | TimeTZ
68 | Bit
68 | Bit
69− | Varbit
69+ | VarBit
70 | Numeric
70 | Numeric
71− | Refcursor
71+ | RefCursor
72 | Record
72 | Record
73 | Void
73 | Void
74 deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
74 deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
75
75
76builtin2oid :: BuiltinType -> PQ.Oid
76builtin2oid :: BuiltinType -> PQ.Oid
77builtin2oid typ = PQ.Oid $ case typ of
77builtin2oid typ = PQ.Oid $ case typ of
78− Bool -> 16
78+ Bool -> 16
79− Bytea -> 17
79+ ByteA -> 17
80− Char -> 18
80+ Char -> 18
81− Name -> 19
81+ Name -> 19
82− Int8 -> 20
82+ Int8 -> 20
83− Int2 -> 21
83+ Int2 -> 21
84− Int4 -> 23
84+ Int4 -> 23
85− Regproc -> 24
85+ RegProc -> 24
86− Text -> 25
86+ Text -> 25
87− Oid -> 26
87+ Oid -> 26
88− Tid -> 27
88+ Tid -> 27
89− Xid -> 28
89+ Xid -> 28
90− Cid -> 29
90+ Cid -> 29
91− Xml -> 142
91+ Xml -> 142
92− Point -> 600
92+ Point -> 600
93− Lseg -> 601
93+ LSeg -> 601
94− Path -> 602
94+ Path -> 602
95− Box -> 603
95+ Box -> 603
96− Polygon -> 604
96+ Polygon -> 604
97− Line -> 628
97+ Line -> 628
98− Cidr -> 650
98+ Cidr -> 650
99− Float4 -> 700
99+ Float4 -> 700
100− Float8 -> 701
100+ Float8 -> 701
101− Abstime -> 702
101+ AbsTime -> 702
102− Reltime -> 703
102+ RelTime -> 703
103− Tinterval -> 704
103+ TInterval -> 704
104− Unknown -> 705
104+ Unknown -> 705
105− Circle -> 718
105+ Circle -> 718
106− Money -> 790
106+ Money -> 790
107− Macaddr -> 829
107+ MacAddr -> 829
108− Inet -> 869
108+ Inet -> 869
109− Bpchar -> 1042
109+ BpChar -> 1042
110− Varchar -> 1043
110+ VarChar -> 1043
111− Date -> 1082
111+ Date -> 1082
112− Time -> 1083
112+ Time -> 1083
113− Timestamp -> 1114
113+ Timestamp -> 1114
114− TimestampWithTimeZone -> 1184
114+ TimestampTZ -> 1184
115− Interval -> 1186
115+ Interval -> 1186
116− TimeWithTimeZone -> 1266
116+ TimeTZ -> 1266
117− Bit -> 1560
117+ Bit -> 1560
118− Varbit -> 1562
118+ VarBit -> 1562
119− Numeric -> 1700
119+ Numeric -> 1700
120− Refcursor -> 1790
120+ RefCursor -> 1790
121− Record -> 2249
121+ Record -> 2249
122− Void -> 2278
122+ Void -> 2278
123
123
124oid2builtin :: PQ.Oid -> Maybe BuiltinType
124oid2builtin :: PQ.Oid -> Maybe BuiltinType
125oid2builtin (PQ.Oid x) = case x of
125oid2builtin (PQ.Oid x) = case x of
126 16 -> Just Bool
126 16 -> Just Bool
127− 17 -> Just Bytea
127+ 17 -> Just ByteA
128 18 -> Just Char
128 18 -> Just Char
129 19 -> Just Name
129 19 -> Just Name
130 20 -> Just Int8
130 20 -> Just Int8
131 21 -> Just Int2
131 21 -> Just Int2
132 23 -> Just Int4
132 23 -> Just Int4
133− 24 -> Just Regproc
133+ 24 -> Just RegProc
134 25 -> Just Text
134 25 -> Just Text
135 26 -> Just Oid
135 26 -> Just Oid
136 27 -> Just Tid
136 27 -> Just Tid
@@ -138,7 +138,7 @@ oid2builtin (PQ.Oid x) = case x of
138 29 -> Just Cid
138 29 -> Just Cid
139 142 -> Just Xml
139 142 -> Just Xml
140 600 -> Just Point
140 600 -> Just Point
141− 601 -> Just Lseg
141+ 601 -> Just LSeg
142 602 -> Just Path
142 602 -> Just Path
143 603 -> Just Box
143 603 -> Just Box
144 604 -> Just Polygon
144 604 -> Just Polygon
@@ -146,77 +146,77 @@ oid2builtin (PQ.Oid x) = case x of
146 650 -> Just Cidr
146 650 -> Just Cidr
147 700 -> Just Float4
147 700 -> Just Float4
148 701 -> Just Float8
148 701 -> Just Float8
149− 702 -> Just Abstime
149+ 702 -> Just AbsTime
150− 703 -> Just Reltime
150+ 703 -> Just RelTime
151− 704 -> Just Tinterval
151+ 704 -> Just TInterval
152 705 -> Just Unknown
152 705 -> Just Unknown
153 718 -> Just Circle
153 718 -> Just Circle
154 790 -> Just Money
154 790 -> Just Money
155− 829 -> Just Macaddr
155+ 829 -> Just MacAddr
156 869 -> Just Inet
156 869 -> Just Inet
157− 1042 -> Just Bpchar
157+ 1042 -> Just BpChar
158− 1043 -> Just Varchar
158+ 1043 -> Just VarChar
159 1082 -> Just Date
159 1082 -> Just Date
160 1083 -> Just Time
160 1083 -> Just Time
161 1114 -> Just Timestamp
161 1114 -> Just Timestamp
162− 1184 -> Just TimestampWithTimeZone
162+ 1184 -> Just TimestampTZ
163 1186 -> Just Interval
163 1186 -> Just Interval
164− 1266 -> Just TimeWithTimeZone
164+ 1266 -> Just TimeTZ
165 1560 -> Just Bit
165 1560 -> Just Bit
166− 1562 -> Just Varbit
166+ 1562 -> Just VarBit
167 1700 -> Just Numeric
167 1700 -> Just Numeric
168− 1790 -> Just Refcursor
168+ 1790 -> Just RefCursor
169 2249 -> Just Record
169 2249 -> Just Record
170 2278 -> Just Void
170 2278 -> Just Void
171 _ -> Nothing
171 _ -> Nothing
172
172
173builtin2typname :: BuiltinType -> ByteString
173builtin2typname :: BuiltinType -> ByteString
174builtin2typname typ = case typ of
174builtin2typname typ = case typ of
175− Bool -> bool
175+ Bool -> bool
176− Bytea -> bytea
176+ ByteA -> bytea
177− Char -> char
177+ Char -> char
178− Name -> name
178+ Name -> name
179− Int8 -> int8
179+ Int8 -> int8
180− Int2 -> int2
180+ Int2 -> int2
181− Int4 -> int4
181+ Int4 -> int4
182− Regproc -> regproc
182+ RegProc -> regproc
183− Text -> text
183+ Text -> text
184− Oid -> oid
184+ Oid -> oid
185− Tid -> tid
185+ Tid -> tid
186− Xid -> xid
186+ Xid -> xid
187− Cid -> cid
187+ Cid -> cid
188− Xml -> xml
188+ Xml -> xml
189− Point -> point
189+ Point -> point
190− Lseg -> lseg
190+ LSeg -> lseg
191− Path -> path
191+ Path -> path
192− Box -> box
192+ Box -> box
193− Polygon -> polygon
193+ Polygon -> polygon
194− Line -> line
194+ Line -> line
195− Cidr -> cidr
195+ Cidr -> cidr
196− Float4 -> float4
196+ Float4 -> float4
197− Float8 -> float8
197+ Float8 -> float8
198− Abstime -> abstime
198+ AbsTime -> abstime
199− Reltime -> reltime
199+ RelTime -> reltime
200− Tinterval -> tinterval
200+ TInterval -> tinterval
201− Unknown -> unknown
201+ Unknown -> unknown
202− Circle -> circle
202+ Circle -> circle
203− Money -> money
203+ Money -> money
204− Macaddr -> macaddr
204+ MacAddr -> macaddr
205− Inet -> inet
205+ Inet -> inet
206− Bpchar -> bpchar
206+ BpChar -> bpchar
207− Varchar -> varchar
207+ VarChar -> varchar
208− Date -> date
208+ Date -> date
209− Time -> time
209+ Time -> time
210− Timestamp -> timestamp
210+ Timestamp -> timestamp
211− TimestampWithTimeZone -> timestamptz
211+ TimestampTZ -> timestamptz
212− Interval -> interval
212+ Interval -> interval
213− TimeWithTimeZone -> timetz
213+ TimeTZ -> timetz
214− Bit -> bit
214+ Bit -> bit
215− Varbit -> varbit
215+ VarBit -> varbit
216− Numeric -> numeric
216+ Numeric -> numeric
217− Refcursor -> refcursor
217+ RefCursor -> refcursor
218− Record -> record
218+ Record -> record
219− Void -> void
219+ Void -> void
220
220
221oid2typname :: PQ.Oid -> Maybe ByteString
221oid2typname :: PQ.Oid -> Maybe ByteString
222oid2typname (PQ.Oid x) = case x of
222oid2typname (PQ.Oid x) = case x of
src/Database/PostgreSQL/Simple/FromField.hs+8−8
@@ -160,7 +160,7 @@ unBinary :: Binary t -> t
160unBinary (Binary x) = x
160unBinary (Binary x) = x
161
161
162instance FromField SB.ByteString where
162instance FromField SB.ByteString where
163− fromField f dat = if typeOid f == builtin2oid Bytea
163+ fromField f dat = if typeOid f == builtin2oid ByteA
164 then unBinary <$> fromField f dat
164 then unBinary <$> fromField f dat
165 else doFromField f okText' (pure . B.copy) dat
165 else doFromField f okText' (pure . B.copy) dat
166
166
@@ -195,10 +195,10 @@ instance FromField [Char] where
195 fromField f dat = ST.unpack <$> fromField f dat
195 fromField f dat = ST.unpack <$> fromField f dat
196
196
197instance FromField UTCTime where
197instance FromField UTCTime where
198− fromField = ff TimestampWithTimeZone "UTCTime" parseUTCTime
198+ fromField = ff TimestampTZ "UTCTime" parseUTCTime
199
199
200instance FromField ZonedTime where
200instance FromField ZonedTime where
201− fromField = ff TimestampWithTimeZone "ZonedTime" parseZonedTime
201+ fromField = ff TimestampTZ "ZonedTime" parseZonedTime
202
202
203instance FromField LocalTime where
203instance FromField LocalTime where
204 fromField = ff Timestamp "LocalTime" parseLocalTime
204 fromField = ff Timestamp "LocalTime" parseLocalTime
@@ -210,10 +210,10 @@ instance FromField TimeOfDay where
210 fromField = ff Time "TimeOfDay" parseTimeOfDay
210 fromField = ff Time "TimeOfDay" parseTimeOfDay
211
211
212instance FromField UTCTimestamp where
212instance FromField UTCTimestamp where
213− fromField = ff TimestampWithTimeZone "UTCTimestamp" parseUTCTimestamp
213+ fromField = ff TimestampTZ "UTCTimestamp" parseUTCTimestamp
214
214
215instance FromField ZonedTimestamp where
215instance FromField ZonedTimestamp where
216− fromField = ff TimestampWithTimeZone "ZonedTimestamp" parseZonedTimestamp
216+ fromField = ff TimestampTZ "ZonedTimestamp" parseZonedTimestamp
217
217
218instance FromField LocalTimestamp where
218instance FromField LocalTimestamp where
219 fromField = ff Timestamp "LocalTimestamp" parseLocalTimestamp
219 fromField = ff Timestamp "LocalTimestamp" parseLocalTimestamp
@@ -251,9 +251,9 @@ compat :: Compat -> Compat -> Bool
251compat (Compat a) (Compat b) = a .&. b /= 0
251compat (Compat a) (Compat b) = a .&. b /= 0
252
252
253okText, okText', okBinary, ok16, ok32, ok64, okInt :: Compat
253okText, okText', okBinary, ok16, ok32, ok64, okInt :: Compat
254−okText = mkCompats [Name,Text,Char,Bpchar,Varchar]
254+okText = mkCompats [Name,Text,Char,BpChar,VarChar]
255−okText' = mkCompats [Name,Text,Char,Bpchar,Varchar,Unknown]
255+okText' = mkCompats [Name,Text,Char,BpChar,VarChar,Unknown]
256−okBinary = mkCompats [Bytea]
256+okBinary = mkCompats [ByteA]
257ok16 = mkCompats [Int2]
257ok16 = mkCompats [Int2]
258ok32 = mkCompats [Int2,Int4]
258ok32 = mkCompats [Int2,Int4]
259ok64 = mkCompats [Int2,Int4,Int8]
259ok64 = mkCompats [Int2,Int4,Int8]
src/Database/PostgreSQL/Simple/ToField.hs+4−4
@@ -53,7 +53,7 @@ data Action =
53 -- ^ Escape and enclose in quotes before substituting. Use for all
53 -- ^ Escape and enclose in quotes before substituting. Use for all
54 -- text-like types, and anything else that may contain unsafe
54 -- text-like types, and anything else that may contain unsafe
55 -- characters when rendered.
55 -- characters when rendered.
56− | EscapeBytea ByteString
56+ | EscapeByteA ByteString
57 -- ^ Escape binary data for use as a @bytea@ literal. Include surrounding
57 -- ^ Escape binary data for use as a @bytea@ literal. Include surrounding
58 -- quotes. This is used by the 'Binary' newtype wrapper.
58 -- quotes. This is used by the 'Binary' newtype wrapper.
59 | Many [Action]
59 | Many [Action]
@@ -63,7 +63,7 @@ data Action =
63instance Show Action where
63instance Show Action where
64 show (Plain b) = "Plain " ++ show (toByteString b)
64 show (Plain b) = "Plain " ++ show (toByteString b)
65 show (Escape b) = "Escape " ++ show b
65 show (Escape b) = "Escape " ++ show b
66− show (EscapeBytea b) = "EscapeBytea " ++ show b
66+ show (EscapeByteA b) = "EscapeByteA " ++ show b
67 show (Many b) = "Many " ++ show b
67 show (Many b) = "Many " ++ show b
68
68
69-- | A type that may be used as a single parameter to a SQL query.
69-- | A type that may be used as a single parameter to a SQL query.
@@ -158,11 +158,11 @@ instance ToField Double where
158 {-# INLINE toField #-}
158 {-# INLINE toField #-}
159
159
160instance ToField (Binary SB.ByteString) where
160instance ToField (Binary SB.ByteString) where
161− toField (Binary bs) = EscapeBytea bs
161+ toField (Binary bs) = EscapeByteA bs
162 {-# INLINE toField #-}
162 {-# INLINE toField #-}
163
163
164instance ToField (Binary LB.ByteString) where
164instance ToField (Binary LB.ByteString) where
165− toField (Binary bs) = (EscapeBytea . SB.concat . LB.toChunks) bs
165+ toField (Binary bs) = (EscapeByteA . SB.concat . LB.toChunks) bs
166 {-# INLINE toField #-}
166 {-# INLINE toField #-}
167
167
168instance ToField SB.ByteString where
168instance ToField SB.ByteString where