Open
Description
Custom type conversion does not seem to work with Domain.
I want to create a custom id field based on int4, but that id field is to be represented as base32 encoded string in javascript land.
create domain appId as int4 not null;
create table app (
id appId
);
select oid from pg_catelog.pg_type where typname = 'appId'; // returns 17842
const sql = postgres({
user: 'postgres',
pass: 'password',
types: {
appId: {
to: 17842,
from: [17842],
serialize: (value: string) => parseInt(value, 32),
parse: (value: string) => {
console.log("parsing") // never invoked
return parseInt(value).toString(32)
}
}
},
});
console.log(await sql`select id from app`) // -> Result(1) [ { id: 1262438631 } ]
the id
will still return as an number because the parse
function is never invokes.
Now if we change the 17842 (oid of appId) to 23 (oid of int4), then the parse
function does get invoked as expected.