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
- Split Large SQL Files: Break down massive SQL dumps into manageable, per-statement files
- SQL Reformatting: Pretty-print SQL with consistent formatting
- Syntax-Aware Grep: Search SQL files with understanding of SQL structure
- Table Name Replacement: Safely rename tables throughout your SQL files
- Add TRUNCATE/DROP Commands: Automatically generate table management statements
- Multi-Dialect Support: Works with 20+ database dialects via sqlglot
- Fast Processing: Efficient handling of large SQL files with progress indicators
Installation
Via pip (Recommended)
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:
- Review individual statements
- Version control specific changes
- Debug problematic queries
- Selectively apply statements
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:
- MySQL
- PostgreSQL
- SQLite
- Oracle
- SQL Server
- BigQuery
- Snowflake
- Redshift
- Presto
- Spark SQL
- And many more!
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
- Python 3.x
- sqlglot
- tqdm (for progress bars)
Philosophy
SQLAxe is built on principles of:
- Syntax Awareness: Understand SQL structure, donβt just treat it as text
- Reliability: Handle edge cases and malformed SQL gracefully
- Usability: Simple commands for common SQL file operations
- Performance: Process large files efficiently
Development
Testing
python -m pytest
Dependencies
SQLAxe uses:
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature
) - Make your changes
- Ensure tests pass (
pytest
) - Commit your changes
- Push to your fork
- Open a pull request
Commercial Support
Commercial support is available from Durable Programming, LLC. Contact us at [email protected] for:
- Custom features
- Priority bug fixes
- Integration assistance
- Training and consulting
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