Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

472
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda