Closed unilynx closed 1 year ago
Hi GlobalTypeMap is a registry that matches PostgreSQL's OID's with JavaScript types. And you are right "DataTypeMap.determine" method lookups for data types in "fifo" order. So this might be a problem for registering new types. To overcome this issue, I have released a new version (2.6.0) with the following changes. Now DataTypeMap.determine method lookup for data-types in reverse order. So last registered data-type returns first. Please let me know if this fixes your problem.
Please let me know if this fixes your problem.
Thanks. I'll try to doublecheck later but I expect it should - I simply replaced push
with unshift
in the register call which fixed it too and has about the same effect
yep ,works
Which OID do you registering as a new type? Are there any missed data types in the library?
It's not an existing type, but a custom type (CREATE TYPE webhare_internal.webhare_blob AS (id text, size int8)
) which I convert from/to a JS Object that wraps a blob/file stored outside postgres.
@erayhanoglu doesn't simply reversing the lookup order break other assumptions/risk regressions? Eg JsonType and JsonbType have the same isType
check. So 2.6.0 would match with the JsonbType where older versions would match JsonType.
I spoke too soon, you also reordered the registrations.
You are welcome. :grinning:
How can I properly define my own object type in the GlobalTypeMap - or am I not supposed to do that ?
I'm trying to add a type using
GlobalTypeMap.register
but itsisType
is never invoked as the builtin JSONType simply checks fortypeof v === "object"
and GlobalTypeMap.register adds new types to the end of the list.