@sequeljs/ast
Version:
A SQL AST manager for JavaScript
32 lines • 1 kB
JavaScript
import SQLString from '../collectors/SQLString';
import EngineNotSetError from '../errors/EngineNotSetError';
import VisitorNotSetError from '../errors/VisitorNotSetError';
import SequelAST from '../SequelAST';
class TreeManager {
constructor(ast) {
this.ctx = null;
this.ast = ast;
}
toSQL(engine = undefined) {
let currentEngine = engine;
if (typeof currentEngine === 'undefined') {
currentEngine = SequelAST.engine;
}
if (!currentEngine) {
throw new EngineNotSetError();
}
if (!currentEngine.connection.visitor) {
throw new VisitorNotSetError();
}
let collector;
collector = new SQLString();
collector = currentEngine.connection.visitor.accept(this.ast, collector);
return collector.value;
}
where(expr) {
this.ctx.wheres.push(expr);
return this;
}
}
export default TreeManager;
//# sourceMappingURL=TreeManager.js.map