Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

467
Views
How to get all records, where the date value in the record is older then an hour with Prisma DB and javascript?

This is what I am doing right now:

const addHours = function (date: Date, hours: number) {
  date.setTime(date.getTime() + (hours * 60 * 60 * 1000))
  return date;
}
let expiredReservation = await prisma.collectionIndexes.findMany({
    where: {
        AND: [
            {
                collectionId: dbCollection.id
            },
            {
                submitedTx: null
            }
        ]
    },
    orderBy: {
        reservedAt: 'asc'
    }
})
expiredReservation = expiredReservation.filter(r => addHours(r.reservedAt, 1).getTime() < new Date().getTime())

These are my models:

model CollectionIndexes {
  id            Int        @id @unique @default(autoincrement())
  submitedTx    String?

  collection    Collection @relation(fields: [collectionId], references: [id])
  collectionId  Int

  reservedIndex Int
  reservedAt    DateTime   @default(now())

}

model Collection {
  id                Int                 @id @unique @default(autoincrement())
  collectionName    String              @unique
  collectionLimit   Int?
  CollectionIndexes CollectionIndexes[]
}

I would much rather just get the correct records from prisma db, without doing filter after. If it's possible, how to write it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Could you try something like below

const subtractHour = (date, hour) => {
  date.setHours(date.getHours() - hour);
  return date;
}

let expiredReservation = await prisma.collectionIndexes.findMany({
    where: {
        AND: [
            {
                collectionId: dbCollection.id
            },
            {
                submitedTx: null
            },
            {
                reservedAt: {
                  lte: subtractHour(new Date(), 1)
                }
            }
        ]
    },
    orderBy: {
        reservedAt: 'asc'
    }
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!