node-mysql2
node-mysql2 copied to clipboard
Callback on connection.query() never executes
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
});
is it just the callback to your second connection.query() or the transform itself is never called?
transform IS called, but the callback of the query isn't.
can you try without async ?
Tried it already, still doesn't work.
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
});