#sql-query #sql #query #toolkit #insight #cli-interface

app sql-insight-cli

A CLI toolkit for SQL query analysis, formatting, and transformation

2 releases

0.1.1 Feb 12, 2024
0.1.0 Feb 12, 2024

#10 in #insight

Download history 31/week @ 2024-02-09 25/week @ 2024-02-16 19/week @ 2024-02-23 6/week @ 2024-03-01 2/week @ 2024-03-08 1/week @ 2024-03-15 136/week @ 2024-03-22 20/week @ 2024-03-29

159 downloads per month

MIT license

94KB
2K SLoC

sql-insight-cli

A command-line interface built on top of the sql-insight. It provides a set of commands that sql-insight supports.

Crates.io Rust codecov License: MIT

Features

  • SQL Formatting: Format SQL queries to standardized form, improving readability and maintainability.
  • SQL Normalization: Convert SQL queries into a normalized form, making them easier to analyze and process.
  • Table Extraction: Extract tables referenced in SQL queries, clarifying the data sources involved.
  • CRUD Table Extraction: Identify the create, read, update, and delete operations, along with the tables involved in each operation within SQL queries.

Additional Features:

  • File and Interactive Mode Support: Process SQL queries directly from files or via an interactive CLI session.

Installation

Install sql-insight-cli using Cargo:

cargo install sql-insight-cli

Usage

sql-insight-cli supports the following commands. Commands can process input directly from the command line, from a file using the --file option, or interactively.

General Options

  • --file <path>: Read SQL queries from the specified file instead of command line arguments.
  • interactive mode: Launch an interactive CLI session to input SQL queries. Enter this mode by running the command without a SQL argument nor --file option. To exit, type exit, quit or press Ctrl + C.

Formatting SQL

Format SQL queries to a standardized style:

sql-insight format "SELECT *  \n FROM users         WHERE id = 1;"

This outputs:

SELECT * FROM users WHERE id = 1

Normalizing SQL

Normalize SQL queries, abstracting values to placeholders:

sql-insight normalize "SELECT *  \n FROM users         WHERE id = 1;"

This outputs:

SELECT * FROM users WHERE id = ?

Table Extraction

Identify tables involved in SQL queries:

sql-insight extract-tables "SELECT * FROM catalog.schema.users as users_alias"

This outputs:

catalog.schema.users AS users_alias

CRUD Table Extraction

Extract and identify CRUD operations and involved tables:

sql-insight extract-crud "INSERT INTO users (name) SELECT name FROM employees"

This outputs:

Create: [users], Read: [employees], Update: [], Delete: []

Supported SQL Dialects

sql-insight-cli leverages sqlparser-rs for parsing, supporting a wide range of SQL dialects. For a detailed list, please refer to the sqlparser-rs documentation.

Contributing

Contributions to sql-insight-cli are welcome! Whether it's adding new features, fixing bugs, or improving documentation, feel free to fork the repository and submit a pull request.

License

sql-insight-cli is licensed under the MIT License.

Dependencies

~3MB
~59K SLoC