@@ -6,7 +6,7 @@
66{- |
77Module: Database.PostgreSQL.Simple.FromField
88Copyright: (c) 2011 MailRank, Inc.
9− (c) 2011-2012 Leon P Smith
9+ (c) 2011-2013 Leon P Smith
1010License: BSD3
1111Maintainer: Leon P Smith <leon@melding-monads.com>
1212Stability: experimental
@@ -31,13 +31,14 @@ might look like for a UUID type that implements the @Read@ class:
3131
3232@
3333import Data.UUID ( UUID )
34−import Database.PostgreSQL.Simple.BuiltinTypes
35− ( BuiltinType(UUID), builtin2oid )
34+import Database.PostgreSQL.Simple.FromField
35+ ( typeOid, returnError, ResultError(..) )
36+import Database.PostgreSQL.Simple.TypeInfo.Static (typoid, uuid)
3637import qualified Data.ByteString as B
3738
3839instance FromField UUID where
3940 fromField f mdata =
40− if typeOid f /= builtin2oid UUID
41+ if typeOid f /= typoid uuid
4142 then returnError Incompatible f \"\"
4243 else case B.unpack \`fmap\` mdata of
4344 Nothing -> returnError UnexpectedNull f \"\"
@@ -49,8 +50,9 @@ instance FromField UUID where
4950
5051Note that because PostgreSQL's @uuid@ type is built into postgres and is
5152not provided by an extension, the 'typeOid' of @uuid@ does not change and
52−thus we can examine it directly. Here, we simply pull the type oid out
53−of the static table provided by postgresql-simple.
53+thus we can examine it directly. One could hard-code the type oid, or
54+obtain it by other means, but in this case we simply pull it out of the
55+static table provided by postgresql-simple.
5456
5557On the other hand if the type is provided by an extension, such as
5658@PostGIS@ or @hstore@, then the 'typeOid' is not stable and can vary from
@@ -175,9 +177,9 @@ class FromField a where
175177--
176178-- More concretely, it returns the @typname@ column associated with the
177179-- type oid in the @pg_type@ table. First, postgresql-simple will check
178−-- built-in, static table. If the type oid is not there, postgresql-simple
179−-- will check a per-connection cache, and then finally query the database's
180−-- meta-schema.
180+-- the built-in, static table. If the type oid is not there,
181+-- postgresql-simple will check a per-connection cache, and then
182+-- finally query the database's meta-schema.
181183
182184typename :: Field -> Conversion ByteString
183185typename field = typname <$> typeInfo field