rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
36 lines • 1.41 kB
JavaScript
/**
* This decorator formats parameter tokens according to DBMS-specific rules.
* It supports prefix/suffix, and parameter style (named, indexed, anonymous).
*/
export class ParameterDecorator {
constructor(options) {
var _a, _b, _c;
this.prefix = (_a = options === null || options === void 0 ? void 0 : options.prefix) !== null && _a !== void 0 ? _a : ':';
this.suffix = (_b = options === null || options === void 0 ? void 0 : options.suffix) !== null && _b !== void 0 ? _b : '';
this.style = (_c = options === null || options === void 0 ? void 0 : options.style) !== null && _c !== void 0 ? _c : 'named';
}
/**
* Decorate a parameter token with DBMS-specific format.
* @param token The parameter token
* @param index The parameter index (for indexed/anonymous)
*/
decorate(text, index) {
let paramText = '';
if (this.style === 'anonymous') {
// e.g. ?
paramText = this.prefix;
}
else if (this.style === 'indexed') {
// e.g. $1, ?1, :1
paramText = this.prefix + index;
}
else if (this.style === 'named') {
// e.g. :name, @name, ${name}
paramText = this.prefix + text + this.suffix;
}
// override
text = paramText;
return text;
}
}
//# sourceMappingURL=ParameterDecorator.js.map