你可以用
mysql2
支持该格式的包:
Named placeholders
namedPlaceholders配置值或查询/执行时间选项。命名
占位符是否转换为未命名?在客户端(mysql协议)上
不支持命名参数)。如果引用参数
时代。
connection.config.namedPlaceholders = true;
connection.execute('select :x + :y as z', {x: 1, y: 2}, function (err, rows) {
// statement prepared as "select ? + ? as z" and executed with [1,2] values
// rows returned: [ { z: 3 } ]
});
connection.execute('select :x + :x as z', {x: 1}, function (err, rows) {
// select ? + ? as z, execute with [1, 1]
});
connection.query('select :x + :x as z', {x: 1}, function (err, rows) {
// query select 1 + 1 as z
});