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

106
Views
Prevent database access when selecting for update in Sequelize

I have an asynchronous function a that selects a row's columns and then updates them after x amount of time, and an asynchronous function b that accesses these same values. I'm trying to make it so that function b waits for function a to be done with fetching and updating the row's values before it accesses it. I think the answer to this has something to do with Transactions but I'm not sure how to implement it.

Here's my attempt on it:

this.storage.Instance.transaction({
    isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
}, async transaction => {
    this.storage.Guilds.findOne({
        where: {
            id: 1,
        },
        lock: transaction.LOCK.UPDATE,
    }, {
        transaction: transaction,
    }).then(guild => {
        setTimeout(() => {
            guild.settings = 2;
            guild.save();
        }, 10000);
    });
});

this.storage.Guilds.findOne({
    where: {
        id: 1,
    },
}).then(guild => {
    guild.settings = 3;
    guild.save();
    this.logger.debug(guild.settings);
});

This is just a test I made, in practical terms these functions would be in completely different scopes. The second SELECT FOR UPDATE query is not waiting for the first SELECT FOR UPDATE.

about 4 years ago · Juan Pablo Isaza
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!