Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91763b4

Browse files
committed
Load type names when fetching types
1 parent ea6ccd4 commit 91763b4

File tree

5 files changed

+75
-9
lines changed

5 files changed

+75
-9
lines changed

cjs/src/connection.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,22 +730,44 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
730730
async function fetchArrayTypes() {
731731
needsTypes = false
732732
const types = await new Query([`
733-
select b.oid, b.typarray
733+
select b.oid, b.typarray, b.typname
734734
from pg_catalog.pg_type a
735735
left join pg_catalog.pg_type b on b.oid = a.typelem
736736
where a.typcategory = 'A'
737737
group by b.oid, b.typarray
738738
order by b.oid
739739
`], [], execute)
740-
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
740+
types.forEach(({ oid, typarray, typname }) => addArrayType(oid, typarray, typname))
741741
}
742742

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+
744762
const parser = options.parsers[oid]
745763
options.shared.typeArrayMap[oid] = typarray
746764
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
747765
options.parsers[typarray].array = true
748766
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid])
767+
768+
if(options.serializers[oid]){
769+
options.serializers[typname] = options.serializers[oid]
770+
}
749771
}
750772

751773
function tryNext(x, xs) {

cjs/src/query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const Query = module.exports.Query = class Query extends Promise {
118118

119119
forEach(fn) {
120120
this.forEachFn = fn
121+
this.handle()
121122
return this
122123
}
123124

deno/src/connection.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,22 +733,44 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
733733
async function fetchArrayTypes() {
734734
needsTypes = false
735735
const types = await new Query([`
736-
select b.oid, b.typarray
736+
select b.oid, b.typarray, b.typname
737737
from pg_catalog.pg_type a
738738
left join pg_catalog.pg_type b on b.oid = a.typelem
739739
where a.typcategory = 'A'
740740
group by b.oid, b.typarray
741741
order by b.oid
742742
`], [], execute)
743-
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
743+
types.forEach(({ oid, typarray, typname }) => addArrayType(oid, typarray, typname))
744744
}
745745

746-
function addArrayType(oid, typarray) {
746+
function addArrayType(oid, typarray, typname) {
747+
console.log('add type with name',typname);
748+
749+
const namedtype = options.types[typname];
750+
if(namedtype){
751+
if(namedtype.to == undefined){
752+
namedtype.to ||= oid;
753+
options.serializers[oid] = namedtype.serialize
754+
}
755+
756+
options.serializers[namedtype] = options.serializers[oid];
757+
758+
if(namedtype.from == undefined){
759+
namedtype.from = [oid]
760+
options.parsers[oid] = namedtype.parse
761+
}
762+
options.parsers[namedtype] = options.parsers[oid];
763+
}
764+
747765
const parser = options.parsers[oid]
748766
options.shared.typeArrayMap[oid] = typarray
749767
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
750768
options.parsers[typarray].array = true
751769
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid])
770+
771+
if(options.serializers[oid]){
772+
options.serializers[typname] = options.serializers[oid]
773+
}
752774
}
753775

754776
function tryNext(x, xs) {

deno/src/query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export class Query extends Promise {
118118

119119
forEach(fn) {
120120
this.forEachFn = fn
121+
this.handle()
121122
return this
122123
}
123124

src/connection.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,22 +730,42 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
730730
async function fetchArrayTypes() {
731731
needsTypes = false
732732
const types = await new Query([`
733-
select b.oid, b.typarray
733+
select b.oid, b.typarray, b.typname
734734
from pg_catalog.pg_type a
735735
left join pg_catalog.pg_type b on b.oid = a.typelem
736736
where a.typcategory = 'A'
737737
group by b.oid, b.typarray
738738
order by b.oid
739739
`], [], execute)
740-
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
740+
types.forEach(({ oid, typarray, typname }) => addArrayType(oid, typarray, typname))
741741
}
742742

743-
function addArrayType(oid, typarray) {
743+
function addArrayType(oid, typarray, typname) {
744+
const namedtype = options.types[typname];
745+
if(namedtype){
746+
if(namedtype.to == undefined){
747+
namedtype.to ||= oid;
748+
options.serializers[oid] = namedtype.serialize
749+
}
750+
751+
options.serializers[namedtype] = options.serializers[oid];
752+
753+
if(namedtype.from == undefined){
754+
namedtype.from = [oid]
755+
options.parsers[oid] = namedtype.parse
756+
}
757+
options.parsers[namedtype] = options.parsers[oid];
758+
}
759+
744760
const parser = options.parsers[oid]
745761
options.shared.typeArrayMap[oid] = typarray
746762
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
747763
options.parsers[typarray].array = true
748764
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid])
765+
766+
if(options.serializers[oid]){
767+
options.serializers[typname] = options.serializers[oid]
768+
}
749769
}
750770

751771
function tryNext(x, xs) {

0 commit comments

Comments
 (0)