Skip to content

Commit

Permalink
Allow for incomplete custom types
Browse files Browse the repository at this point in the history
Specifically, I'd like to be able to get away with a type definition consisting in just the `to` property, like this:
`
    int4: {
      to: 23
    }
`
That's because I mereley want to use a name for a Postgres type OID and the usual conversions are already defined in this file. As a fallback, the default serialization in src/connection.js at line 912 is just fine.
  • Loading branch information
acarstoiu authored and porsager committed Jun 26, 2023
1 parent 82908d3 commit 1df4286
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ export const mergeUserTypes = function(types) {
function typeHandlers(types) {
return Object.keys(types).reduce((acc, k) => {
types[k].from && [].concat(types[k].from).forEach(x => acc.parsers[x] = types[k].parse)
acc.serializers[types[k].to] = types[k].serialize
types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
if (types[k].serialize) {
acc.serializers[types[k].to] = types[k].serialize
types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
}
return acc
}, { parsers: {}, serializers: {} })
}
Expand Down

0 comments on commit 1df4286

Please sign in to comment.