Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Time management library

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading