git.iko.soy/typeable/postgresql-simple
on master help sign in
Major reorganization
commite4eb4e646f97856f967d575d347e658887ef1f70 authorLeon P Smith <leon@melding-monads.com> dateSun 27 Jan 2013, 20:01 (14 years ago) parentf6de08c
10 files changed+832−723
src/Database/PostgreSQL/Simple.hs+4−195 src/Database/PostgreSQL/Simple.hs-boot+23 src/Database/PostgreSQL/Simple/FromField.hs-boot+10 src/Database/PostgreSQL/Simple/FromRow.hs-boot+7 src/Database/PostgreSQL/Simple/ToField.hs-boot+7 src/Database/PostgreSQL/Simple/ToRow.hs-boot+8 src/Database/PostgreSQL/Simple/Transaction.hs+189 src/Database/PostgreSQL/Simple/TypeInfo.hs+44−526 src/Database/PostgreSQL/Simple/TypeInfo/Static.hs+538 tools/GenTypeInfo.hs+2−2
src/Database/PostgreSQL/Simple.hs+4−195
@@ -123,19 +123,15 @@ import Blaze.ByteString.Builder
123123 ( Builder, fromByteString, toByteString )
124124import Blaze.ByteString.Builder.Char8 (fromChar)
125125import Control.Applicative ((<$>), pure)
126−import Control.Concurrent.MVar
127126import Control.Exception
128− ( Exception, onException, throw, throwIO, finally
129− , try, SomeException, fromException )
127+ ( Exception, throw, throwIO, finally )
130128import Control.Monad (foldM)
131129import Data.ByteString (ByteString)
132130import Data.Int (Int64)
133−import qualified Data.IntMap as IntMap
134131import Data.List (intersperse)
135132import Data.Monoid (mconcat)
136133import Data.Typeable (Typeable)
137−import Database.PostgreSQL.Simple.BuiltinTypes ( oid2typname )
138−import Database.PostgreSQL.Simple.Compat ( mask, (<>) )
134+import Database.PostgreSQL.Simple.Compat ( (<>) )
139135import Database.PostgreSQL.Simple.FromField (ResultError(..))
140136import Database.PostgreSQL.Simple.FromRow (FromRow(..))
141137import Database.PostgreSQL.Simple.Ok
@@ -144,6 +140,8 @@ import Database.PostgreSQL.Simple.ToRow (ToRow(..))
144140import Database.PostgreSQL.Simple.Types
145141 ( Binary(..), In(..), Only(..), Query(..), (:.)(..) )
146142import Database.PostgreSQL.Simple.Internal as Base
143+import Database.PostgreSQL.Simple.Transaction
144+import Database.PostgreSQL.Simple.TypeInfo
147145import qualified Database.PostgreSQL.LibPQ as PQ
148146import qualified Data.ByteString.Char8 as B
149147import qualified Data.Text as T
@@ -589,166 +587,6 @@ ellipsis bs
589587 | B.length bs > 15 = B.take 10 bs `B.append` "[...]"
590588 | otherwise = bs
591589
592−
593−-- | Of the four isolation levels defined by the SQL standard,
594−-- these are the three levels distinguished by PostgreSQL as of version 9.0.
595−-- See <http://www.postgresql.org/docs/9.1/static/transaction-iso.html>
596−-- for more information. Note that prior to PostgreSQL 9.0, 'RepeatableRead'
597−-- was equivalent to 'Serializable'.
598−
599−data IsolationLevel
600− = DefaultIsolationLevel -- ^ the isolation level will be taken from
601− -- PostgreSQL's per-connection
602− -- @default_transaction_isolation@ variable,
603− -- which is initialized according to the
604− -- server's config. The default configuration
605− -- is 'ReadCommitted'.
606− | ReadCommitted
607− | RepeatableRead
608− | Serializable
609− deriving (Show, Eq, Ord, Enum, Bounded)
610−
611−data ReadWriteMode
612− = DefaultReadWriteMode -- ^ the read-write mode will be taken from
613− -- PostgreSQL's per-connection
614− -- @default_transaction_read_only@ variable,
615− -- which is initialized according to the
616− -- server's config. The default configuration
617− -- is 'ReadWrite'.
618− | ReadWrite
619− | ReadOnly
620− deriving (Show, Eq, Ord, Enum, Bounded)
621−
622−data TransactionMode = TransactionMode {
623− isolationLevel :: !IsolationLevel,
624− readWriteMode :: !ReadWriteMode
625− } deriving (Show, Eq)
626−
627−defaultTransactionMode :: TransactionMode
628−defaultTransactionMode = TransactionMode
629− defaultIsolationLevel
630− defaultReadWriteMode
631−
632−defaultIsolationLevel :: IsolationLevel
633−defaultIsolationLevel = DefaultIsolationLevel
634−
635−defaultReadWriteMode :: ReadWriteMode
636−defaultReadWriteMode = DefaultReadWriteMode
637−
638−-- | Execute an action inside a SQL transaction.
639−--
640−-- This function initiates a transaction with a \"@begin
641−-- transaction@\" statement, then executes the supplied action. If
642−-- the action succeeds, the transaction will be completed with
643−-- 'Base.commit' before this function returns.
644−--
645−-- If the action throws /any/ kind of exception (not just a
646−-- PostgreSQL-related exception), the transaction will be rolled back using
647−-- 'rollback', then the exception will be rethrown.
648−withTransaction :: Connection -> IO a -> IO a
649−withTransaction = withTransactionMode defaultTransactionMode
650−
651−-- | Execute an action inside of a 'Serializable' transaction. If a
652−-- serialization failure occurs, roll back the transaction and try again.
653−-- Be warned that this may execute the IO action multiple times.
654−--
655−-- A 'Serializable' transaction creates the illusion that your program has
656−-- exclusive access to the database. This means that, even in a concurrent
657−-- setting, you can perform queries in sequence without having to worry about
658−-- what might happen between one statement and the next.
659−--
660−-- Think of it as STM, but without @retry@.
661−withTransactionSerializable :: Connection -> IO a -> IO a
662−withTransactionSerializable =
663− withTransactionModeRetry
664− TransactionMode
665− { isolationLevel = Serializable
666− , readWriteMode = ReadWrite
667− }
668− retryOnNotSerializable
669− where
670− retryOnNotSerializable exception =
671− case exception of
672− SqlError{..} | sqlState == serialization_failure
673− -> True
674− _ -> False
675− -- http://www.postgresql.org/docs/current/static/errcodes-appendix.html
676− serialization_failure = "40001"
677−
678−-- | Execute an action inside a SQL transaction with a given isolation level.
679−withTransactionLevel :: IsolationLevel -> Connection -> IO a -> IO a
680−withTransactionLevel lvl
681− = withTransactionMode defaultTransactionMode { isolationLevel = lvl }
682−
683−-- | Execute an action inside a SQL transaction with a given transaction mode.
684−withTransactionMode :: TransactionMode -> Connection -> IO a -> IO a
685−withTransactionMode mode conn act =
686− mask $ \restore -> do
687− beginMode mode conn
688− r <- restore act `onException` rollback conn
689− commit conn
690− return r
691−
692−-- | Like 'withTransactionMode', but also takes a custom callback to
693−-- determine if a transaction should be retried if an 'SqlError' occurs.
694−-- If the callback returns True, then the transaction will be retried.
695−-- If the callback returns False, or an exception other than an 'SqlError'
696−-- occurs then the transaction will be rolled back and the exception rethrown.
697−--
698−-- This is used to implement 'withTransactionSerializable'.
699−withTransactionModeRetry :: TransactionMode -> (SqlError -> Bool) -> Connection -> IO a -> IO a
700−withTransactionModeRetry mode shouldRetry conn act =
701− mask $ \restore ->
702− retryLoop $ try $ do
703− a <- restore act
704− commit conn
705− return a
706− where
707− retryLoop :: IO (Either SomeException a) -> IO a
708− retryLoop act' = do
709− beginMode mode conn
710− r <- act'
711− case r of
712− Left e -> do
713− rollback conn
714− case fmap shouldRetry (fromException e) of
715− Just True -> retryLoop act'
716− _ -> throwIO e
717− Right a ->
718− return a
719−
720−-- | Rollback a transaction.
721−rollback :: Connection -> IO ()
722−rollback conn = execute_ conn "ABORT" >> return ()
723−
724−-- | Commit a transaction.
725−commit :: Connection -> IO ()
726−commit conn = execute_ conn "COMMIT" >> return ()
727−
728−-- | Begin a transaction.
729−begin :: Connection -> IO ()
730−begin = beginMode defaultTransactionMode
731−
732−-- | Begin a transaction with a given isolation level
733−beginLevel :: IsolationLevel -> Connection -> IO ()
734−beginLevel lvl = beginMode defaultTransactionMode { isolationLevel = lvl }
735−
736−-- | Begin a transaction with a given transaction mode
737−beginMode :: TransactionMode -> Connection -> IO ()
738−beginMode mode conn = do
739− _ <- execute_ conn $! Query (B.concat ["BEGIN", isolevel, readmode])
740− return ()
741− where
742− isolevel = case isolationLevel mode of
743− DefaultIsolationLevel -> ""
744− ReadCommitted -> " ISOLATION LEVEL READ COMMITTED"
745− RepeatableRead -> " ISOLATION LEVEL REPEATABLE READ"
746− Serializable -> " ISOLATION LEVEL SERIALIZABLE"
747− readmode = case readWriteMode mode of
748− DefaultReadWriteMode -> ""
749− ReadWrite -> " READ WRITE"
750− ReadOnly -> " READ ONLY"
751−
752590fmtError :: String -> Query -> [Action] -> a
753591fmtError msg q xs = throw FormatError {
754592 fmtMessage = msg
@@ -1022,32 +860,3 @@ fmtError msg q xs = throw FormatError {
1022860-- UTF-8. If you use some other encoding, decoding may fail or give
1023861-- wrong results. In such cases, write a @newtype@ wrapper and a
1024862-- custom 'Result' instance to handle your encoding.
1025−
1026−getTypeInfo :: Connection -> PQ.Oid -> IO TypeInfo
1027−getTypeInfo conn@Connection{..} oid =
1028− case oid2typname oid of
1029− Just name -> return $! TypeInfo { typ = NamedOid oid name
1030− , typelem = Nothing
1031− }
1032− Nothing -> modifyMVar connectionObjects $ \oidmap -> do
1033− case IntMap.lookup (oid2int oid) oidmap of
1034− Just typeinfo -> return (oidmap, typeinfo)
1035− Nothing -> do
1036− names <- query conn "SELECT p.oid, p.typname, c.oid, c.typname\
1037− \ FROM pg_type AS p LEFT OUTER JOIN pg_type AS c\
1038− \ ON c.oid = p.typelem\
1039− \ WHERE p.oid = ?"
1040− (Only oid)
1041− typinf <- case names of
1042− [] -> return $ throw (fatalError "invalid type oid")
1043− [(pOid, pTypName, mbCOid, mbCTypName)] ->
1044− return $! TypeInfo { typ = NamedOid pOid pTypName
1045− , typelem = do
1046− cOid <- mbCOid
1047− cTypName <- mbCTypName
1048− return $ NamedOid cOid cTypName
1049− }
1050− _ -> fail "typename query returned more than one result"
1051− -- oid is a primary key, so the query should
1052− -- never return more than one result
1053− return (IntMap.insert (oid2int oid) typinf oidmap, typinf)
src/Database/PostgreSQL/Simple.hs-bootnew file+23
@@ -0,0 +1,23 @@
1+module Database.PostgreSQL.Simple
2+ ( Connection
3+ , Query
4+ , query
5+ , query_
6+ , execute
7+ , execute_
8+ , executeMany
9+ ) where
10+
11+import Data.Int(Int64)
12+import Database.PostgreSQL.Simple.Internal
13+import Database.PostgreSQL.Simple.Types
14+import {-# SOURCE #-} Database.PostgreSQL.Simple.FromRow
15+import {-# SOURCE #-} Database.PostgreSQL.Simple.ToRow
16+
17+query :: (ToRow q, FromRow r) => Connection -> Query -> q -> IO [r]
18+
19+query_ :: FromRow r => Connection -> Query -> IO [r]
20+
21+execute :: ToRow q => Connection -> Query -> q -> IO Int64
22+
23+executeMany :: ToRow q => Connection -> Query -> [q] -> IO Int64
src/Database/PostgreSQL/Simple/FromField.hs-bootnew file+10
@@ -0,0 +1,10 @@
1+module Database.PostgreSQL.Simple.FromField where
2+
3+import Data.ByteString(ByteString)
4+import Database.PostgreSQL.Simple.Types
5+
6+class FromField a
7+
8+instance FromField Oid
9+instance FromField ByteString
10+instance FromField a => FromField (Maybe a)
src/Database/PostgreSQL/Simple/FromRow.hs-bootnew file+7
@@ -0,0 +1,7 @@
1+module Database.PostgreSQL.Simple.FromRow where
2+
3+import {-# SOURCE #-} Database.PostgreSQL.Simple.FromField
4+
5+class FromRow a
6+
7+instance (FromField a, FromField b, FromField c, FromField d) => FromRow (a,b,c,d)
src/Database/PostgreSQL/Simple/ToField.hs-bootnew file+7
@@ -0,0 +1,7 @@
1+module Database.PostgreSQL.Simple.ToField where
2+
3+import Database.PostgreSQL.Simple.Types
4+
5+class ToField a
6+
7+instance ToField Oid
src/Database/PostgreSQL/Simple/ToRow.hs-bootnew file+8
@@ -0,0 +1,8 @@
1+module Database.PostgreSQL.Simple.ToRow where
2+
3+import Database.PostgreSQL.Simple.Types
4+import {-# SOURCE #-} Database.PostgreSQL.Simple.ToField
5+
6+class ToRow a
7+
8+instance ToField a => ToRow (Only a)
src/Database/PostgreSQL/Simple/Transaction.hsnew file+189
@@ -0,0 +1,189 @@
1+{-# LANGUAGE RecordWildCards #-}
2+
3+module Database.PostgreSQL.Simple.Transaction
4+ (
5+ -- * Transaction handling
6+ withTransaction
7+ , withTransactionLevel
8+ , withTransactionMode
9+ , withTransactionModeRetry
10+ , withTransactionSerializable
11+ , TransactionMode(..)
12+ , IsolationLevel(..)
13+ , ReadWriteMode(..)
14+ , defaultTransactionMode
15+ , defaultIsolationLevel
16+ , defaultReadWriteMode
17+-- , Base.autocommit
18+ , begin
19+ , beginLevel
20+ , beginMode
21+ , commit
22+ , rollback
23+ ) where
24+
25+import Control.Exception hiding (mask)
26+import qualified Data.ByteString as B
27+import Database.PostgreSQL.Simple.Internal
28+import Database.PostgreSQL.Simple.Types
29+import Database.PostgreSQL.Simple.Compat(mask)
30+
31+
32+-- | Of the four isolation levels defined by the SQL standard,
33+-- these are the three levels distinguished by PostgreSQL as of version 9.0.
34+-- See <http://www.postgresql.org/docs/9.1/static/transaction-iso.html>
35+-- for more information. Note that prior to PostgreSQL 9.0, 'RepeatableRead'
36+-- was equivalent to 'Serializable'.
37+
38+data IsolationLevel
39+ = DefaultIsolationLevel -- ^ the isolation level will be taken from
40+ -- PostgreSQL's per-connection
41+ -- @default_transaction_isolation@ variable,
42+ -- which is initialized according to the
43+ -- server's config. The default configuration
44+ -- is 'ReadCommitted'.
45+ | ReadCommitted
46+ | RepeatableRead
47+ | Serializable
48+ deriving (Show, Eq, Ord, Enum, Bounded)
49+
50+data ReadWriteMode
51+ = DefaultReadWriteMode -- ^ the read-write mode will be taken from
52+ -- PostgreSQL's per-connection
53+ -- @default_transaction_read_only@ variable,
54+ -- which is initialized according to the
55+ -- server's config. The default configuration
56+ -- is 'ReadWrite'.
57+ | ReadWrite
58+ | ReadOnly
59+ deriving (Show, Eq, Ord, Enum, Bounded)
60+
61+data TransactionMode = TransactionMode {
62+ isolationLevel :: !IsolationLevel,
63+ readWriteMode :: !ReadWriteMode
64+ } deriving (Show, Eq)
65+
66+defaultTransactionMode :: TransactionMode
67+defaultTransactionMode = TransactionMode
68+ defaultIsolationLevel
69+ defaultReadWriteMode
70+
71+defaultIsolationLevel :: IsolationLevel
72+defaultIsolationLevel = DefaultIsolationLevel
73+
74+defaultReadWriteMode :: ReadWriteMode
75+defaultReadWriteMode = DefaultReadWriteMode
76+
77+-- | Execute an action inside a SQL transaction.
78+--
79+-- This function initiates a transaction with a \"@begin
80+-- transaction@\" statement, then executes the supplied action. If
81+-- the action succeeds, the transaction will be completed with
82+-- 'Base.commit' before this function returns.
83+--
84+-- If the action throws /any/ kind of exception (not just a
85+-- PostgreSQL-related exception), the transaction will be rolled back using
86+-- 'rollback', then the exception will be rethrown.
87+withTransaction :: Connection -> IO a -> IO a
88+withTransaction = withTransactionMode defaultTransactionMode
89+
90+-- | Execute an action inside of a 'Serializable' transaction. If a
91+-- serialization failure occurs, roll back the transaction and try again.
92+-- Be warned that this may execute the IO action multiple times.
93+--
94+-- A 'Serializable' transaction creates the illusion that your program has
95+-- exclusive access to the database. This means that, even in a concurrent
96+-- setting, you can perform queries in sequence without having to worry about
97+-- what might happen between one statement and the next.
98+--
99+-- Think of it as STM, but without @retry@.
100+withTransactionSerializable :: Connection -> IO a -> IO a
101+withTransactionSerializable =
102+ withTransactionModeRetry
103+ TransactionMode
104+ { isolationLevel = Serializable
105+ , readWriteMode = ReadWrite
106+ }
107+ retryOnNotSerializable
108+ where
109+ retryOnNotSerializable exception =
110+ case exception of
111+ SqlError{..} | sqlState == serialization_failure
112+ -> True
113+ _ -> False
114+ -- http://www.postgresql.org/docs/current/static/errcodes-appendix.html
115+ serialization_failure = "40001"
116+
117+-- | Execute an action inside a SQL transaction with a given isolation level.
118+withTransactionLevel :: IsolationLevel -> Connection -> IO a -> IO a
119+withTransactionLevel lvl
120+ = withTransactionMode defaultTransactionMode { isolationLevel = lvl }
121+
122+-- | Execute an action inside a SQL transaction with a given transaction mode.
123+withTransactionMode :: TransactionMode -> Connection -> IO a -> IO a
124+withTransactionMode mode conn act =
125+ mask $ \restore -> do
126+ beginMode mode conn
127+ r <- restore act `onException` rollback conn
128+ commit conn
129+ return r
130+
131+-- | Like 'withTransactionMode', but also takes a custom callback to
132+-- determine if a transaction should be retried if an 'SqlError' occurs.
133+-- If the callback returns True, then the transaction will be retried.
134+-- If the callback returns False, or an exception other than an 'SqlError'
135+-- occurs then the transaction will be rolled back and the exception rethrown.
136+--
137+-- This is used to implement 'withTransactionSerializable'.
138+withTransactionModeRetry :: TransactionMode -> (SqlError -> Bool) -> Connection -> IO a -> IO a
139+withTransactionModeRetry mode shouldRetry conn act =
140+ mask $ \restore ->
141+ retryLoop $ try $ do
142+ a <- restore act
143+ commit conn
144+ return a
145+ where
146+ retryLoop :: IO (Either SomeException a) -> IO a
147+ retryLoop act' = do
148+ beginMode mode conn
149+ r <- act'
150+ case r of
151+ Left e -> do
152+ rollback conn
153+ case fmap shouldRetry (fromException e) of
154+ Just True -> retryLoop act'
155+ _ -> throwIO e
156+ Right a ->
157+ return a
158+
159+-- | Rollback a transaction.
160+rollback :: Connection -> IO ()
161+rollback conn = execute_ conn "ABORT" >> return ()
162+
163+-- | Commit a transaction.
164+commit :: Connection -> IO ()
165+commit conn = execute_ conn "COMMIT" >> return ()
166+
167+-- | Begin a transaction.
168+begin :: Connection -> IO ()
169+begin = beginMode defaultTransactionMode
170+
171+-- | Begin a transaction with a given isolation level
172+beginLevel :: IsolationLevel -> Connection -> IO ()
173+beginLevel lvl = beginMode defaultTransactionMode { isolationLevel = lvl }
174+
175+-- | Begin a transaction with a given transaction mode
176+beginMode :: TransactionMode -> Connection -> IO ()
177+beginMode mode conn = do
178+ _ <- execute_ conn $! Query (B.concat ["BEGIN", isolevel, readmode])
179+ return ()
180+ where
181+ isolevel = case isolationLevel mode of
182+ DefaultIsolationLevel -> ""
183+ ReadCommitted -> " ISOLATION LEVEL READ COMMITTED"
184+ RepeatableRead -> " ISOLATION LEVEL REPEATABLE READ"
185+ Serializable -> " ISOLATION LEVEL SERIALIZABLE"
186+ readmode = case readWriteMode mode of
187+ DefaultReadWriteMode -> ""
188+ ReadWrite -> " READ WRITE"
189+ ReadOnly -> " READ ONLY"
src/Database/PostgreSQL/Simple/TypeInfo.hs+44−526
@@ -1,538 +1,56 @@
1+{-# LANGUAGE RecordWildCards #-}
2+
13------------------------------------------------------------------------------
24-- |
35-- Module: Database.PostgreSQL.Simple.TypeInfo
4−-- Copyright: (c) 2011-2012 Leon P Smith
6+-- Copyright: (c) 2013 Leon P Smith
57-- License: BSD3
68-- Maintainer: Leon P Smith <leon@melding-monads.com>
79-- Stability: experimental
810--
911------------------------------------------------------------------------------
1012
11−-- Note that this file is generated by tools/GenTypeInfo.hs, and should
12−-- not be edited directly
13−
1413module Database.PostgreSQL.Simple.TypeInfo
15− ( TypeInfo(..)
16− , staticTypeInfo
17− , bool
18− , bytea
19− , char
20− , name
21− , int8
22− , int2
23− , int4
24− , regproc
25− , text
26− , oid
27− , tid
28− , xid
29− , cid
30− , xml
31− , point
32− , lseg
33− , path
34− , box
35− , polygon
36− , line
37− , cidr
38− , float4
39− , float8
40− , abstime
41− , reltime
42− , tinterval
43− , unknown
44− , circle
45− , money
46− , macaddr
47− , inet
48− , bpchar
49− , varchar
50− , date
51− , time
52− , timestamp
53− , timestamptz
54− , interval
55− , timetz
56− , bit
57− , varbit
58− , numeric
59− , refcursor
60− , record
61− , void
62− , uuid
14+ ( getTypeInfo
15+ , NamedOid(..)
16+ , TypeInfo(..)
6317 ) where
6418
65−import Data.ByteString (ByteString)
66−import Database.PostgreSQL.LibPQ (Oid(..))
67−
68−data TypeInfo = TypeInfo
69− { typoid :: {-# UNPACK #-} !Oid
70− , typcategory :: {-# UNPACK #-} !Char
71− , typdelim :: {-# UNPACK #-} !Char
72− , typelem :: !(Maybe TypeInfo)
73− , typname :: !ByteString
74− }
75−
76−staticTypeInfo :: Oid -> Maybe TypeInfo
77−staticTypeInfo (Oid x) = case x of
78− 16 -> Just bool
79− 17 -> Just bytea
80− 18 -> Just char
81− 19 -> Just name
82− 20 -> Just int8
83− 21 -> Just int2
84− 23 -> Just int4
85− 24 -> Just regproc
86− 25 -> Just text
87− 26 -> Just oid
88− 27 -> Just tid
89− 28 -> Just xid
90− 29 -> Just cid
91− 142 -> Just xml
92− 600 -> Just point
93− 601 -> Just lseg
94− 602 -> Just path
95− 603 -> Just box
96− 604 -> Just polygon
97− 628 -> Just line
98− 650 -> Just cidr
99− 700 -> Just float4
100− 701 -> Just float8
101− 702 -> Just abstime
102− 703 -> Just reltime
103− 704 -> Just tinterval
104− 705 -> Just unknown
105− 718 -> Just circle
106− 790 -> Just money
107− 829 -> Just macaddr
108− 869 -> Just inet
109− 1042 -> Just bpchar
110− 1043 -> Just varchar
111− 1082 -> Just date
112− 1083 -> Just time
113− 1114 -> Just timestamp
114− 1184 -> Just timestamptz
115− 1186 -> Just interval
116− 1266 -> Just timetz
117− 1560 -> Just bit
118− 1562 -> Just varbit
119− 1700 -> Just numeric
120− 1790 -> Just refcursor
121− 2249 -> Just record
122− 2278 -> Just void
123− 2950 -> Just uuid
124− _ -> Nothing
125−
126−bool :: TypeInfo
127−bool = TypeInfo {
128− typoid = Oid 16,
129− typcategory = 'B',
130− typdelim = ',',
131− typelem = Nothing,
132− typname = "bool"
133− }
134−
135−bytea :: TypeInfo
136−bytea = TypeInfo {
137− typoid = Oid 17,
138− typcategory = 'U',
139− typdelim = ',',
140− typelem = Nothing,
141− typname = "bytea"
142− }
143−
144−char :: TypeInfo
145−char = TypeInfo {
146− typoid = Oid 18,
147− typcategory = 'S',
148− typdelim = ',',
149− typelem = Nothing,
150− typname = "char"
151− }
152−
153−name :: TypeInfo
154−name = TypeInfo {
155− typoid = Oid 19,
156− typcategory = 'S',
157− typdelim = ',',
158− typelem = Just char,
159− typname = "name"
160− }
161−
162−int8 :: TypeInfo
163−int8 = TypeInfo {
164− typoid = Oid 20,
165− typcategory = 'N',
166− typdelim = ',',
167− typelem = Nothing,
168− typname = "int8"
169− }
170−
171−int2 :: TypeInfo
172−int2 = TypeInfo {
173− typoid = Oid 21,
174− typcategory = 'N',
175− typdelim = ',',
176− typelem = Nothing,
177− typname = "int2"
178− }
179−
180−int4 :: TypeInfo
181−int4 = TypeInfo {
182− typoid = Oid 23,
183− typcategory = 'N',
184− typdelim = ',',
185− typelem = Nothing,
186− typname = "int4"
187− }
188−
189−regproc :: TypeInfo
190−regproc = TypeInfo {
191− typoid = Oid 24,
192− typcategory = 'N',
193− typdelim = ',',
194− typelem = Nothing,
195− typname = "regproc"
196− }
197−
198−text :: TypeInfo
199−text = TypeInfo {
200− typoid = Oid 25,
201− typcategory = 'S',
202− typdelim = ',',
203− typelem = Nothing,
204− typname = "text"
205− }
206−
207−oid :: TypeInfo
208−oid = TypeInfo {
209− typoid = Oid 26,
210− typcategory = 'N',
211− typdelim = ',',
212− typelem = Nothing,
213− typname = "oid"
214− }
215−
216−tid :: TypeInfo
217−tid = TypeInfo {
218− typoid = Oid 27,
219− typcategory = 'U',
220− typdelim = ',',
221− typelem = Nothing,
222− typname = "tid"
223− }
224−
225−xid :: TypeInfo
226−xid = TypeInfo {
227− typoid = Oid 28,
228− typcategory = 'U',
229− typdelim = ',',
230− typelem = Nothing,
231− typname = "xid"
232− }
233−
234−cid :: TypeInfo
235−cid = TypeInfo {
236− typoid = Oid 29,
237− typcategory = 'U',
238− typdelim = ',',
239− typelem = Nothing,
240− typname = "cid"
241− }
242−
243−xml :: TypeInfo
244−xml = TypeInfo {
245− typoid = Oid 142,
246− typcategory = 'U',
247− typdelim = ',',
248− typelem = Nothing,
249− typname = "xml"
250− }
251−
252−point :: TypeInfo
253−point = TypeInfo {
254− typoid = Oid 600,
255− typcategory = 'G',
256− typdelim = ',',
257− typelem = Just float8,
258− typname = "point"
259− }
260−
261−lseg :: TypeInfo
262−lseg = TypeInfo {
263− typoid = Oid 601,
264− typcategory = 'G',
265− typdelim = ',',
266− typelem = Just point,
267− typname = "lseg"
268− }
269−
270−path :: TypeInfo
271−path = TypeInfo {
272− typoid = Oid 602,
273− typcategory = 'G',
274− typdelim = ',',
275− typelem = Nothing,
276− typname = "path"
277− }
278−
279−box :: TypeInfo
280−box = TypeInfo {
281− typoid = Oid 603,
282− typcategory = 'G',
283− typdelim = ';',
284− typelem = Just point,
285− typname = "box"
286− }
287−
288−polygon :: TypeInfo
289−polygon = TypeInfo {
290− typoid = Oid 604,
291− typcategory = 'G',
292− typdelim = ',',
293− typelem = Nothing,
294− typname = "polygon"
295− }
296−
297−line :: TypeInfo
298−line = TypeInfo {
299− typoid = Oid 628,
300− typcategory = 'G',
301− typdelim = ',',
302− typelem = Just float8,
303− typname = "line"
304− }
305−
306−cidr :: TypeInfo
307−cidr = TypeInfo {
308− typoid = Oid 650,
309− typcategory = 'I',
310− typdelim = ',',
311− typelem = Nothing,
312− typname = "cidr"
313− }
314−
315−float4 :: TypeInfo
316−float4 = TypeInfo {
317− typoid = Oid 700,
318− typcategory = 'N',
319− typdelim = ',',
320− typelem = Nothing,
321− typname = "float4"
322− }
323−
324−float8 :: TypeInfo
325−float8 = TypeInfo {
326− typoid = Oid 701,
327− typcategory = 'N',
328− typdelim = ',',
329− typelem = Nothing,
330− typname = "float8"
331− }
332−
333−abstime :: TypeInfo
334−abstime = TypeInfo {
335− typoid = Oid 702,
336− typcategory = 'D',
337− typdelim = ',',
338− typelem = Nothing,
339− typname = "abstime"
340− }
341−
342−reltime :: TypeInfo
343−reltime = TypeInfo {
344− typoid = Oid 703,
345− typcategory = 'T',
346− typdelim = ',',
347− typelem = Nothing,
348− typname = "reltime"
349− }
350−
351−tinterval :: TypeInfo
352−tinterval = TypeInfo {
353− typoid = Oid 704,
354− typcategory = 'T',
355− typdelim = ',',
356− typelem = Nothing,
357− typname = "tinterval"
358− }
359−
360−unknown :: TypeInfo
361−unknown = TypeInfo {
362− typoid = Oid 705,
363− typcategory = 'X',
364− typdelim = ',',
365− typelem = Nothing,
366− typname = "unknown"
367− }
368−
369−circle :: TypeInfo
370−circle = TypeInfo {
371− typoid = Oid 718,
372− typcategory = 'G',
373− typdelim = ',',
374− typelem = Nothing,
375− typname = "circle"
376− }
377−
378−money :: TypeInfo
379−money = TypeInfo {
380− typoid = Oid 790,
381− typcategory = 'N',
382− typdelim = ',',
383− typelem = Nothing,
384− typname = "money"
385− }
386−
387−macaddr :: TypeInfo
388−macaddr = TypeInfo {
389− typoid = Oid 829,
390− typcategory = 'U',
391− typdelim = ',',
392− typelem = Nothing,
393− typname = "macaddr"
394− }
395−
396−inet :: TypeInfo
397−inet = TypeInfo {
398− typoid = Oid 869,
399− typcategory = 'I',
400− typdelim = ',',
401− typelem = Nothing,
402− typname = "inet"
403− }
404−
405−bpchar :: TypeInfo
406−bpchar = TypeInfo {
407− typoid = Oid 1042,
408− typcategory = 'S',
409− typdelim = ',',
410− typelem = Nothing,
411− typname = "bpchar"
412− }
413−
414−varchar :: TypeInfo
415−varchar = TypeInfo {
416− typoid = Oid 1043,
417− typcategory = 'S',
418− typdelim = ',',
419− typelem = Nothing,
420− typname = "varchar"
421− }
422−
423−date :: TypeInfo
424−date = TypeInfo {
425− typoid = Oid 1082,
426− typcategory = 'D',
427− typdelim = ',',
428− typelem = Nothing,
429− typname = "date"
430− }
431−
432−time :: TypeInfo
433−time = TypeInfo {
434− typoid = Oid 1083,
435− typcategory = 'D',
436− typdelim = ',',
437− typelem = Nothing,
438− typname = "time"
439− }
440−
441−timestamp :: TypeInfo
442−timestamp = TypeInfo {
443− typoid = Oid 1114,
444− typcategory = 'D',
445− typdelim = ',',
446− typelem = Nothing,
447− typname = "timestamp"
448− }
449−
450−timestamptz :: TypeInfo
451−timestamptz = TypeInfo {
452− typoid = Oid 1184,
453− typcategory = 'D',
454− typdelim = ',',
455− typelem = Nothing,
456− typname = "timestamptz"
457− }
458−
459−interval :: TypeInfo
460−interval = TypeInfo {
461− typoid = Oid 1186,
462− typcategory = 'T',
463− typdelim = ',',
464− typelem = Nothing,
465− typname = "interval"
466− }
467−
468−timetz :: TypeInfo
469−timetz = TypeInfo {
470− typoid = Oid 1266,
471− typcategory = 'D',
472− typdelim = ',',
473− typelem = Nothing,
474− typname = "timetz"
475− }
476−
477−bit :: TypeInfo
478−bit = TypeInfo {
479− typoid = Oid 1560,
480− typcategory = 'V',
481− typdelim = ',',
482− typelem = Nothing,
483− typname = "bit"
484− }
485−
486−varbit :: TypeInfo
487−varbit = TypeInfo {
488− typoid = Oid 1562,
489− typcategory = 'V',
490− typdelim = ',',
491− typelem = Nothing,
492− typname = "varbit"
493− }
494−
495−numeric :: TypeInfo
496−numeric = TypeInfo {
497− typoid = Oid 1700,
498− typcategory = 'N',
499− typdelim = ',',
500− typelem = Nothing,
501− typname = "numeric"
502− }
503−
504−refcursor :: TypeInfo
505−refcursor = TypeInfo {
506− typoid = Oid 1790,
507− typcategory = 'U',
508− typdelim = ',',
509− typelem = Nothing,
510− typname = "refcursor"
511− }
512−
513−record :: TypeInfo
514−record = TypeInfo {
515− typoid = Oid 2249,
516− typcategory = 'P',
517− typdelim = ',',
518− typelem = Nothing,
519− typname = "record"
520− }
521−
522−void :: TypeInfo
523−void = TypeInfo {
524− typoid = Oid 2278,
525− typcategory = 'P',
526− typdelim = ',',
527− typelem = Nothing,
528− typname = "void"
529− }
530−
531−uuid :: TypeInfo
532−uuid = TypeInfo {
533− typoid = Oid 2950,
534− typcategory = 'U',
535− typdelim = ',',
536− typelem = Nothing,
537− typname = "uuid"
538− }
19+import qualified Data.IntMap as IntMap
20+import Control.Concurrent.MVar
21+import Control.Exception (throw)
22+
23+import qualified Database.PostgreSQL.LibPQ as PQ
24+import {-# SOURCE #-} Database.PostgreSQL.Simple
25+import Database.PostgreSQL.Simple.Internal
26+import Database.PostgreSQL.Simple.Types
27+import Database.PostgreSQL.Simple.BuiltinTypes
28+
29+getTypeInfo :: Connection -> PQ.Oid -> IO TypeInfo
30+getTypeInfo conn@Connection{..} oid =
31+ case oid2typname oid of
32+ Just name -> return $! TypeInfo { typ = NamedOid oid name
33+ , typelem = Nothing
34+ }
35+ Nothing -> modifyMVar connectionObjects $ \oidmap -> do
36+ case IntMap.lookup (oid2int oid) oidmap of
37+ Just typeinfo -> return (oidmap, typeinfo)
38+ Nothing -> do
39+ names <- query conn "SELECT p.oid, p.typname, c.oid, c.typname\
40+ \ FROM pg_type AS p LEFT OUTER JOIN pg_type AS c\
41+ \ ON c.oid = p.typelem\
42+ \ WHERE p.oid = ?"
43+ (Only oid)
44+ typinf <- case names of
45+ [] -> return $ throw (fatalError "invalid type oid")
46+ [(pOid, pTypName, mbCOid, mbCTypName)] ->
47+ return $! TypeInfo { typ = NamedOid pOid pTypName
48+ , typelem = do
49+ cOid <- mbCOid
50+ cTypName <- mbCTypName
51+ return $ NamedOid cOid cTypName
52+ }
53+ _ -> fail "typename query returned more than one result"
54+ -- oid is a primary key, so the query should
55+ -- never return more than one result
56+ return (IntMap.insert (oid2int oid) typinf oidmap, typinf)
src/Database/PostgreSQL/Simple/TypeInfo/Static.hsnew file+538
@@ -0,0 +1,538 @@
1+------------------------------------------------------------------------------
2+-- |
3+-- Module: Database.PostgreSQL.Simple.TypeInfo
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+------------------------------------------------------------------------------
10+
11+-- Note that this file is generated by tools/GenTypeInfo.hs, and should
12+-- not be edited directly
13+
14+module Database.PostgreSQL.Simple.TypeInfo.Static
15+ ( TypeInfo(..)
16+ , staticTypeInfo
17+ , bool
18+ , bytea
19+ , char
20+ , name
21+ , int8
22+ , int2
23+ , int4
24+ , regproc
25+ , text
26+ , oid
27+ , tid
28+ , xid
29+ , cid
30+ , xml
31+ , point
32+ , lseg
33+ , path
34+ , box
35+ , polygon
36+ , line
37+ , cidr
38+ , float4
39+ , float8
40+ , abstime
41+ , reltime
42+ , tinterval
43+ , unknown
44+ , circle
45+ , money
46+ , macaddr
47+ , inet
48+ , bpchar
49+ , varchar
50+ , date
51+ , time
52+ , timestamp
53+ , timestamptz
54+ , interval
55+ , timetz
56+ , bit
57+ , varbit
58+ , numeric
59+ , refcursor
60+ , record
61+ , void
62+ , uuid
63+ ) where
64+
65+import Data.ByteString (ByteString)
66+import Database.PostgreSQL.LibPQ (Oid(..))
67+
68+data TypeInfo = TypeInfo
69+ { typoid :: {-# UNPACK #-} !Oid
70+ , typcategory :: {-# UNPACK #-} !Char
71+ , typdelim :: {-# UNPACK #-} !Char
72+ , typelem :: !(Maybe TypeInfo)
73+ , typname :: !ByteString
74+ }
75+
76+staticTypeInfo :: Oid -> Maybe TypeInfo
77+staticTypeInfo (Oid x) = case x of
78+ 16 -> Just bool
79+ 17 -> Just bytea
80+ 18 -> Just char
81+ 19 -> Just name
82+ 20 -> Just int8
83+ 21 -> Just int2
84+ 23 -> Just int4
85+ 24 -> Just regproc
86+ 25 -> Just text
87+ 26 -> Just oid
88+ 27 -> Just tid
89+ 28 -> Just xid
90+ 29 -> Just cid
91+ 142 -> Just xml
92+ 600 -> Just point
93+ 601 -> Just lseg
94+ 602 -> Just path
95+ 603 -> Just box
96+ 604 -> Just polygon
97+ 628 -> Just line
98+ 650 -> Just cidr
99+ 700 -> Just float4
100+ 701 -> Just float8
101+ 702 -> Just abstime
102+ 703 -> Just reltime
103+ 704 -> Just tinterval
104+ 705 -> Just unknown
105+ 718 -> Just circle
106+ 790 -> Just money
107+ 829 -> Just macaddr
108+ 869 -> Just inet
109+ 1042 -> Just bpchar
110+ 1043 -> Just varchar
111+ 1082 -> Just date
112+ 1083 -> Just time
113+ 1114 -> Just timestamp
114+ 1184 -> Just timestamptz
115+ 1186 -> Just interval
116+ 1266 -> Just timetz
117+ 1560 -> Just bit
118+ 1562 -> Just varbit
119+ 1700 -> Just numeric
120+ 1790 -> Just refcursor
121+ 2249 -> Just record
122+ 2278 -> Just void
123+ 2950 -> Just uuid
124+ _ -> Nothing
125+
126+bool :: TypeInfo
127+bool = TypeInfo {
128+ typoid = Oid 16,
129+ typcategory = 'B',
130+ typdelim = ',',
131+ typelem = Nothing,
132+ typname = "bool"
133+ }
134+
135+bytea :: TypeInfo
136+bytea = TypeInfo {
137+ typoid = Oid 17,
138+ typcategory = 'U',
139+ typdelim = ',',
140+ typelem = Nothing,
141+ typname = "bytea"
142+ }
143+
144+char :: TypeInfo
145+char = TypeInfo {
146+ typoid = Oid 18,
147+ typcategory = 'S',
148+ typdelim = ',',
149+ typelem = Nothing,
150+ typname = "char"
151+ }
152+
153+name :: TypeInfo
154+name = TypeInfo {
155+ typoid = Oid 19,
156+ typcategory = 'S',
157+ typdelim = ',',
158+ typelem = Just char,
159+ typname = "name"
160+ }
161+
162+int8 :: TypeInfo
163+int8 = TypeInfo {
164+ typoid = Oid 20,
165+ typcategory = 'N',
166+ typdelim = ',',
167+ typelem = Nothing,
168+ typname = "int8"
169+ }
170+
171+int2 :: TypeInfo
172+int2 = TypeInfo {
173+ typoid = Oid 21,
174+ typcategory = 'N',
175+ typdelim = ',',
176+ typelem = Nothing,
177+ typname = "int2"
178+ }
179+
180+int4 :: TypeInfo
181+int4 = TypeInfo {
182+ typoid = Oid 23,
183+ typcategory = 'N',
184+ typdelim = ',',
185+ typelem = Nothing,
186+ typname = "int4"
187+ }
188+
189+regproc :: TypeInfo
190+regproc = TypeInfo {
191+ typoid = Oid 24,
192+ typcategory = 'N',
193+ typdelim = ',',
194+ typelem = Nothing,
195+ typname = "regproc"
196+ }
197+
198+text :: TypeInfo
199+text = TypeInfo {
200+ typoid = Oid 25,
201+ typcategory = 'S',
202+ typdelim = ',',
203+ typelem = Nothing,
204+ typname = "text"
205+ }
206+
207+oid :: TypeInfo
208+oid = TypeInfo {
209+ typoid = Oid 26,
210+ typcategory = 'N',
211+ typdelim = ',',
212+ typelem = Nothing,
213+ typname = "oid"
214+ }
215+
216+tid :: TypeInfo
217+tid = TypeInfo {
218+ typoid = Oid 27,
219+ typcategory = 'U',
220+ typdelim = ',',
221+ typelem = Nothing,
222+ typname = "tid"
223+ }
224+
225+xid :: TypeInfo
226+xid = TypeInfo {
227+ typoid = Oid 28,
228+ typcategory = 'U',
229+ typdelim = ',',
230+ typelem = Nothing,
231+ typname = "xid"
232+ }
233+
234+cid :: TypeInfo
235+cid = TypeInfo {
236+ typoid = Oid 29,
237+ typcategory = 'U',
238+ typdelim = ',',
239+ typelem = Nothing,
240+ typname = "cid"
241+ }
242+
243+xml :: TypeInfo
244+xml = TypeInfo {
245+ typoid = Oid 142,
246+ typcategory = 'U',
247+ typdelim = ',',
248+ typelem = Nothing,
249+ typname = "xml"
250+ }
251+
252+point :: TypeInfo
253+point = TypeInfo {
254+ typoid = Oid 600,
255+ typcategory = 'G',
256+ typdelim = ',',
257+ typelem = Just float8,
258+ typname = "point"
259+ }
260+
261+lseg :: TypeInfo
262+lseg = TypeInfo {
263+ typoid = Oid 601,
264+ typcategory = 'G',
265+ typdelim = ',',
266+ typelem = Just point,
267+ typname = "lseg"
268+ }
269+
270+path :: TypeInfo
271+path = TypeInfo {
272+ typoid = Oid 602,
273+ typcategory = 'G',
274+ typdelim = ',',
275+ typelem = Nothing,
276+ typname = "path"
277+ }
278+
279+box :: TypeInfo
280+box = TypeInfo {
281+ typoid = Oid 603,
282+ typcategory = 'G',
283+ typdelim = ';',
284+ typelem = Just point,
285+ typname = "box"
286+ }
287+
288+polygon :: TypeInfo
289+polygon = TypeInfo {
290+ typoid = Oid 604,
291+ typcategory = 'G',
292+ typdelim = ',',
293+ typelem = Nothing,
294+ typname = "polygon"
295+ }
296+
297+line :: TypeInfo
298+line = TypeInfo {
299+ typoid = Oid 628,
300+ typcategory = 'G',
301+ typdelim = ',',
302+ typelem = Just float8,
303+ typname = "line"
304+ }
305+
306+cidr :: TypeInfo
307+cidr = TypeInfo {
308+ typoid = Oid 650,
309+ typcategory = 'I',
310+ typdelim = ',',
311+ typelem = Nothing,
312+ typname = "cidr"
313+ }
314+
315+float4 :: TypeInfo
316+float4 = TypeInfo {
317+ typoid = Oid 700,
318+ typcategory = 'N',
319+ typdelim = ',',
320+ typelem = Nothing,
321+ typname = "float4"
322+ }
323+
324+float8 :: TypeInfo
325+float8 = TypeInfo {
326+ typoid = Oid 701,
327+ typcategory = 'N',
328+ typdelim = ',',
329+ typelem = Nothing,
330+ typname = "float8"
331+ }
332+
333+abstime :: TypeInfo
334+abstime = TypeInfo {
335+ typoid = Oid 702,
336+ typcategory = 'D',
337+ typdelim = ',',
338+ typelem = Nothing,
339+ typname = "abstime"
340+ }
341+
342+reltime :: TypeInfo
343+reltime = TypeInfo {
344+ typoid = Oid 703,
345+ typcategory = 'T',
346+ typdelim = ',',
347+ typelem = Nothing,
348+ typname = "reltime"
349+ }
350+
351+tinterval :: TypeInfo
352+tinterval = TypeInfo {
353+ typoid = Oid 704,
354+ typcategory = 'T',
355+ typdelim = ',',
356+ typelem = Nothing,
357+ typname = "tinterval"
358+ }
359+
360+unknown :: TypeInfo
361+unknown = TypeInfo {
362+ typoid = Oid 705,
363+ typcategory = 'X',
364+ typdelim = ',',
365+ typelem = Nothing,
366+ typname = "unknown"
367+ }
368+
369+circle :: TypeInfo
370+circle = TypeInfo {
371+ typoid = Oid 718,
372+ typcategory = 'G',
373+ typdelim = ',',
374+ typelem = Nothing,
375+ typname = "circle"
376+ }
377+
378+money :: TypeInfo
379+money = TypeInfo {
380+ typoid = Oid 790,
381+ typcategory = 'N',
382+ typdelim = ',',
383+ typelem = Nothing,
384+ typname = "money"
385+ }
386+
387+macaddr :: TypeInfo
388+macaddr = TypeInfo {
389+ typoid = Oid 829,
390+ typcategory = 'U',
391+ typdelim = ',',
392+ typelem = Nothing,
393+ typname = "macaddr"
394+ }
395+
396+inet :: TypeInfo
397+inet = TypeInfo {
398+ typoid = Oid 869,
399+ typcategory = 'I',
400+ typdelim = ',',
401+ typelem = Nothing,
402+ typname = "inet"
403+ }
404+
405+bpchar :: TypeInfo
406+bpchar = TypeInfo {
407+ typoid = Oid 1042,
408+ typcategory = 'S',
409+ typdelim = ',',
410+ typelem = Nothing,
411+ typname = "bpchar"
412+ }
413+
414+varchar :: TypeInfo
415+varchar = TypeInfo {
416+ typoid = Oid 1043,
417+ typcategory = 'S',
418+ typdelim = ',',
419+ typelem = Nothing,
420+ typname = "varchar"
421+ }
422+
423+date :: TypeInfo
424+date = TypeInfo {
425+ typoid = Oid 1082,
426+ typcategory = 'D',
427+ typdelim = ',',
428+ typelem = Nothing,
429+ typname = "date"
430+ }
431+
432+time :: TypeInfo
433+time = TypeInfo {
434+ typoid = Oid 1083,
435+ typcategory = 'D',
436+ typdelim = ',',
437+ typelem = Nothing,
438+ typname = "time"
439+ }
440+
441+timestamp :: TypeInfo
442+timestamp = TypeInfo {
443+ typoid = Oid 1114,
444+ typcategory = 'D',
445+ typdelim = ',',
446+ typelem = Nothing,
447+ typname = "timestamp"
448+ }
449+
450+timestamptz :: TypeInfo
451+timestamptz = TypeInfo {
452+ typoid = Oid 1184,
453+ typcategory = 'D',
454+ typdelim = ',',
455+ typelem = Nothing,
456+ typname = "timestamptz"
457+ }
458+
459+interval :: TypeInfo
460+interval = TypeInfo {
461+ typoid = Oid 1186,
462+ typcategory = 'T',
463+ typdelim = ',',
464+ typelem = Nothing,
465+ typname = "interval"
466+ }
467+
468+timetz :: TypeInfo
469+timetz = TypeInfo {
470+ typoid = Oid 1266,
471+ typcategory = 'D',
472+ typdelim = ',',
473+ typelem = Nothing,
474+ typname = "timetz"
475+ }
476+
477+bit :: TypeInfo
478+bit = TypeInfo {
479+ typoid = Oid 1560,
480+ typcategory = 'V',
481+ typdelim = ',',
482+ typelem = Nothing,
483+ typname = "bit"
484+ }
485+
486+varbit :: TypeInfo
487+varbit = TypeInfo {
488+ typoid = Oid 1562,
489+ typcategory = 'V',
490+ typdelim = ',',
491+ typelem = Nothing,
492+ typname = "varbit"
493+ }
494+
495+numeric :: TypeInfo
496+numeric = TypeInfo {
497+ typoid = Oid 1700,
498+ typcategory = 'N',
499+ typdelim = ',',
500+ typelem = Nothing,
501+ typname = "numeric"
502+ }
503+
504+refcursor :: TypeInfo
505+refcursor = TypeInfo {
506+ typoid = Oid 1790,
507+ typcategory = 'U',
508+ typdelim = ',',
509+ typelem = Nothing,
510+ typname = "refcursor"
511+ }
512+
513+record :: TypeInfo
514+record = TypeInfo {
515+ typoid = Oid 2249,
516+ typcategory = 'P',
517+ typdelim = ',',
518+ typelem = Nothing,
519+ typname = "record"
520+ }
521+
522+void :: TypeInfo
523+void = TypeInfo {
524+ typoid = Oid 2278,
525+ typcategory = 'P',
526+ typdelim = ',',
527+ typelem = Nothing,
528+ typname = "void"
529+ }
530+
531+uuid :: TypeInfo
532+uuid = TypeInfo {
533+ typoid = Oid 2950,
534+ typcategory = 'U',
535+ typdelim = ',',
536+ typelem = Nothing,
537+ typname = "uuid"
538+ }
tools/GenTypeInfo.hs+2−2
@@ -167,7 +167,7 @@ getTypeInfos typnames = withPostgreSQL $ \conn -> do
167167
168168main = do
169169 (oidmap, namemap) <- getTypeInfos typeNames
170− L.writeFile "../src/Database/PostgreSQL/Simple/TypeInfo.hs"
170+ L.writeFile "../src/Database/PostgreSQL/Simple/TypeInfo/Static.hs"
171171 (Blaze.toLazyByteString (renderFile oidmap namemap typeNames))
172172
173173
@@ -214,7 +214,7 @@ renderFile byOid byName names = ([longstring|
214214-- Note that this file is generated by tools/GenTypeInfo.hs, and should
215215-- not be edited directly
216216
217−module Database.PostgreSQL.Simple.TypeInfo
217+module Database.PostgreSQL.Simple.TypeInfo.Static
218218 ( TypeInfo(..)
219219 , staticTypeInfo
220220|] ++ concat [ " , " ++ bs (hs name) ++ "\n"