adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

Column-level type mapping #567

Open andreaperizzato opened 7 months ago

andreaperizzato commented 7 months ago

How can I map the type of a specific column to a custom type?

The doc explains how column postgres types can be mapped to specific JS types, but i was looking at setting up mappings at column level.

As an example, let's say I have a table users

id status
1 active
2 inactive

And a table orders

id status
1 dispatched
2 cancelled

And i would like to map users.status and orders.status to two custom TypeScript types. These may look like enums but the problem is more generic and could be any type.