plsql-to-ast
v1.1.1
Published
PL/SQL Parser that just works
Downloads
13
Maintainers
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:
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:
# 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:
-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:
import { getASTAsJSON } from "plsql-to-ast";
const query = 'SELECT * FROM \`employees\`;';
const jsonOutput = getASTAsJSON(query);
Examples
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
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!