@@ -563,7 +563,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
563563
564564 if ( needsTypes ) {
565565 initial . reserve && ( initial = null )
566- return fetchArrayTypes ( )
566+ return fetchTypes ( )
567567 }
568568
569569 initial && ! initial . reserve && execute ( initial )
@@ -659,7 +659,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
659659 name : transform . column . from
660660 ? transform . column . from ( x . toString ( 'utf8' , start , index - 1 ) )
661661 : x . toString ( 'utf8' , start , index - 1 ) ,
662- parser : parsers [ type ] ,
662+ parser : parsers [ type ] || parsers [ options . shared . typeOidToName [ type ] ] ,
663663 table,
664664 number,
665665 type
@@ -767,26 +767,29 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
767767 backend . secret = x . readUInt32BE ( 9 )
768768 }
769769
770- async function fetchArrayTypes ( ) {
770+ async function fetchTypes ( ) {
771771 needsTypes = false
772772 const types = await new Query ( [ `
773- select b.oid, b.typarray
774- from pg_catalog.pg_type a
775- left join pg_catalog.pg_type b on b.oid = a.typelem
776- where a.typcategory = 'A'
777- group by b.oid, b.typarray
778- order by b.oid
773+ select oid, typname, typarray
774+ from pg_catalog.pg_type
775+ order by oid
779776 ` ] , [ ] , execute )
780- types . forEach ( ( { oid, typarray } ) => addArrayType ( oid , typarray ) )
777+ types . forEach ( ( { oid, typname, typarray } ) => {
778+ options . shared . typeNameToOid [ typname ] = oid
779+ options . shared . typeOidToName [ oid ] = typname
780+
781+ if ( typarray ) addArrayType ( oid , typarray )
782+ } )
781783 }
782784
783785 function addArrayType ( oid , typarray ) {
784786 if ( ! ! options . parsers [ typarray ] && ! ! options . serializers [ typarray ] ) return
785- const parser = options . parsers [ oid ]
787+ const name = options . shared . typeOidToName [ oid ]
788+ const parser = options . parsers [ oid ] || options . parsers [ name ]
786789 options . shared . typeArrayMap [ oid ] = typarray
787790 options . parsers [ typarray ] = ( xs ) => arrayParser ( xs , parser , typarray )
788791 options . parsers [ typarray ] . array = true
789- options . serializers [ typarray ] = ( xs ) => arraySerializer ( xs , options . serializers [ oid ] , options , typarray )
792+ options . serializers [ typarray ] = ( xs ) => arraySerializer ( xs , options . serializers [ oid ] || options . serializers [ name ] , options , typarray )
790793 }
791794
792795 function tryNext ( x , xs ) {
@@ -973,7 +976,10 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
973976
974977 function Parse ( str , parameters , types , name = '' ) {
975978 b ( ) . P ( ) . str ( name + b . N ) . str ( str + b . N ) . i16 ( parameters . length )
976- parameters . forEach ( ( x , i ) => b . i32 ( types [ i ] || 0 ) )
979+ parameters . forEach ( ( x , i ) => {
980+ const type = types [ i ]
981+ b . i32 ( options . shared . typeNameToOid [ type ] || type || 0 )
982+ } )
977983 return b . end ( )
978984 }
979985
0 commit comments