git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #73 from Targen/json

Add the new JSON type to the static typeinfo table

commit9a114501ffdecf2ea2a4c1cc41a1b2017ab74c3e authorLeon P Smith <leon@melding-monads.com> dateSat 17 Aug 2013, 00:20 (13 years ago) parentafb1604f7b0106
4 files changed+21−1
src/Database/PostgreSQL/Simple/BuiltinTypes.hs+8 src/Database/PostgreSQL/Simple/TypeInfo/Static.hs+10 tools/GenBuiltinTypes.hs+1 tools/GenTypeInfo.hs+2−1
src/Database/PostgreSQL/Simple/BuiltinTypes.hs+8
@@ -72,6 +72,7 @@ data BuiltinType
7272 | Record
7373 | Void
7474 | UUID
75+ | JSON
7576 deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
7677
7778builtin2oid :: BuiltinType -> PQ.Oid
@@ -122,6 +123,7 @@ builtin2oid typ = PQ.Oid $ case typ of
122123 Record -> 2249
123124 Void -> 2278
124125 UUID -> 2950
126+ JSON -> 114
125127
126128oid2builtin :: PQ.Oid -> Maybe BuiltinType
127129oid2builtin (PQ.Oid x) = case x of
@@ -171,6 +173,7 @@ oid2builtin (PQ.Oid x) = case x of
171173 2249 -> Just Record
172174 2278 -> Just Void
173175 2950 -> Just UUID
176+ 114 -> Just JSON
174177 _ -> Nothing
175178
176179builtin2typname :: BuiltinType -> ByteString
@@ -221,6 +224,7 @@ builtin2typname typ = case typ of
221224 Record -> record
222225 Void -> void
223226 UUID -> uuid
227+ JSON -> json
224228
225229oid2typname :: PQ.Oid -> Maybe ByteString
226230oid2typname (PQ.Oid x) = case x of
@@ -270,6 +274,7 @@ oid2typname (PQ.Oid x) = case x of
270274 2249 -> Just record
271275 2278 -> Just void
272276 2950 -> Just uuid
277+ 114 -> Just json
273278 _ -> Nothing
274279
275280bool :: ByteString
@@ -409,3 +414,6 @@ void = "void"
409414
410415uuid :: ByteString
411416uuid = "uuid"
417+
418+json :: ByteString
419+json = "json"
src/Database/PostgreSQL/Simple/TypeInfo/Static.hs+10
@@ -63,6 +63,7 @@ module Database.PostgreSQL.Simple.TypeInfo.Static
6363 , record
6464 , void
6565 , uuid
66+ , json
6667 ) where
6768
6869import Database.PostgreSQL.LibPQ (Oid(..))
@@ -116,6 +117,7 @@ staticTypeInfo (Oid x) = case x of
116117 2249 -> Just record
117118 2278 -> Just void
118119 2950 -> Just uuid
120+ 114 -> Just json
119121 _ -> Nothing
120122
121123bool :: TypeInfo
@@ -485,3 +487,11 @@ uuid = Basic {
485487 typdelim = ',',
486488 typname = "uuid"
487489 }
490+
491+json :: TypeInfo
492+json = Basic {
493+ typoid = Oid 114,
494+ typcategory = 'U',
495+ typdelim = ',',
496+ typname = "json"
497+ }
tools/GenBuiltinTypes.hs+1
@@ -84,6 +84,7 @@ refcursor RefCursor
8484record
8585void
8686uuid UUID
87+json JSON
8788|]
8889
8990instance IsString Blaze.Builder where
tools/GenTypeInfo.hs+2−1
@@ -67,7 +67,7 @@ data TypeInfo = TypeInfo
6767
6868instance FromRow TypeInfo where
6969 fromRow = TypeInfo <$> field <*> charF <*> charF <*> field <*> field
70− where charF = fieldWith (\_f dat -> Ok (B.head (unJust dat)))
70+ where charF = fieldWith (\_f dat -> return (B.head (unJust dat)))
7171 unJust (Just x) = x
7272
7373type NameMap = Map.Map B.ByteString TypeInfo
@@ -128,6 +128,7 @@ refcursor
128128record
129129void
130130uuid
131+json
131132|]
132133
133134instance IsString Blaze.Builder where