1.0.9 • Published 2 years ago

sqlanalyzer-sdk-js v1.0.9

Weekly downloads
-
License
Apache License 2....
Repository
-
Last release
2 years ago

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...

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago