Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SqlString = require('mysql/lib/protocol/SqlString.js');
- module.exports = escape;
- function escape(query, values) {
- if (!values) { return query; }
- [
- {regex: /\:\:(\w+)/g, esc: SqlString.escapeId},
- {regex: /\:(\w+)/g, esc: SqlString.escape}
- ].forEach(function(opt) {
- query = query.replace(opt.regex, function(txt, key) {
- if (values.hasOwnProperty(key)) {
- return opt.esc(values[key]);
- }
- return txt;
- });
- });
- return query;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement