git.iko.soy/typeable/postgresql-simple
on master help sign in
Fill in some documentation
f685f92Leon P Smith
CHANGES+4−4
@@ -3,7 +3,7 @@ Version 0.3.0.1 (2013-03-26)
3 silently failed to render in Haddock.
3 silently failed to render in Haddock.
4
4
5Version 0.3.0.0 (2013-03-25)
5Version 0.3.0.0 (2013-03-25)
6− * Added support for PostgreSQL's Array Types. Thanks to Jason Dusek
6+ * Added support for PostgreSQL's Array Types. Thanks to Jason Dusek
7 for his work on this feature.
7 for his work on this feature.
8
8
9 * Added a brand new TypeInfo system that gives FromField instances
9 * Added a brand new TypeInfo system that gives FromField instances
@@ -15,7 +15,7 @@ Version 0.3.0.0 (2013-03-25)
15 * Changed the type of the `fromField` and `fromRow` methods to allow
15 * Changed the type of the `fromField` and `fromRow` methods to allow
16 a restricted set of IO actions, and stopped pre-calculating the type
16 a restricted set of IO actions, and stopped pre-calculating the type
17 name of every column. As a result, the type of the `typename`
17 name of every column. As a result, the type of the `typename`
18− operator changed from `Field -> ByteString` to
18+ operator changed from `Field -> ByteString` to
19 `Field -> Conversion ByteString`, where Conversion is the new monad
19 `Field -> Conversion ByteString`, where Conversion is the new monad
20 that conversion computations run inside.
20 that conversion computations run inside.
21
21
@@ -33,7 +33,7 @@ Version 0.3.0.0 (2013-03-25)
33
33
34 * Changed withTransactionModeRetry to accept a predicate of which
34 * Changed withTransactionModeRetry to accept a predicate of which
35 SqlErrors to retry, due to the fact that serialization errors can
35 SqlErrors to retry, due to the fact that serialization errors can
36− sometimes manifest themselves as constraint violations. Thanks
36+ sometimes manifest themselves as constraint violations. Thanks
37 to Oliver Charles for pointing this out and implementing the change.
37 to Oliver Charles for pointing this out and implementing the change.
38
38
39 * Added simple tests of the fold operator, thanks to Joey Adams.
39 * Added simple tests of the fold operator, thanks to Joey Adams.
@@ -45,7 +45,7 @@ Version 0.3.0.0 (2013-03-25)
45
45
46
46
47Version 0.2.4.1 (2012-08-29)
47Version 0.2.4.1 (2012-08-29)
48− * Fixed the documentation of `In`. Thanks to rekado and dstcruz for
48+ * Fixed the documentation of `In`. Thanks to rekado and dstcruz for
49 pointing this out.
49 pointing this out.
50
50
51Version 0.2.4.0 (2012-08-23)
51Version 0.2.4.0 (2012-08-23)
src/Database/PostgreSQL/Simple/TypeInfo.hs+19
@@ -8,6 +8,18 @@
8-- Maintainer: Leon P Smith <leon@melding-monads.com>
8-- Maintainer: Leon P Smith <leon@melding-monads.com>
9-- Stability: experimental
9-- Stability: experimental
10--
10--
11+-- This module provides convenient and efficient access to parts of the
12+-- @pg_type@ metatable. At the moment, this requires PostgreSQL 8.4 if
13+-- you need to work with types that do not appear in
14+-- 'Database.PostgreSQL.Simple.TypeInfo.Static'.
15+--
16+-- The current scheme could be more efficient, especially for some use
17+-- cases. In particular, connection pools that use many user-added
18+-- types and connect to a set of servers with identical (or at least
19+-- compatible) @pg_type@ and associated tables could share a common
20+-- typeinfo cache, thus saving memory and communication between the
21+-- client and server.
22+--
11------------------------------------------------------------------------------
23------------------------------------------------------------------------------
12
24
13module Database.PostgreSQL.Simple.TypeInfo
25module Database.PostgreSQL.Simple.TypeInfo
@@ -27,6 +39,13 @@ import Database.PostgreSQL.Simple.Types
27import Database.PostgreSQL.Simple.TypeInfo.Types
39import Database.PostgreSQL.Simple.TypeInfo.Types
28import Database.PostgreSQL.Simple.TypeInfo.Static
40import Database.PostgreSQL.Simple.TypeInfo.Static
29
41
42+-- | Returns the metadata of the type with a particular oid. To find
43+-- this data, 'getTypeInfo' first consults postgresql-simple's
44+-- built-in 'staticTypeInfo' table, then checks the connection's
45+-- typeinfo cache. Finally, the database's 'pg_type' table will
46+-- be queried only if necessary, and the result will be stored
47+-- in the connections's cache.
48+
30getTypeInfo :: Connection -> PQ.Oid -> IO TypeInfo
49getTypeInfo :: Connection -> PQ.Oid -> IO TypeInfo
31getTypeInfo conn@Connection{..} oid =
50getTypeInfo conn@Connection{..} oid =
32 case staticTypeInfo oid of
51 case staticTypeInfo oid of
src/Database/PostgreSQL/Simple/TypeInfo/Types.hs+3
@@ -13,6 +13,9 @@ module Database.PostgreSQL.Simple.TypeInfo.Types where
13import Data.ByteString(ByteString)
13import Data.ByteString(ByteString)
14import Database.PostgreSQL.LibPQ(Oid)
14import Database.PostgreSQL.LibPQ(Oid)
15
15
16+-- | A structure representing some of the metadata regarding a PostgreSQL
17+-- type, mostly taken from the @pg_type@ table.
18+
16data TypeInfo
19data TypeInfo
17
20
18 = Basic { typoid :: {-# UNPACK #-} !Oid
21 = Basic { typoid :: {-# UNPACK #-} !Oid