rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
73 lines • 2.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SqlDialectConfiguration = exports.SqlComponent = void 0;
class SqlComponent {
constructor() {
// Legacy comment field for backward compatibility
// @deprecated Use positionedComments instead for better comment positioning
this.comments = null;
// New position-based comment system
this.positionedComments = null;
}
getKind() {
return this.constructor.kind;
}
accept(visitor) {
return visitor.visit(this);
}
toSqlString(formatter) {
return this.accept(formatter);
}
/**
* Add comments at a specific position
*/
addPositionedComments(position, comments) {
if (!comments || comments.length === 0)
return;
if (!this.positionedComments) {
this.positionedComments = [];
}
// Find existing positioned comment for this position
const existing = this.positionedComments.find(pc => pc.position === position);
if (existing) {
existing.comments.push(...comments);
}
else {
this.positionedComments.push({ position, comments: [...comments] });
}
}
/**
* Get comments for a specific position
*/
getPositionedComments(position) {
if (!this.positionedComments)
return [];
const positioned = this.positionedComments.find(pc => pc.position === position);
return positioned ? positioned.comments : [];
}
/**
* Get all positioned comments as a flat array in order (before, after)
*/
getAllPositionedComments() {
if (!this.positionedComments)
return [];
const result = [];
// Add 'before' comments first
const beforeComments = this.getPositionedComments('before');
result.push(...beforeComments);
// Add 'after' comments second
const afterComments = this.getPositionedComments('after');
result.push(...afterComments);
return result;
}
}
exports.SqlComponent = SqlComponent;
class SqlDialectConfiguration {
constructor() {
this.parameterSymbol = ":";
this.identifierEscape = { start: '"', end: '"' };
this.exportComment = "none";
}
}
exports.SqlDialectConfiguration = SqlDialectConfiguration;
//# sourceMappingURL=SqlComponent.js.map