node-mysql2
node-mysql2 copied to clipboard
`namedPlaceholders` option in connection config causes type error
Hi,
Following an example from https://github.com/sidorares/node-mysql2/blob/master/documentation/Extras.md on how to send named parameters as an object instead of an array but that causes an error:
TypeError: Class constructor LRUCache cannot be invoked without 'new'
The code where the error occurs. Tried it several different ways but with no success.
conn.execute('select :x + :y as z', { x: 1, y: 2 }, (err, rows) => {
// statement prepared as "select ? + ? as z" and executed with [1,2] values
// rows returned: [ { z: 3 } ]
});
Any insight would be appreciated.
Hi @svetlasyrimis, I tried it in ^3.4.1 and it works fine for me.
I performed a real connection and:
import mysql from 'mysql2';
const conn = mysql.createConnection({
host: '',
user: '',
password: '',
database: '',
});
conn.config.namedPlaceholders = true;
conn.execute('select :x + :y as z', { x: 1, y: 2 }, (err, rows) => {
conn.end();
console.log(rows);
});
That returns:
[ { z: 3 } ]
Can you check it using the latest version?
If the problem persists, can you share a basic repro?
Knowing your NodeJS version can help 🙋🏻♂️