Skip to content

Commit 7d3ce4b

Browse files
committed
Register array types properly
1 parent 0f10e50 commit 7d3ce4b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,27 @@ function Postgres(a, b) {
221221
return arrayTypesPromise || (arrayTypesPromise =
222222
new Promise((resolve, reject) => {
223223
send(connection, { resolve, reject, raw: true }, `
224-
select oid, typelem
225-
from pg_catalog.pg_type
226-
where typcategory = 'A'
224+
select b.oid, b.typarray
225+
from pg_catalog.pg_type a
226+
left join pg_catalog.pg_type b on b.oid = a.typelem
227+
where a.typcategory = 'A' and b.typcategory != 'C'
228+
group by b.oid, b.typarray
229+
order by b.oid
227230
`)
228231
}).then(types => {
229-
types.forEach(({ oid, typelem }) => addArrayType(oid, typelem))
232+
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
230233
ready = true
231234
})
232235
)
233236
}
234237

235-
function addArrayType(oid, typelem) {
236-
const parser = options.parsers[typelem]
238+
function addArrayType(oid, typarray) {
239+
const parser = options.parsers[oid]
237240

238-
typeArrayMap[typelem] = oid
239-
options.parsers[oid] = (xs) => arrayParser(xs, parser)
240-
options.parsers[oid].array = true
241-
options.serializers[oid] = (xs) => arraySerializer(xs, options.serializers[typelem])
241+
typeArrayMap[oid] = typarray
242+
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
243+
options.parsers[typarray].array = true
244+
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid])
242245
}
243246

244247
function addTypes(sql, connection) {

0 commit comments

Comments
 (0)