Issue
This is a broad question, but I want to ask for opinions
I'm working with Typescript, Prisma ORM and PostgreSQL stack.
I want to handle time ranges. Let's say activeStartDate
, activeEndDate
of different entities.
I want to be able to match when entity A overlaps entity B, query which is active(are active) in a particular date, etc. In general being able to manage time ranges and related operations
Could you suggest a library(in typescript) or is it possible to manage these operations with postgres?
Thanks for your help
Note: I'm trying right now only querying using Prisma ORM which is not easy to read and can be imprecise
Solution
Managing time ranges in your scenario can be effectively handled with PostgreSQL itself. You might want to explore PostgreSQL's range types and functions, especially the tsrange
type for timestamp ranges. This, combined with relevant range operators and functions, can help you perform efficient and accurate time range queries directly in the database.
For TypeScript, you can continue using Prisma, but consider creating custom queries or functions that leverage PostgreSQL's range capabilities. Alternatively, you might find a lightweight TypeScript library for handling time ranges, but keep in mind that offloading these operations to the database can often lead to better performance.
Answered By - Han Ginon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.