sqlanalyzer-sdk-js
v1.0.9
Published
SDK for SQLAnalyzer API
Downloads
2
Readme
SQLParser-SDK-JS
Javascript/Typescript SDK to work with SQL Parser API
Installing
For the latest stable version:
npm i sqlanalyzer-sdk-js
Usage
To convert JSON response from the API use the following:
// jsonResponseFromApi - assuming this is JSON object, convert it to data objects
const response: ParSeQL = convert(jsonResponseFromApi);
Now you have dataclass objects tree and to easily walk over that tree you can leverage the Visitor interface and default implementation of BaseVisitor. As an example this package contains SDKVisitor which overrides 2 methods of the BaseVisitor class and gather information about tables used in the statement and every column.
export class SDKVisitor extends BaseVisitor {
table_list: Set<Ds> = new Set();
column_list: Set<Attr> = new Set();
visit_ds(param: Ds) {
super.visit_ds(param);
// Add REFERENCES of all dataset WITH TYPE table to table_names list
if (param.type == "table") {
this.table_list.add(param)
}
}
visit_attr(param: Attr) {
super.visit_attr(param);
this.column_list.add(param)
}
}
To use the visitor you can use the snippet below:
// initialize SDK visitor
const visitor = new SDKVisitor();
// run visitor over the data objects
response.accept(visitor)
// Get tables used in our statement, which was collected by visitor
console.log(visitor.table_list)
Documentation
TBD...
Contribute
TBD...