background

SQLAxe

License: MITPython

SQLAxe is a syntax-aware command-line tool for manipulating SQL files. Whether you need to split large SQL dumps, reformat messy queries, or search through SQL with dialect-aware parsing, SQLAxe has you covered.

Features

Installation

pip install sqlaxe

From GitHub

pip install git+https://github.com/djberube/sqlaxe

From Source

git clone https://github.com/djberube/sqlaxe.git
cd sqlaxe
pip install -e .

Usage

Split SQL Files

Break a large SQL file into individual statement files:

sqlaxe split sql_file.sql

This creates a directory with one file per SQL statement, making it easier to:

Pretty Print SQL

Reformat SQL for readability:

sqlaxe pp sql_file.sql

Outputs nicely formatted SQL with consistent indentation and style.

Search SQL Files

Grep through SQL files with syntax awareness:

sqlaxe grep sql_file.sql PATTERN

Unlike traditional grep, SQLAxe understands SQL structure and can search more intelligently.

Table Name Replacement

Rename tables throughout your SQL:

sqlaxe replace-table sql_file.sql old_table_name new_table_name

Add Table Management Commands

Generate TRUNCATE or DROP TABLE statements:

sqlaxe add-truncate sql_file.sql
sqlaxe add-drop sql_file.sql

Supported Database Dialects

SQLAxe supports 20+ database dialects through sqlglot, including:

Use Cases

Database Migration

Split large migration files to review and apply changes incrementally:

sqlaxe split production_migration.sql

SQL Debugging

Extract and format specific problematic queries:

sqlaxe pp messy_query.sql > formatted_query.sql

Code Review

Make SQL dumps readable for version control and review:

sqlaxe pp dump.sql > readable_dump.sql

Schema Management

Prepare database cleanup scripts:

sqlaxe add-drop schema.sql

Development

Standardize SQL formatting across your project:

find . -name "*.sql" -exec sqlaxe pp {} \;

Requirements

Philosophy

SQLAxe is built on principles of:

Development

Testing

python -m pytest

Dependencies

SQLAxe uses:

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Make your changes
  4. Ensure tests pass (pytest)
  5. Commit your changes
  6. Push to your fork
  7. Open a pull request

Commercial Support

Commercial support is available from Durable Programming, LLC. Contact us at [email protected] for:

License

MIT License - see LICENSE.md for details.

Support

For bugs, feature requests, or questions, please open an issue on GitHub.

GitHub

⭐ 8 stars | πŸ“… Created June 2024 | πŸ”„ Updated 2024

View on GitHub