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

269
Views
Do sequelize promises await postgres trigger completion before they resolve?

I have a contact postgres table, with a contacted_date column. I recently created a contact_date table, which is meant to store each date a contact was contacted.

Because the codebase frequently refers to the contact table for the most recent contacted date, I haven't migrated all the data out of that table. Instead, contact_date contains each date a given contact was contacted, and a trigger on that table updates contact with the latest date for each contact.

If I use Sequelize to make a change to contact_date, does the promise await the successful completion of the trigger? Or does it only await the successful completion of the change to contact_date?

In most of my code, this isn't a big concern - if I persist a new contact date, then my code already has access to that date, and I can use that date in other calculations if I need it. But I'm running into difficulties with my tests, and it may be because of a race condition. In my tests, I'm creating new contacts with contact dates, and some of my tests are failing, perhaps because the promise is resolving before the trigger has finished doing its work.

Update: This SO post indicates that the trigger is part of the same transaction, implying that the Sequelize promise wouldn't resolve until the trigger had completed, but if someone knows for sure, I'd still like to hear dis/confirmation.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I hope you're using transactions for your queries, without which I feel this would not be possible.

Also, an alternative way to achieve your objective would be to use hooks (basically a trigger at application level) in sequelize, instead of creating trigger at DB level.
Since you can pass the transaction object to hooks, the operation performed under hooks is guaranteed to be part of the same transaction which caused the hook to run.

over 4 years ago · Santiago Trujillo 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!