git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix TypeInfo for the _record type
28f469bLeon P Smith
src/Database/PostgreSQL/Simple/TypeInfo/Static.hs+11
@@ -63,6 +63,7 @@ module Database.PostgreSQL.Simple.TypeInfo.Static
63 , refcursor
63 , refcursor
64 , record
64 , record
65 , void
65 , void
66+ , array_record
66 , uuid
67 , uuid
67 , json
68 , json
68 , jsonb
69 , jsonb
@@ -118,6 +119,7 @@ staticTypeInfo (Oid x) = case x of
118 1790 -> Just refcursor
119 1790 -> Just refcursor
119 2249 -> Just record
120 2249 -> Just record
120 2278 -> Just void
121 2278 -> Just void
122+ 2287 -> Just array_record
121 2950 -> Just uuid
123 2950 -> Just uuid
122 114 -> Just json
124 114 -> Just json
123 3802 -> Just jsonb
125 3802 -> Just jsonb
@@ -483,6 +485,15 @@ void = Basic {
483 typname = "void"
485 typname = "void"
484 }
486 }
485
487
488+array_record :: TypeInfo
489+array_record = Array {
490+ typoid = Oid 2287,
491+ typcategory = 'P',
492+ typdelim = ',',
493+ typname = "_record",
494+ typelem = record
495+ }
496+
486uuid :: TypeInfo
497uuid :: TypeInfo
487uuid = Basic {
498uuid = Basic {
488 typoid = Oid 2950,
499 typoid = Oid 2950,
tools/GenTypeInfo.hs+32−11
@@ -125,6 +125,7 @@ numeric
125refcursor
125refcursor
126record
126record
127void
127void
128+_record array_record
128uuid
129uuid
129json
130json
130jsonb
131jsonb
@@ -187,6 +188,35 @@ renderElem byOid elemOid
187 Nothing -> error ("oid not found: " ++ show elemOid)
188 Nothing -> error ("oid not found: " ++ show elemOid)
188 Just x -> "Just " ++ bs (typname x)
189 Just x -> "Just " ++ bs (typname x)
189
190
191+renderTypeInfo :: OidMap -> TypeInfo -> TypeName -> Blaze.Builder
192+renderTypeInfo byOid info name
193+ | typcategory info == 'A' || typname info == "_record" =
194+ let (Just typelem_info) = Map.lookup (typelem info) byOid
195+ (Just typelem_hs_name) = lookup (typname typelem_info) typeNames
196+ in concat
197+ [ "\n"
198+ , bs (hs name), " :: TypeInfo\n"
199+ , bs (hs name), " = Array {\n"
200+ , " typoid = ", fromString (show (typoid info)), ",\n"
201+ , " typcategory = '", Blaze.fromChar (typcategory info), "',\n"
202+ , " typdelim = '", Blaze.fromChar (typdelim info), "',\n"
203+ , " typname = \"", bs (typname info), "\",\n"
204+ , " typelem = ", bs typelem_hs_name, "\n"
205+ , " }\n"
206+ ]
207+ | typcategory info == 'R' = undefined
208+ | otherwise =
209+ concat
210+ [ "\n"
211+ , bs (hs name), " :: TypeInfo\n"
212+ , bs (hs name), " = Basic {\n"
213+ , " typoid = ", fromString (show (typoid info)), ",\n"
214+ , " typcategory = '", Blaze.fromChar (typcategory info), "',\n"
215+ , " typdelim = '", Blaze.fromChar (typdelim info), "',\n"
216+ , " typname = \"", bs (typname info), "\"\n"
217+ , " }\n"
218+ ]
219+
190-- FIXME: add in any names that we need that we didn't specify, (i.e.
220-- FIXME: add in any names that we need that we didn't specify, (i.e.
191-- the "unknowns" in getTypeInfos
221-- the "unknowns" in getTypeInfos
192-- and munge them into a valid haskell identifier if needed.
222-- and munge them into a valid haskell identifier if needed.
@@ -237,15 +267,6 @@ staticTypeInfo (Oid x) = case x of
237 ++ [longstring|
267 ++ [longstring|
238 _ -> Nothing
268 _ -> Nothing
239|]
269|]
240− ++ concat [concat
270+ ++ concat [ renderTypeInfo byOid typeInfo name
241− [ "\n"
242− , bs (hs name), " :: TypeInfo\n"
243− , bs (hs name), " = Basic {\n"
244− , " typoid = ", fromString (show typoid), ",\n"
245− , " typcategory = '", Blaze.fromChar typcategory, "',\n"
246− , " typdelim = '", Blaze.fromChar typdelim, "',\n"
247− , " typname = \"", bs typname, "\"\n"
248− , " }\n"
249− ]
250 | name <- getNames byName names
271 | name <- getNames byName names
251− , let (Just (TypeInfo{..})) = Map.lookup (pg name) byName])
272+ , let (Just typeInfo) = Map.lookup (pg name) byName])