martianboy / postgres-range

Range data type parser and serializer for PostgreSQL
MIT License
8 stars 7 forks source link

Add toPostgres method #4

Closed kristiandupont closed 9 months ago

kristiandupont commented 1 year ago

node-postgres has undocumented support for custom serialization if an object has a toPostgres method on it.

This PR adds such a function to the Range class so that you can give an instance as a parameter to node-postgres (or Knex or whatever might sit on top) without having to explicitly serialize it.

Since node-pg-types uses this library per default, it felt like the right place to add this so that it works both ways out of the box. Let me know what you think!

martianboy commented 9 months ago

Thank you for this, and my apologies for having missed this for so long! I didn't know about toPostgres().