git.iko.soy/typeable/postgresql-simple
on master help sign in
Add many of the built-in array types to the static table
d1a8c8fLeon P Smith
src/Database/PostgreSQL/Simple/TypeInfo/Static.hs+528−10
@@ -25,7 +25,6 @@ module Database.PostgreSQL.Simple.TypeInfo.Static
25 , int8
25 , int8
26 , int2
26 , int2
27 , int4
27 , int4
28− , regproc
29 , text
28 , text
30 , oid
29 , oid
31 , tid
30 , tid
@@ -67,6 +66,54 @@ module Database.PostgreSQL.Simple.TypeInfo.Static
67 , uuid
66 , uuid
68 , json
67 , json
69 , jsonb
68 , jsonb
69+ , int2vector
70+ , oidvector
71+ , array_xml
72+ , array_json
73+ , array_line
74+ , array_cidr
75+ , array_circle
76+ , array_money
77+ , array_bool
78+ , array_bytea
79+ , array_char
80+ , array_name
81+ , array_int2
82+ , array_int2vector
83+ , array_int4
84+ , array_text
85+ , array_tid
86+ , array_xid
87+ , array_cid
88+ , array_oidvector
89+ , array_bpchar
90+ , array_varchar
91+ , array_int8
92+ , array_point
93+ , array_lseg
94+ , array_path
95+ , array_box
96+ , array_float4
97+ , array_float8
98+ , array_abstime
99+ , array_reltime
100+ , array_tinterval
101+ , array_polygon
102+ , array_oid
103+ , array_macaddr
104+ , array_inet
105+ , array_timestamp
106+ , array_date
107+ , array_time
108+ , array_timestamptz
109+ , array_interval
110+ , array_numeric
111+ , array_timetz
112+ , array_bit
113+ , array_varbit
114+ , array_refcursor
115+ , array_uuid
116+ , array_jsonb
70 ) where
117 ) where
71
118
72import Database.PostgreSQL.LibPQ (Oid(..))
119import Database.PostgreSQL.LibPQ (Oid(..))
@@ -81,7 +128,6 @@ staticTypeInfo (Oid x) = case x of
81 20 -> Just int8
128 20 -> Just int8
82 21 -> Just int2
129 21 -> Just int2
83 23 -> Just int4
130 23 -> Just int4
84− 24 -> Just regproc
85 25 -> Just text
131 25 -> Just text
86 26 -> Just oid
132 26 -> Just oid
87 27 -> Just tid
133 27 -> Just tid
@@ -123,6 +169,54 @@ staticTypeInfo (Oid x) = case x of
123 2950 -> Just uuid
169 2950 -> Just uuid
124 114 -> Just json
170 114 -> Just json
125 3802 -> Just jsonb
171 3802 -> Just jsonb
172+ 22 -> Just int2vector
173+ 30 -> Just oidvector
174+ 143 -> Just array_xml
175+ 199 -> Just array_json
176+ 629 -> Just array_line
177+ 651 -> Just array_cidr
178+ 719 -> Just array_circle
179+ 791 -> Just array_money
180+ 1000 -> Just array_bool
181+ 1001 -> Just array_bytea
182+ 1002 -> Just array_char
183+ 1003 -> Just array_name
184+ 1005 -> Just array_int2
185+ 1006 -> Just array_int2vector
186+ 1007 -> Just array_int4
187+ 1009 -> Just array_text
188+ 1010 -> Just array_tid
189+ 1011 -> Just array_xid
190+ 1012 -> Just array_cid
191+ 1013 -> Just array_oidvector
192+ 1014 -> Just array_bpchar
193+ 1015 -> Just array_varchar
194+ 1016 -> Just array_int8
195+ 1017 -> Just array_point
196+ 1018 -> Just array_lseg
197+ 1019 -> Just array_path
198+ 1020 -> Just array_box
199+ 1021 -> Just array_float4
200+ 1022 -> Just array_float8
201+ 1023 -> Just array_abstime
202+ 1024 -> Just array_reltime
203+ 1025 -> Just array_tinterval
204+ 1027 -> Just array_polygon
205+ 1028 -> Just array_oid
206+ 1040 -> Just array_macaddr
207+ 1041 -> Just array_inet
208+ 1115 -> Just array_timestamp
209+ 1182 -> Just array_date
210+ 1183 -> Just array_time
211+ 1185 -> Just array_timestamptz
212+ 1187 -> Just array_interval
213+ 1231 -> Just array_numeric
214+ 1270 -> Just array_timetz
215+ 1561 -> Just array_bit
216+ 1563 -> Just array_varbit
217+ 2201 -> Just array_refcursor
218+ 2951 -> Just array_uuid
219+ 3807 -> Just array_jsonb
126 _ -> Nothing
220 _ -> Nothing
127
221
128bool :: TypeInfo
222bool :: TypeInfo
@@ -181,14 +275,6 @@ int4 = Basic {
181 typname = "int4"
275 typname = "int4"
182 }
276 }
183
277
184−regproc :: TypeInfo
185−regproc = Basic {
186− typoid = Oid 24,
187− typcategory = 'N',
188− typdelim = ',',
189− typname = "regproc"
190− }
191−
192text :: TypeInfo
278text :: TypeInfo
193text = Basic {
279text = Basic {
194 typoid = Oid 25,
280 typoid = Oid 25,
@@ -517,3 +603,435 @@ jsonb = Basic {
517 typdelim = ',',
603 typdelim = ',',
518 typname = "jsonb"
604 typname = "jsonb"
519 }
605 }
606+
607+int2vector :: TypeInfo
608+int2vector = Array {
609+ typoid = Oid 22,
610+ typcategory = 'A',
611+ typdelim = ',',
612+ typname = "int2vector",
613+ typelem = int2
614+ }
615+
616+oidvector :: TypeInfo
617+oidvector = Array {
618+ typoid = Oid 30,
619+ typcategory = 'A',
620+ typdelim = ',',
621+ typname = "oidvector",
622+ typelem = oid
623+ }
624+
625+array_xml :: TypeInfo
626+array_xml = Array {
627+ typoid = Oid 143,
628+ typcategory = 'A',
629+ typdelim = ',',
630+ typname = "_xml",
631+ typelem = xml
632+ }
633+
634+array_json :: TypeInfo
635+array_json = Array {
636+ typoid = Oid 199,
637+ typcategory = 'A',
638+ typdelim = ',',
639+ typname = "_json",
640+ typelem = json
641+ }
642+
643+array_line :: TypeInfo
644+array_line = Array {
645+ typoid = Oid 629,
646+ typcategory = 'A',
647+ typdelim = ',',
648+ typname = "_line",
649+ typelem = line
650+ }
651+
652+array_cidr :: TypeInfo
653+array_cidr = Array {
654+ typoid = Oid 651,
655+ typcategory = 'A',
656+ typdelim = ',',
657+ typname = "_cidr",
658+ typelem = cidr
659+ }
660+
661+array_circle :: TypeInfo
662+array_circle = Array {
663+ typoid = Oid 719,
664+ typcategory = 'A',
665+ typdelim = ',',
666+ typname = "_circle",
667+ typelem = circle
668+ }
669+
670+array_money :: TypeInfo
671+array_money = Array {
672+ typoid = Oid 791,
673+ typcategory = 'A',
674+ typdelim = ',',
675+ typname = "_money",
676+ typelem = money
677+ }
678+
679+array_bool :: TypeInfo
680+array_bool = Array {
681+ typoid = Oid 1000,
682+ typcategory = 'A',
683+ typdelim = ',',
684+ typname = "_bool",
685+ typelem = bool
686+ }
687+
688+array_bytea :: TypeInfo
689+array_bytea = Array {
690+ typoid = Oid 1001,
691+ typcategory = 'A',
692+ typdelim = ',',
693+ typname = "_bytea",
694+ typelem = bytea
695+ }
696+
697+array_char :: TypeInfo
698+array_char = Array {
699+ typoid = Oid 1002,
700+ typcategory = 'A',
701+ typdelim = ',',
702+ typname = "_char",
703+ typelem = char
704+ }
705+
706+array_name :: TypeInfo
707+array_name = Array {
708+ typoid = Oid 1003,
709+ typcategory = 'A',
710+ typdelim = ',',
711+ typname = "_name",
712+ typelem = name
713+ }
714+
715+array_int2 :: TypeInfo
716+array_int2 = Array {
717+ typoid = Oid 1005,
718+ typcategory = 'A',
719+ typdelim = ',',
720+ typname = "_int2",
721+ typelem = int2
722+ }
723+
724+array_int2vector :: TypeInfo
725+array_int2vector = Array {
726+ typoid = Oid 1006,
727+ typcategory = 'A',
728+ typdelim = ',',
729+ typname = "_int2vector",
730+ typelem = int2vector
731+ }
732+
733+array_int4 :: TypeInfo
734+array_int4 = Array {
735+ typoid = Oid 1007,
736+ typcategory = 'A',
737+ typdelim = ',',
738+ typname = "_int4",
739+ typelem = int4
740+ }
741+
742+array_text :: TypeInfo
743+array_text = Array {
744+ typoid = Oid 1009,
745+ typcategory = 'A',
746+ typdelim = ',',
747+ typname = "_text",
748+ typelem = text
749+ }
750+
751+array_tid :: TypeInfo
752+array_tid = Array {
753+ typoid = Oid 1010,
754+ typcategory = 'A',
755+ typdelim = ',',
756+ typname = "_tid",
757+ typelem = tid
758+ }
759+
760+array_xid :: TypeInfo
761+array_xid = Array {
762+ typoid = Oid 1011,
763+ typcategory = 'A',
764+ typdelim = ',',
765+ typname = "_xid",
766+ typelem = xid
767+ }
768+
769+array_cid :: TypeInfo
770+array_cid = Array {
771+ typoid = Oid 1012,
772+ typcategory = 'A',
773+ typdelim = ',',
774+ typname = "_cid",
775+ typelem = cid
776+ }
777+
778+array_oidvector :: TypeInfo
779+array_oidvector = Array {
780+ typoid = Oid 1013,
781+ typcategory = 'A',
782+ typdelim = ',',
783+ typname = "_oidvector",
784+ typelem = oidvector
785+ }
786+
787+array_bpchar :: TypeInfo
788+array_bpchar = Array {
789+ typoid = Oid 1014,
790+ typcategory = 'A',
791+ typdelim = ',',
792+ typname = "_bpchar",
793+ typelem = bpchar
794+ }
795+
796+array_varchar :: TypeInfo
797+array_varchar = Array {
798+ typoid = Oid 1015,
799+ typcategory = 'A',
800+ typdelim = ',',
801+ typname = "_varchar",
802+ typelem = varchar
803+ }
804+
805+array_int8 :: TypeInfo
806+array_int8 = Array {
807+ typoid = Oid 1016,
808+ typcategory = 'A',
809+ typdelim = ',',
810+ typname = "_int8",
811+ typelem = int8
812+ }
813+
814+array_point :: TypeInfo
815+array_point = Array {
816+ typoid = Oid 1017,
817+ typcategory = 'A',
818+ typdelim = ',',
819+ typname = "_point",
820+ typelem = point
821+ }
822+
823+array_lseg :: TypeInfo
824+array_lseg = Array {
825+ typoid = Oid 1018,
826+ typcategory = 'A',
827+ typdelim = ',',
828+ typname = "_lseg",
829+ typelem = lseg
830+ }
831+
832+array_path :: TypeInfo
833+array_path = Array {
834+ typoid = Oid 1019,
835+ typcategory = 'A',
836+ typdelim = ',',
837+ typname = "_path",
838+ typelem = path
839+ }
840+
841+array_box :: TypeInfo
842+array_box = Array {
843+ typoid = Oid 1020,
844+ typcategory = 'A',
845+ typdelim = ';',
846+ typname = "_box",
847+ typelem = box
848+ }
849+
850+array_float4 :: TypeInfo
851+array_float4 = Array {
852+ typoid = Oid 1021,
853+ typcategory = 'A',
854+ typdelim = ',',
855+ typname = "_float4",
856+ typelem = float4
857+ }
858+
859+array_float8 :: TypeInfo
860+array_float8 = Array {
861+ typoid = Oid 1022,
862+ typcategory = 'A',
863+ typdelim = ',',
864+ typname = "_float8",
865+ typelem = float8
866+ }
867+
868+array_abstime :: TypeInfo
869+array_abstime = Array {
870+ typoid = Oid 1023,
871+ typcategory = 'A',
872+ typdelim = ',',
873+ typname = "_abstime",
874+ typelem = abstime
875+ }
876+
877+array_reltime :: TypeInfo
878+array_reltime = Array {
879+ typoid = Oid 1024,
880+ typcategory = 'A',
881+ typdelim = ',',
882+ typname = "_reltime",
883+ typelem = reltime
884+ }
885+
886+array_tinterval :: TypeInfo
887+array_tinterval = Array {
888+ typoid = Oid 1025,
889+ typcategory = 'A',
890+ typdelim = ',',
891+ typname = "_tinterval",
892+ typelem = tinterval
893+ }
894+
895+array_polygon :: TypeInfo
896+array_polygon = Array {
897+ typoid = Oid 1027,
898+ typcategory = 'A',
899+ typdelim = ',',
900+ typname = "_polygon",
901+ typelem = polygon
902+ }
903+
904+array_oid :: TypeInfo
905+array_oid = Array {
906+ typoid = Oid 1028,
907+ typcategory = 'A',
908+ typdelim = ',',
909+ typname = "_oid",
910+ typelem = oid
911+ }
912+
913+array_macaddr :: TypeInfo
914+array_macaddr = Array {
915+ typoid = Oid 1040,
916+ typcategory = 'A',
917+ typdelim = ',',
918+ typname = "_macaddr",
919+ typelem = macaddr
920+ }
921+
922+array_inet :: TypeInfo
923+array_inet = Array {
924+ typoid = Oid 1041,
925+ typcategory = 'A',
926+ typdelim = ',',
927+ typname = "_inet",
928+ typelem = inet
929+ }
930+
931+array_timestamp :: TypeInfo
932+array_timestamp = Array {
933+ typoid = Oid 1115,
934+ typcategory = 'A',
935+ typdelim = ',',
936+ typname = "_timestamp",
937+ typelem = timestamp
938+ }
939+
940+array_date :: TypeInfo
941+array_date = Array {
942+ typoid = Oid 1182,
943+ typcategory = 'A',
944+ typdelim = ',',
945+ typname = "_date",
946+ typelem = date
947+ }
948+
949+array_time :: TypeInfo
950+array_time = Array {
951+ typoid = Oid 1183,
952+ typcategory = 'A',
953+ typdelim = ',',
954+ typname = "_time",
955+ typelem = time
956+ }
957+
958+array_timestamptz :: TypeInfo
959+array_timestamptz = Array {
960+ typoid = Oid 1185,
961+ typcategory = 'A',
962+ typdelim = ',',
963+ typname = "_timestamptz",
964+ typelem = timestamptz
965+ }
966+
967+array_interval :: TypeInfo
968+array_interval = Array {
969+ typoid = Oid 1187,
970+ typcategory = 'A',
971+ typdelim = ',',
972+ typname = "_interval",
973+ typelem = interval
974+ }
975+
976+array_numeric :: TypeInfo
977+array_numeric = Array {
978+ typoid = Oid 1231,
979+ typcategory = 'A',
980+ typdelim = ',',
981+ typname = "_numeric",
982+ typelem = numeric
983+ }
984+
985+array_timetz :: TypeInfo
986+array_timetz = Array {
987+ typoid = Oid 1270,
988+ typcategory = 'A',
989+ typdelim = ',',
990+ typname = "_timetz",
991+ typelem = timetz
992+ }
993+
994+array_bit :: TypeInfo
995+array_bit = Array {
996+ typoid = Oid 1561,
997+ typcategory = 'A',
998+ typdelim = ',',
999+ typname = "_bit",
1000+ typelem = bit
1001+ }
1002+
1003+array_varbit :: TypeInfo
1004+array_varbit = Array {
1005+ typoid = Oid 1563,
1006+ typcategory = 'A',
1007+ typdelim = ',',
1008+ typname = "_varbit",
1009+ typelem = varbit
1010+ }
1011+
1012+array_refcursor :: TypeInfo
1013+array_refcursor = Array {
1014+ typoid = Oid 2201,
1015+ typcategory = 'A',
1016+ typdelim = ',',
1017+ typname = "_refcursor",
1018+ typelem = refcursor
1019+ }
1020+
1021+array_uuid :: TypeInfo
1022+array_uuid = Array {
1023+ typoid = Oid 2951,
1024+ typcategory = 'A',
1025+ typdelim = ',',
1026+ typname = "_uuid",
1027+ typelem = uuid
1028+ }
1029+
1030+array_jsonb :: TypeInfo
1031+array_jsonb = Array {
1032+ typoid = Oid 3807,
1033+ typcategory = 'A',
1034+ typdelim = ',',
1035+ typname = "_jsonb",
1036+ typelem = jsonb
1037+ }
tools/GenTypeInfo.hs+52−3
@@ -87,7 +87,6 @@ name
87int8
87int8
88int2
88int2
89int4
89int4
90−regproc
91text
90text
92oid
91oid
93tid
92tid
@@ -125,10 +124,58 @@ numeric
125refcursor
124refcursor
126record
125record
127void
126void
128−_record array_record
127+_record array_record
129uuid
128uuid
130json
129json
131jsonb
130jsonb
131+int2vector
132+oidvector
133+_xml array_xml
134+_json array_json
135+_line array_line
136+_cidr array_cidr
137+_circle array_circle
138+_money array_money
139+_bool array_bool
140+_bytea array_bytea
141+_char array_char
142+_name array_name
143+_int2 array_int2
144+_int2vector array_int2vector
145+_int4 array_int4
146+_text array_text
147+_tid array_tid
148+_xid array_xid
149+_cid array_cid
150+_oidvector array_oidvector
151+_bpchar array_bpchar
152+_varchar array_varchar
153+_int8 array_int8
154+_point array_point
155+_lseg array_lseg
156+_path array_path
157+_box array_box
158+_float4 array_float4
159+_float8 array_float8
160+_abstime array_abstime
161+_reltime array_reltime
162+_tinterval array_tinterval
163+_polygon array_polygon
164+_oid array_oid
165+_macaddr array_macaddr
166+_inet array_inet
167+_timestamp array_timestamp
168+_date array_date
169+_time array_time
170+_timestamptz array_timestamptz
171+_interval array_interval
172+_numeric array_numeric
173+_timetz array_timetz
174+_bit array_bit
175+_varbit array_varbit
176+_refcursor array_refcursor
177+_uuid array_uuid
178+_jsonb array_jsonb
132|]
179|]
133
180
134instance IsString Blaze.Builder where
181instance IsString Blaze.Builder where
@@ -192,7 +239,9 @@ renderTypeInfo :: OidMap -> TypeInfo -> TypeName -> Blaze.Builder
192renderTypeInfo byOid info name
239renderTypeInfo byOid info name
193 | typcategory info == 'A' || typname info == "_record" =
240 | typcategory info == 'A' || typname info == "_record" =
194 let (Just typelem_info) = Map.lookup (typelem info) byOid
241 let (Just typelem_info) = Map.lookup (typelem info) byOid
195− (Just typelem_hs_name) = lookup (typname typelem_info) typeNames
242+ typelem_hs_name = case lookup (typname typelem_info) typeNames of
243+ Nothing -> error ("type not found: " ++ B.unpack( typname typelem_info) ++ " (typelem of " ++ B.unpack (typname info) ++ ")")
244+ Just x -> x
196 in concat
245 in concat
197 [ "\n"
246 [ "\n"
198 , bs (hs name), " :: TypeInfo\n"
247 , bs (hs name), " :: TypeInfo\n"