Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda