@@ -730,22 +730,44 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
730
730
async function fetchArrayTypes ( ) {
731
731
needsTypes = false
732
732
const types = await new Query ( [ `
733
- select b.oid, b.typarray
733
+ select b.oid, b.typarray, b.typname
734
734
from pg_catalog.pg_type a
735
735
left join pg_catalog.pg_type b on b.oid = a.typelem
736
736
where a.typcategory = 'A'
737
737
group by b.oid, b.typarray
738
738
order by b.oid
739
739
` ] , [ ] , execute )
740
- types . forEach ( ( { oid, typarray } ) => addArrayType ( oid , typarray ) )
740
+ types . forEach ( ( { oid, typarray, typname } ) => addArrayType ( oid , typarray , typname ) )
741
741
}
742
742
743
- function addArrayType ( oid , typarray ) {
743
+ function addArrayType ( oid , typarray , typname ) {
744
+ console . log ( 'add type with name' , typname ) ;
745
+
746
+ const namedtype = options . types [ typname ] ;
747
+ if ( namedtype ) {
748
+ if ( namedtype . to == undefined ) {
749
+ namedtype . to ||= oid ;
750
+ options . serializers [ oid ] = namedtype . serialize
751
+ }
752
+
753
+ options . serializers [ namedtype ] = options . serializers [ oid ] ;
754
+
755
+ if ( namedtype . from == undefined ) {
756
+ namedtype . from = [ oid ]
757
+ options . parsers [ oid ] = namedtype . parse
758
+ }
759
+ options . parsers [ namedtype ] = options . parsers [ oid ] ;
760
+ }
761
+
744
762
const parser = options . parsers [ oid ]
745
763
options . shared . typeArrayMap [ oid ] = typarray
746
764
options . parsers [ typarray ] = ( xs ) => arrayParser ( xs , parser )
747
765
options . parsers [ typarray ] . array = true
748
766
options . serializers [ typarray ] = ( xs ) => arraySerializer ( xs , options . serializers [ oid ] )
767
+
768
+ if ( options . serializers [ oid ] ) {
769
+ options . serializers [ typname ] = options . serializers [ oid ]
770
+ }
749
771
}
750
772
751
773
function tryNext ( x , xs ) {
0 commit comments