Custom Types does not work with DOMAIN
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the SQL and JavaScript reproduction in the issue as the starting point; run it against PostgreSQL and trace why a domain OID bypasses the configured custom parser. Done means selecting app.id invokes parse and returns the base32 string, while serialization still handles the custom id.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100