any way to automatically cast numeric types on retrieval?

I have a numeric field in a video table:
export const VideoTable = pgTable('videos', {
id: uuid('id').primaryKey().defaultRandom(),
height: integer('height'),
width: integer('width'),
duration: numeric('duration', { precision: 10, scale: 5 }),
});
export const VideoTable = pgTable('videos', {
id: uuid('id').primaryKey().defaultRandom(),
height: integer('height'),
width: integer('width'),
duration: numeric('duration', { precision: 10, scale: 5 }),
});
but duration is a string so I end up casting it around my app is there a better type to use or a way to cast on retreival? (i don't really need that much precision)
3 Replies
PGT
PGTOP15mo ago
@luxaritas thanks for this, would I use this at the pgTable schema level or at the query level?
Luxaritas
Luxaritas15mo ago
I believe query level unless you use custom types? You may also want to check if that column type has an alternate mode you can opt into when initializing it in the schema, I can’t remember off hand if it does
Want results from more Discord servers?
Add your server