INSERT INTO fails with node-mysql

Pay attention to the documentation of node-mysql: If you paid attention, you may have noticed that this escaping allows you to do neat things like this: var post = {id: 1, title: ‘Hello MySQL’}; var query = connection.query(‘INSERT INTO posts SET ?’, post, function(err, result) { // Neat! }); console.log(query.sql); // INSERT INTO posts SET … Read more

Use promise to process MySQL return value in node.js

This is gonna be a little scattered, forgive me. First, assuming this code uses the mysql driver API correctly, here’s one way you could wrap it to work with a native promise: function getLastRecord(name) { return new Promise(function(resolve, reject) { // The Promise constructor should catch any errors thrown on // this tick. Alternately, try/catch … Read more