git.iko.soy/typeable/postgresql-simple
on master help sign in
support jsonb type (from postgresql 9.4)
01886cbTobias Florek
src/Database/PostgreSQL/Simple/BuiltinTypes.hs+8
@@ -74,6 +74,7 @@ data BuiltinType
74 | Void
74 | Void
75 | UUID
75 | UUID
76 | JSON
76 | JSON
77+ | JSONB
77 deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
78 deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable)
78
79
79builtin2oid :: BuiltinType -> PQ.Oid
80builtin2oid :: BuiltinType -> PQ.Oid
@@ -125,6 +126,7 @@ builtin2oid typ = PQ.Oid $ case typ of
125 Void -> 2278
126 Void -> 2278
126 UUID -> 2950
127 UUID -> 2950
127 JSON -> 114
128 JSON -> 114
129+ JSONB -> 3802
128
130
129oid2builtin :: PQ.Oid -> Maybe BuiltinType
131oid2builtin :: PQ.Oid -> Maybe BuiltinType
130oid2builtin (PQ.Oid x) = case x of
132oid2builtin (PQ.Oid x) = case x of
@@ -175,6 +177,7 @@ oid2builtin (PQ.Oid x) = case x of
175 2278 -> Just Void
177 2278 -> Just Void
176 2950 -> Just UUID
178 2950 -> Just UUID
177 114 -> Just JSON
179 114 -> Just JSON
180+ 3802 -> Just JSONB
178 _ -> Nothing
181 _ -> Nothing
179
182
180builtin2typname :: BuiltinType -> ByteString
183builtin2typname :: BuiltinType -> ByteString
@@ -226,6 +229,7 @@ builtin2typname typ = case typ of
226 Void -> void
229 Void -> void
227 UUID -> uuid
230 UUID -> uuid
228 JSON -> json
231 JSON -> json
232+ JSONB -> jsonb
229
233
230oid2typname :: PQ.Oid -> Maybe ByteString
234oid2typname :: PQ.Oid -> Maybe ByteString
231oid2typname (PQ.Oid x) = case x of
235oid2typname (PQ.Oid x) = case x of
@@ -276,6 +280,7 @@ oid2typname (PQ.Oid x) = case x of
276 2278 -> Just void
280 2278 -> Just void
277 2950 -> Just uuid
281 2950 -> Just uuid
278 114 -> Just json
282 114 -> Just json
283+ 3802 -> Just jsonb
279 _ -> Nothing
284 _ -> Nothing
280
285
281bool :: ByteString
286bool :: ByteString
@@ -418,3 +423,6 @@ uuid = "uuid"
418
423
419json :: ByteString
424json :: ByteString
420json = "json"
425json = "json"
426+
427+jsonb :: ByteString
428+jsonb = "jsonb"
src/Database/PostgreSQL/Simple/FromField.hs+1−1
@@ -492,7 +492,7 @@ instance FromField UUID where
492-- | json
492-- | json
493instance FromField JSON.Value where
493instance FromField JSON.Value where
494 fromField f mbs =
494 fromField f mbs =
495− if typeOid f /= $(inlineTypoid TI.json)
495+ if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
496 then returnError Incompatible f ""
496 then returnError Incompatible f ""
497 else case mbs of
497 else case mbs of
498 Nothing -> returnError UnexpectedNull f ""
498 Nothing -> returnError UnexpectedNull f ""
src/Database/PostgreSQL/Simple/TypeInfo/Static.hs+10
@@ -65,6 +65,7 @@ module Database.PostgreSQL.Simple.TypeInfo.Static
65 , void
65 , void
66 , uuid
66 , uuid
67 , json
67 , json
68+ , jsonb
68 ) where
69 ) where
69
70
70import Database.PostgreSQL.LibPQ (Oid(..))
71import Database.PostgreSQL.LibPQ (Oid(..))
@@ -119,6 +120,7 @@ staticTypeInfo (Oid x) = case x of
119 2278 -> Just void
120 2278 -> Just void
120 2950 -> Just uuid
121 2950 -> Just uuid
121 114 -> Just json
122 114 -> Just json
123+ 3802 -> Just jsonb
122 _ -> Nothing
124 _ -> Nothing
123
125
124bool :: TypeInfo
126bool :: TypeInfo
@@ -496,3 +498,11 @@ json = Basic {
496 typdelim = ',',
498 typdelim = ',',
497 typname = "json"
499 typname = "json"
498 }
500 }
501+
502+jsonb :: TypeInfo
503+jsonb = Basic {
504+ typoid = Oid 3802,
505+ typcategory = 'U',
506+ typdelim = ',',
507+ typname = "jsonb"
508+ }
tools/GenBuiltinTypes.hs+1
@@ -85,6 +85,7 @@ record
85void
85void
86uuid UUID
86uuid UUID
87json JSON
87json JSON
88+jsonb JSONB
88|]
89|]
89
90
90instance IsString Blaze.Builder where
91instance IsString Blaze.Builder where
tools/GenTypeInfo.hs+1
@@ -127,6 +127,7 @@ record
127void
127void
128uuid
128uuid
129json
129json
130+jsonb
130|]
131|]
131
132
132instance IsString Blaze.Builder where
133instance IsString Blaze.Builder where