git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #118 from ibotty/jsonb-support
57e4199Leon P Smith
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+7−8
@@ -27,11 +27,11 @@ Note that the 'Float' and 'Double' instances use attoparsec's 'double'
27conversion routine, which sacrifices some accuracy for speed. If you
27conversion routine, which sacrifices some accuracy for speed. If you
28need accuracy, consider first converting data to a 'Scientific' or 'Rational'
28need accuracy, consider first converting data to a 'Scientific' or 'Rational'
29type, and then converting to a floating-point type. If you are defining
29type, and then converting to a floating-point type. If you are defining
30−your own 'Database.PostgreSQL.Simple.FromRow.FromRow' instances, this can be
30+your own 'Database.PostgreSQL.Simple.FromRow.FromRow' instances, this can be
31−acheived simply by
31+acheived simply by
32−@'fromRational' '<$>' 'Database.PostgreSQL.Simple.FromRow.field'@, although
32+@'fromRational' '<$>' 'Database.PostgreSQL.Simple.FromRow.field'@, although
33this idiom is additionally compatible with PostgreSQL's @numeric@ type.
33this idiom is additionally compatible with PostgreSQL's @numeric@ type.
34−If this is unacceptable, you may find
34+If this is unacceptable, you may find
35'Database.PostgreSQL.Simple.FromRow.fieldWith' useful.
35'Database.PostgreSQL.Simple.FromRow.fieldWith' useful.
36
36
37Because 'FromField' is a typeclass, one may provide conversions to
37Because 'FromField' is a typeclass, one may provide conversions to
@@ -104,12 +104,11 @@ module Database.PostgreSQL.Simple.FromField
104
104
105#include "MachDeps.h"
105#include "MachDeps.h"
106
106
107−import Control.Applicative
107+import Control.Applicative ( (<|>), (<$>), pure )
108− ( Applicative, (<|>), (<$>), pure )
109import Control.Concurrent.MVar (MVar, newMVar)
108import Control.Concurrent.MVar (MVar, newMVar)
110import Control.Exception (Exception)
109import Control.Exception (Exception)
111import qualified Data.Aeson as JSON
110import qualified Data.Aeson as JSON
112−import Data.Attoparsec.Char8 hiding (Result)
111+import Data.Attoparsec.ByteString.Char8 hiding (Result)
113import Data.ByteString (ByteString)
112import Data.ByteString (ByteString)
114import qualified Data.ByteString.Char8 as B
113import qualified Data.ByteString.Char8 as B
115import Data.Int (Int16, Int32, Int64)
114import Data.Int (Int16, Int32, Int64)
@@ -492,7 +491,7 @@ instance FromField UUID where
492-- | json
491-- | json
493instance FromField JSON.Value where
492instance FromField JSON.Value where
494 fromField f mbs =
493 fromField f mbs =
495− if typeOid f /= $(inlineTypoid TI.json)
494+ if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
496 then returnError Incompatible f ""
495 then returnError Incompatible f ""
497 else case mbs of
496 else case mbs of
498 Nothing -> returnError UnexpectedNull f ""
497 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