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

115
Visualizações
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
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