git.iko.soy/typeable/postgresql-simple
on master help sign in
Remove deprecated BuiltinTypes module
commit6c4d7dd7202819c6570aa336a03975a465c0417c authorLeon P Smith <leon@melding-monads.com> dateThu 26 Feb 2015, 08:50 (12 years ago) parentb2a3081
3 files changed−612
postgresql-simple.cabal−1 src/Database/PostgreSQL/Simple/BuiltinTypes.hs−428 tools/GenBuiltinTypes.hs−183
postgresql-simple.cabal−1
@@ -22,7 +22,6 @@ Library
2222 Exposed-modules:
2323 Database.PostgreSQL.Simple
2424 Database.PostgreSQL.Simple.Arrays
25− Database.PostgreSQL.Simple.BuiltinTypes
2625 Database.PostgreSQL.Simple.Copy
2726 Database.PostgreSQL.Simple.FromField
2827 Database.PostgreSQL.Simple.FromRow
src/Database/PostgreSQL/Simple/BuiltinTypes.hsdeleted−428
@@ -1,428 +0,0 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-}
2−
3−------------------------------------------------------------------------------
4−-- |
5−-- Module: Database.PostgreSQL.Simple.BuiltinTypes
6−-- Copyright: (c) 2011-2012 Leon P Smith
7−-- License: BSD3
8−-- Maintainer: Leon P Smith <leon@melding-monads.com>
9−-- Stability: experimental
10−--
11−------------------------------------------------------------------------------
12−
13−-- Note that this file is generated by tools/GenBuiltinTypes.hs, and should
14−-- not be edited directly
15−
16−module Database.PostgreSQL.Simple.BuiltinTypes
17− {-# DEPRECATED "Use TypeInfo instead" #-}
18− ( BuiltinType (..)
19− , builtin2oid
20− , oid2builtin
21− , builtin2typname
22− , oid2typname
23− ) where
24−
25−import Data.Typeable
26−import Data.ByteString (ByteString)
27−import qualified Database.PostgreSQL.LibPQ as PQ
28−
29−data BuiltinType
30− = Bool
31− | ByteA
32− | Char
33− | Name
34− | Int8
35− | Int2
36− | Int4
37− | RegProc
38− | Text
39− | Oid
40− | Tid
41− | Xid
42− | Cid
43− | Xml
44− | Point
45− | LSeg
46− | Path
47− | Box
48− | Polygon
49− | Line
50− | Cidr
51− | Float4
52− | Float8
53− | AbsTime
54− | RelTime
55− | TInterval
56− | Unknown
57− | Circle
58− | Money
59− | MacAddr
60− | Inet
61− | BpChar
62− | VarChar
63− | Date
64− | Time
65− | Timestamp
66− | TimestampTZ
67− | Interval
68− | TimeTZ
69− | Bit
70− | VarBit
71− | Numeric
72− | RefCursor
73− | Record
74− | Void
75− | UUID
76− | JSON
77− | JSONB
78− deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
79−
80−builtin2oid :: BuiltinType -> PQ.Oid
81−builtin2oid typ = PQ.Oid $ case typ of
82− Bool -> 16
83− ByteA -> 17
84− Char -> 18
85− Name -> 19
86− Int8 -> 20
87− Int2 -> 21
88− Int4 -> 23
89− RegProc -> 24
90− Text -> 25
91− Oid -> 26
92− Tid -> 27
93− Xid -> 28
94− Cid -> 29
95− Xml -> 142
96− Point -> 600
97− LSeg -> 601
98− Path -> 602
99− Box -> 603
100− Polygon -> 604
101− Line -> 628
102− Cidr -> 650
103− Float4 -> 700
104− Float8 -> 701
105− AbsTime -> 702
106− RelTime -> 703
107− TInterval -> 704
108− Unknown -> 705
109− Circle -> 718
110− Money -> 790
111− MacAddr -> 829
112− Inet -> 869
113− BpChar -> 1042
114− VarChar -> 1043
115− Date -> 1082
116− Time -> 1083
117− Timestamp -> 1114
118− TimestampTZ -> 1184
119− Interval -> 1186
120− TimeTZ -> 1266
121− Bit -> 1560
122− VarBit -> 1562
123− Numeric -> 1700
124− RefCursor -> 1790
125− Record -> 2249
126− Void -> 2278
127− UUID -> 2950
128− JSON -> 114
129− JSONB -> 3802
130−
131−oid2builtin :: PQ.Oid -> Maybe BuiltinType
132−oid2builtin (PQ.Oid x) = case x of
133− 16 -> Just Bool
134− 17 -> Just ByteA
135− 18 -> Just Char
136− 19 -> Just Name
137− 20 -> Just Int8
138− 21 -> Just Int2
139− 23 -> Just Int4
140− 24 -> Just RegProc
141− 25 -> Just Text
142− 26 -> Just Oid
143− 27 -> Just Tid
144− 28 -> Just Xid
145− 29 -> Just Cid
146− 142 -> Just Xml
147− 600 -> Just Point
148− 601 -> Just LSeg
149− 602 -> Just Path
150− 603 -> Just Box
151− 604 -> Just Polygon
152− 628 -> Just Line
153− 650 -> Just Cidr
154− 700 -> Just Float4
155− 701 -> Just Float8
156− 702 -> Just AbsTime
157− 703 -> Just RelTime
158− 704 -> Just TInterval
159− 705 -> Just Unknown
160− 718 -> Just Circle
161− 790 -> Just Money
162− 829 -> Just MacAddr
163− 869 -> Just Inet
164− 1042 -> Just BpChar
165− 1043 -> Just VarChar
166− 1082 -> Just Date
167− 1083 -> Just Time
168− 1114 -> Just Timestamp
169− 1184 -> Just TimestampTZ
170− 1186 -> Just Interval
171− 1266 -> Just TimeTZ
172− 1560 -> Just Bit
173− 1562 -> Just VarBit
174− 1700 -> Just Numeric
175− 1790 -> Just RefCursor
176− 2249 -> Just Record
177− 2278 -> Just Void
178− 2950 -> Just UUID
179− 114 -> Just JSON
180− 3802 -> Just JSONB
181− _ -> Nothing
182−
183−builtin2typname :: BuiltinType -> ByteString
184−builtin2typname typ = case typ of
185− Bool -> bool
186− ByteA -> bytea
187− Char -> char
188− Name -> name
189− Int8 -> int8
190− Int2 -> int2
191− Int4 -> int4
192− RegProc -> regproc
193− Text -> text
194− Oid -> oid
195− Tid -> tid
196− Xid -> xid
197− Cid -> cid
198− Xml -> xml
199− Point -> point
200− LSeg -> lseg
201− Path -> path
202− Box -> box
203− Polygon -> polygon
204− Line -> line
205− Cidr -> cidr
206− Float4 -> float4
207− Float8 -> float8
208− AbsTime -> abstime
209− RelTime -> reltime
210− TInterval -> tinterval
211− Unknown -> unknown
212− Circle -> circle
213− Money -> money
214− MacAddr -> macaddr
215− Inet -> inet
216− BpChar -> bpchar
217− VarChar -> varchar
218− Date -> date
219− Time -> time
220− Timestamp -> timestamp
221− TimestampTZ -> timestamptz
222− Interval -> interval
223− TimeTZ -> timetz
224− Bit -> bit
225− VarBit -> varbit
226− Numeric -> numeric
227− RefCursor -> refcursor
228− Record -> record
229− Void -> void
230− UUID -> uuid
231− JSON -> json
232− JSONB -> jsonb
233−
234−oid2typname :: PQ.Oid -> Maybe ByteString
235−oid2typname (PQ.Oid x) = case x of
236− 16 -> Just bool
237− 17 -> Just bytea
238− 18 -> Just char
239− 19 -> Just name
240− 20 -> Just int8
241− 21 -> Just int2
242− 23 -> Just int4
243− 24 -> Just regproc
244− 25 -> Just text
245− 26 -> Just oid
246− 27 -> Just tid
247− 28 -> Just xid
248− 29 -> Just cid
249− 142 -> Just xml
250− 600 -> Just point
251− 601 -> Just lseg
252− 602 -> Just path
253− 603 -> Just box
254− 604 -> Just polygon
255− 628 -> Just line
256− 650 -> Just cidr
257− 700 -> Just float4
258− 701 -> Just float8
259− 702 -> Just abstime
260− 703 -> Just reltime
261− 704 -> Just tinterval
262− 705 -> Just unknown
263− 718 -> Just circle
264− 790 -> Just money
265− 829 -> Just macaddr
266− 869 -> Just inet
267− 1042 -> Just bpchar
268− 1043 -> Just varchar
269− 1082 -> Just date
270− 1083 -> Just time
271− 1114 -> Just timestamp
272− 1184 -> Just timestamptz
273− 1186 -> Just interval
274− 1266 -> Just timetz
275− 1560 -> Just bit
276− 1562 -> Just varbit
277− 1700 -> Just numeric
278− 1790 -> Just refcursor
279− 2249 -> Just record
280− 2278 -> Just void
281− 2950 -> Just uuid
282− 114 -> Just json
283− 3802 -> Just jsonb
284− _ -> Nothing
285−
286−bool :: ByteString
287−bool = "bool"
288−
289−bytea :: ByteString
290−bytea = "bytea"
291−
292−char :: ByteString
293−char = "char"
294−
295−name :: ByteString
296−name = "name"
297−
298−int8 :: ByteString
299−int8 = "int8"
300−
301−int2 :: ByteString
302−int2 = "int2"
303−
304−int4 :: ByteString
305−int4 = "int4"
306−
307−regproc :: ByteString
308−regproc = "regproc"
309−
310−text :: ByteString
311−text = "text"
312−
313−oid :: ByteString
314−oid = "oid"
315−
316−tid :: ByteString
317−tid = "tid"
318−
319−xid :: ByteString
320−xid = "xid"
321−
322−cid :: ByteString
323−cid = "cid"
324−
325−xml :: ByteString
326−xml = "xml"
327−
328−point :: ByteString
329−point = "point"
330−
331−lseg :: ByteString
332−lseg = "lseg"
333−
334−path :: ByteString
335−path = "path"
336−
337−box :: ByteString
338−box = "box"
339−
340−polygon :: ByteString
341−polygon = "polygon"
342−
343−line :: ByteString
344−line = "line"
345−
346−cidr :: ByteString
347−cidr = "cidr"
348−
349−float4 :: ByteString
350−float4 = "float4"
351−
352−float8 :: ByteString
353−float8 = "float8"
354−
355−abstime :: ByteString
356−abstime = "abstime"
357−
358−reltime :: ByteString
359−reltime = "reltime"
360−
361−tinterval :: ByteString
362−tinterval = "tinterval"
363−
364−unknown :: ByteString
365−unknown = "unknown"
366−
367−circle :: ByteString
368−circle = "circle"
369−
370−money :: ByteString
371−money = "money"
372−
373−macaddr :: ByteString
374−macaddr = "macaddr"
375−
376−inet :: ByteString
377−inet = "inet"
378−
379−bpchar :: ByteString
380−bpchar = "bpchar"
381−
382−varchar :: ByteString
383−varchar = "varchar"
384−
385−date :: ByteString
386−date = "date"
387−
388−time :: ByteString
389−time = "time"
390−
391−timestamp :: ByteString
392−timestamp = "timestamp"
393−
394−timestamptz :: ByteString
395−timestamptz = "timestamptz"
396−
397−interval :: ByteString
398−interval = "interval"
399−
400−timetz :: ByteString
401−timetz = "timetz"
402−
403−bit :: ByteString
404−bit = "bit"
405−
406−varbit :: ByteString
407−varbit = "varbit"
408−
409−numeric :: ByteString
410−numeric = "numeric"
411−
412−refcursor :: ByteString
413−refcursor = "refcursor"
414−
415−record :: ByteString
416−record = "record"
417−
418−void :: ByteString
419−void = "void"
420−
421−uuid :: ByteString
422−uuid = "uuid"
423−
424−json :: ByteString
425−json = "json"
426−
427−jsonb :: ByteString
428−jsonb = "jsonb"
tools/GenBuiltinTypes.hsdeleted−183
@@ -1,183 +0,0 @@
1−------------------------------------------------------------------------------
2−-- |
3−-- Module: GenBuiltinTypes
4−-- Copyright: (c) 2011-2012 Leon P Smith
5−-- License: BSD3
6−-- Maintainer: Leon P Smith <leon@melding-monads.com>
7−-- Stability: experimental
8−--
9−-- Queries a PostgreSQL for the Object IDs associated with built-in typenames,
10−-- and generates Haskell boilerplate to handle this mapping. The subset
11−-- of types handled this way is easily modifiable, but note that
12−-- user-defined types do not have stable oids, and can differ between
13−-- databases or dumps/reloads.
14−------------------------------------------------------------------------------
15−
16−{-# LANGUAGE OverloadedStrings, QuasiQuotes, ViewPatterns #-}
17−module GenBuiltinTypes where
18−
19−import Prelude hiding ((++))
20−
21−import StringsQQ
22−import Database.PostgreSQL.Simple
23−import qualified Data.ByteString.Char8 as B
24−import qualified Data.ByteString.Lazy as L
25−import qualified Blaze.ByteString.Builder as Blaze
26−import qualified Blaze.ByteString.Builder.ByteString as Blaze
27−import qualified Blaze.ByteString.Builder.Char8 as Blaze
28−import Data.String
29−import Data.List ( sort, intersperse )
30−import qualified Data.Map as Map
31−
32−import Data.Monoid
33−
34−(++) :: Monoid a => a -> a -> a
35−(++) = mappend
36−infixr 5 ++
37−
38−type Map = Map.Map B.ByteString Int
39−builtins :: [(B.ByteString, B.ByteString)]
40−builtins = [strings|
41−bool
42−bytea ByteA
43−char
44−name
45−int8
46−int2
47−int4
48−regproc RegProc
49−text
50−oid
51−tid
52−xid
53−cid
54−xml
55−point
56−lseg LSeg
57−path
58−box
59−polygon
60−line
61−cidr
62−float4
63−float8
64−abstime AbsTime
65−reltime RelTime
66−tinterval TInterval
67−unknown
68−circle
69−money
70−macaddr MacAddr
71−inet
72−bpchar BpChar
73−varchar VarChar
74−date
75−time
76−timestamp
77−timestamptz TimestampTZ
78−interval
79−timetz TimeTZ
80−bit
81−varbit VarBit
82−numeric
83−refcursor RefCursor
84−record
85−void
86−uuid UUID
87−json JSON
88−jsonb JSONB
89−|]
90−
91−instance IsString Blaze.Builder where
92− fromString = Blaze.fromByteString . fromString
93−
94−main = do
95− conn <- connectPostgreSQL ""
96− xs <- query conn "SELECT typname::text, oid::int\
97− \ FROM pg_type\
98− \ WHERE typname IN ?"
99− (Only (In (sort (map fst builtins))))
100− close conn
101− let oidmap = Map.fromList xs :: Map
102− L.writeFile "../src/Database/PostgreSQL/Simple/BuiltinTypes.hs"
103− (Blaze.toLazyByteString (renderFile oidmap builtins))
104−
105−padCons str = fromString (replicate (len - B.length str) ' ')
106− where
107− len = maximum (map (B.length . snd) builtins)
108−
109−renderOid oidmap x
110− = case Map.lookup x oidmap of
111− Nothing -> error (B.unpack x)
112− Just (show -> n) -> fromString (replicate (4 - length n) ' ')
113− ++ fromString n
114−
115−renderOid' oidmap x
116− = case Map.lookup x oidmap of
117− Nothing -> error (B.unpack x)
118− Just (show -> n) -> fromString n
119− ++ fromString (replicate (4 - length n) ' ')
120−
121−bs = Blaze.fromByteString
122−
123−renderFile :: Map -> [(B.ByteString,B.ByteString)] -> Blaze.Builder
124−renderFile oidmap builtins = ([longstring|
125−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-}
126−
127−------------------------------------------------------------------------------
128−-- |
129−-- Module: Database.PostgreSQL.Simple.BuiltinTypes
130−-- Copyright: (c) 2011-2012 Leon P Smith
131−-- License: BSD3
132−-- Maintainer: Leon P Smith <leon@melding-monads.com>
133−-- Stability: experimental
134−--
135−------------------------------------------------------------------------------
136−
137−-- Note that this file is generated by tools/GenBuiltinTypes.hs, and should
138−-- not be edited directly
139−
140−module Database.PostgreSQL.Simple.BuiltinTypes
141− {-# DEPRECATED "Use TypeInfo instead" #-}
142− ( BuiltinType (..)
143− , builtin2oid
144− , oid2builtin
145− , builtin2typname
146− , oid2typname
147− ) where
148−
149−import Data.Typeable
150−import Data.ByteString (ByteString)
151−import qualified Database.PostgreSQL.LibPQ as PQ
152−
153−data BuiltinType
154− = |] ++ mconcat (intersperse "\n | " (map (Blaze.fromByteString . snd) builtins)) ++ [longstring|
155−
156− deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
157−
158−builtin2oid :: BuiltinType -> PQ.Oid
159−builtin2oid typ = PQ.Oid $ case typ of
160−|] ++ mconcat [mconcat [ " ", bs y, padCons y, " -> "
161− , renderOid oidmap x, "\n" ]
162− | (x,y) <- builtins ] ++ [longstring|
163−
164−oid2builtin :: PQ.Oid -> Maybe BuiltinType
165−oid2builtin (PQ.Oid x) = case x of
166−|] ++ mconcat [mconcat [ " ", renderOid' oidmap x, " -> Just ", bs y, "\n" ]
167− | (x,y) <- builtins ] ++ [longstring|
168− _ -> Nothing
169−
170−builtin2typname :: BuiltinType -> ByteString
171−builtin2typname typ = case typ of
172−|] ++ mconcat [mconcat [ " ", bs y, padCons y, " -> ", bs x, "\n"]
173− | (x,y) <- builtins] ++ [longstring|
174−
175−oid2typname :: PQ.Oid -> Maybe ByteString
176−oid2typname (PQ.Oid x) = case x of
177−|] ++ mconcat [mconcat [ " ", renderOid' oidmap x, " -> Just ", bs x, "\n" ]
178− | (x,y) <- builtins ]
179− ++ " _ -> Nothing\n"
180− ++ mconcat [mconcat [ "\n"
181− , bs x, " :: ByteString\n"
182− , bs x, " = \"", bs x, "\"\n"]
183− | (x,_y) <- builtins ])