Skip to content Skip to sidebar Skip to footer

How To Perform Date Comparisons Against Postgres With Sequelize

I want to delete all records with dates before 20 minutes ago. Postgres (or Sequelize) is not satisfied with the bare javascript Date object I provide as the comparison value. I'm

Solution 1:

Well, this is pretty embarrassing. I structured the where clause incorrectly.

// BAD CODE
await SomeModel.destroy({
  where: {
    [ Sequelize.Op.lt ]: {
      dateColumn: deletionCutoff
    }
  }
})


// GOOD CODE
await SomeModel.destroy({
  where: {
    dateColumn: {
      [ Sequelize.Op.lt ]: deletionCutoff
    }
  }
})

Maybe I should delete the question. Maybe not -- the error I got probably could be more helpful.

Post a Comment for "How To Perform Date Comparisons Against Postgres With Sequelize"