skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. You might want to explore libraries like date-fns or luxon, but I think you can efficiently use postgreSQL

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search