Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. var SqlString = require('mysql/lib/protocol/SqlString.js');
  2.  
  3. module.exports = escape;
  4.  
  5. function escape(query, values) {
  6. if (!values) { return query; }
  7. [
  8. {regex: /\:\:(\w+)/g, esc: SqlString.escapeId},
  9. {regex: /\:(\w+)/g, esc: SqlString.escape}
  10. ].forEach(function(opt) {
  11. query = query.replace(opt.regex, function(txt, key) {
  12. if (values.hasOwnProperty(key)) {
  13. return opt.esc(values[key]);
  14. }
  15. return txt;
  16. });
  17. });
  18. return query;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement