node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

Callback on connection.query() never executes

Open ItsRealmy opened this issue 3 years ago • 5 comments

For some reason the callback on connection.query() doesn't execute. I'm trying to execute a query in a stream:

// This DOES execute
connection.query("SELECT * FROM ExampleTable;")
    .on("error", (err) => {
        throw err;
    })
    .stream()
    .pipe(new stream.Transform({
        objectMode: true,
        transform: (row, encoding, callback) => {
            connection.query(`SELECT * FROM AnotherExampleTable LIMIT 1;`, async (err, result, fields) => {
                //This DOES NOT execute
            });
        }
    }))
    .on("finish", () => {
        // handle finish here
    });

ItsRealmy avatar Mar 01 '22 16:03 ItsRealmy

is it just the callback to your second connection.query() or the transform itself is never called?

sidorares avatar Mar 02 '22 03:03 sidorares

transform IS called, but the callback of the query isn't.

ItsRealmy avatar Mar 02 '22 07:03 ItsRealmy

can you try without async ?

sidorares avatar Mar 02 '22 07:03 sidorares

Tried it already, still doesn't work.

ItsRealmy avatar Mar 02 '22 15:03 ItsRealmy

Can you try this? I moved a few of the async/await to new locations.

// This DOES execute
connection.query("SELECT * FROM ExampleTable;")
    .on("error", (err) => {
        throw err;
    })
    .stream()
    .pipe(new stream.Transform({
        objectMode: true,
        transform: async (row, encoding, callback) => {
            await connection.query(`SELECT * FROM AnotherExampleTable LIMIT 1;`, (err, result, fields) => {
                //This DOES NOT execute
            });
        }
    }))
    .on("finish", () => {
        // handle finish here
    });

flipperlite avatar Mar 14 '22 18:03 flipperlite