Skip to content

Instantly share code, notes, and snippets.

@alejandro
Created June 25, 2012 17:26
Show Gist options
  • Select an option

  • Save alejandro/2990018 to your computer and use it in GitHub Desktop.

Select an option

Save alejandro/2990018 to your computer and use it in GitHub Desktop.
var bind = function (str, vars) {
return str.replace(/(^|[^\\])\:(\w*)/g, function (v, w, x) {
return w + vars[x]
})
}
var query = bind('INSERT INTO table1 SER field1 = :field1, field2 = :field2 ON DUPLICATE KEY UPDATE field2 = :field2', {field1: 1, field2: 2}))
conn.query(query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment