# sqlanalyzer-sdk-js

> SDK for SQLAnalyzer API

Latest version **1.0.9** (published 2022-07-27) · Apache License 2.0 license · 0 weekly downloads

## Install

```sh
npm install sqlanalyzer-sdk-js
pnpm add sqlanalyzer-sdk-js
yarn add sqlanalyzer-sdk-js
bun add sqlanalyzer-sdk-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2022-07-27 |
| First published | 2022-05-17 |
| Weekly downloads | 0 |
| License | Apache License 2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 125.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | vadim.mytarev |

## Links

- npm: https://www.npmjs.com/package/sqlanalyzer-sdk-js
- npm.io page: https://npm.io/package/sqlanalyzer-sdk-js

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.2.3

## Recent versions

- 1.0.9 (latest) — 2022-07-27
- 1.0.4 (beta) — 2022-05-18
- 1.0.8 — 2022-07-20
- 1.0.7 — 2022-05-26
- 1.0.6 — 2022-05-26
- 1.0.5 — 2022-05-18
- 1.0.0 — 2022-05-17

## README

# SQLParser-SDK-JS
Javascript/Typescript SDK to work with [SQL Parser API](https://sql.sonra.io/sql-formatter-visualiser/main)
## Installing

For the latest stable version:

```bash
npm i sqlanalyzer-sdk-js
```

## Usage
To convert JSON response from the API use the following:
```js
// 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.

```js
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:
```js
// 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...

---
_Source: https://npm.io/package/sqlanalyzer-sdk-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
