mybatis-mapper
mybatis-mapper copied to clipboard
Can you add a suffix in TRIM tag?
some tools generate mybatis template sql like this: <trim prefix="values (" suffix=")" suffixOverrides=","> So I need to add suffix and suffixOverrides in TRIM tag, I already changed code in my machine, and it run smoothly. can you update this code?
var convertTrimWhere = function(children, param, namespace, myBatisMapper) {
var convertString = '';
var prefix = null;
var prefixOverrides = null;
var suffix = null;
var suffixOverrides = null;
var globalSet = null;
try{
switch (children.name.toLowerCase()) {
case 'trim':
prefix = children.attrs.prefix;
prefixOverrides = children.attrs.prefixOverrides;
suffix = children.attrs.suffix;
suffixOverrides = children.attrs.suffixOverrides;
globalSet = 'g';
break;
case 'where':
prefix = 'WHERE';
prefixOverrides = 'and|or';
globalSet = 'gi';
break;
default:
throw new Error("Error occurred during convert <trim/where> element.");
}
// Convert children first.
for (var j=0, nextChildren; nextChildren=children.children[j]; j++){
convertString += convertChildren(nextChildren, param, namespace, myBatisMapper);
}
// Remove prefixOverrides
var trimRegex = new RegExp('(^)([\\s]*?)(' + prefixOverrides + ')', globalSet);
convertString = convertString.replace(trimRegex, '');
// Remove suffixOverrides
trimRegex = new RegExp('(' + suffixOverrides + ')([\\s]*?)($)', globalSet);
convertString = convertString.replace(trimRegex, '');
if (children.name.toLowerCase() != 'trim'){
var trimRegex = new RegExp('(' + prefixOverrides + ')([\\s]*?)($)', globalSet);
convertString = convertString.replace(trimRegex, '');
}
// Add Prefix if String is not empty.
var trimRegex = new RegExp('([a-zA-Z])', 'g');
var w = convertString.match(trimRegex);
if (w != null && w.length > 0) {
convertString = prefix + ' '+ convertString + ' ' + suffix;
}
// Remove comma(,) before WHERE
if (children.name.toLowerCase() != 'where'){
var regex = new RegExp('(,)([\\s]*?)(where)', 'gi');
convertString = convertString.replace(regex, ' WHERE ');
}
return convertString;
} catch (err) {
throw new Error("Error occurred during convert <" + children.name.toLowerCase() + "> element.");
}
}
hi, could you please make a Pull request for this?
I created a pull request. #23
can you merge the pull request #23