# plsql-to-ast

> PL/SQL Parser that just works

Latest version **1.1.1** (published 2023-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install plsql-to-ast
pnpm add plsql-to-ast
yarn add plsql-to-ast
bun add plsql-to-ast
```

## Health

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

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

Warnings: low downloads; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2023-08-22 |
| First published | 2023-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 10.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Dono da Internet |
| Maintainers | donodainternet |
| Keywords | plsql, mariadb, parser, antlr4 |

## Links

- npm: https://www.npmjs.com/package/plsql-to-ast
- Repository: https://github.com/donodainternet/plsql-parser
- Homepage: https://github.com/donodainternet/plsql-parser#readme
- Issues: https://github.com/donodainternet/plsql-parser/issues
- npm.io page: https://npm.io/package/plsql-to-ast

## Dependencies (4)

- [yargs](https://npm.io/package/yargs.md) ^17.7.2
- [antlr4](https://npm.io/package/antlr4.md) ^4.9.0
- [antlr4ts](https://npm.io/package/antlr4ts.md) ^0.5.0-alpha.4
- [@types/antlr4](https://npm.io/package/@types/antlr4.md) ^4.9.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2023-08-22
- 1.1.0 — 2023-08-22
- 1.0.0 — 2023-08-22

## README

# plsql-to-ast: Parse PL/SQL Code to JSON

plsql-to-ast is a powerful tool for parsing complex PL/SQL code and extracting its Abstract Syntax Tree (AST) into a structured JSON format. It's designed to handle various PL/SQL code constructs, including stored procedures, triggers, and functions, making it a versatile solution for analyzing and manipulating PL/SQL codebases.

## Features

- Parse PL/SQL code and generate structured JSON representation of the AST.
- Handle complex PL/SQL constructs like loops, conditionals, function calls, and more.
- Option to display errors in the console.
- Easily integrated into projects through npm installation or command-line usage.

## Installation

To install the plsql-to-ast module via npm, use the following command:

```bash
npm install plsql-to-ast
```

## Command-Line Usage

plsql-to-ast can be used via the command line to generate JSON output for a provided PL/SQL file. The following options are available:
```bash
# Provide a PL/SQL file to generate abstraction (required)
node dist/plsql-to-ast-script.js --sql-file=path/to/your/sql/file.sql
```
Options:
```bash
-f, --sql-file: Provide a PL/SQL file to generate abstraction (required).
-e, --show-errors: Display errors in the console (boolean, default: false).
--help: Display help information.
```

## Module Usage

You can also use plsql-to-ast as a module in your TypeScript project:
```javascript
import { getASTAsJSON } from "plsql-to-ast";

const query = 'SELECT * FROM \`employees\`;';
const jsonOutput = getASTAsJSON(query);
```

## Examples
<div style="display: flex;">
  <div style="flex: 50%; overflow: auto; padding: 10px; border: 1px solid #ccc;">
    <pre>
CREATE PROCEDURE `complex_procedure`()
BEGIN
    DECLARE `var1` INT;
    DECLARE `var2` INT;
    DECLARE `total_records` INT;
    DECLARE `avg_value` FLOAT;
    
    SET `var1` = 0;
    SET `var2` = 0;
    
    WHILE `var1` < 10 DO
        SET `var2` = 0;
        WHILE `var2` < 5 DO
            INSERT INTO `example_table` (`column1`, `column2`)
            VALUES (`var1`, `var2`);
            
            SET `var2` = `var2` + 1;
        END WHILE;
        
        SET `var1` = `var1` + 1;
    END WHILE;
    
    SET `total_records` = `get_total_records`();
    
    SET `avg_value` = `calculate_average_value`(`example_table`.`column2`);
    
    INSERT INTO `summary_table` (`total_records`, `avg_value`)
    VALUES (`total_records`, `avg_value`);
    
    SELECT * FROM `summary_table`;
END
    </pre>
  </div>
  <div style="flex: 50%; overflow: auto; padding: 10px; border: 1px solid #ccc;">
    <pre>
{
  "data": {
    "children": [
      {
        "symbol": "CREATE",
        "context": "CreateProcedureContext"
      },
      {
        "symbol": "PROCEDURE",
        "context": "CreateProcedureContext"
      },
      {
        "symbol": "`complex_procedure`",
        "context": "FullIdContext"
      },
      {
        "symbol": "(",
        "context": "CreateProcedureContext"
      },
      {
        "symbol": ")",
        "context": "CreateProcedureContext"
      },
      {
        "children": [
          {
            "symbol": "BEGIN",
            "context": "BlockStatementContext"
          },
          {
            "children": [
              {
                "symbol": "DECLARE",
                "context": "DeclareVariableContext"
              },
              {
                "symbol": "`var1`",
                "context": "UidListContext"
              },
              {
                "symbol": "INT",
                "context": "DimensionDataTypeContext"
              }
            ]
      ...
    </pre>
  </div>
</div>
Please explore the `plsql-examples` directory for additional test cases and examples to see how plsql-to-ast handles various PL/SQL scenarios.

## Contributions and Feedback

Contributions to the project are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue.

## Thanks

Thank you for considering plsql-to-ast for your PL/SQL parsing needs. We hope this tool proves valuable in your development and analysis workflows. Happy coding!

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