Skip to content

justindstein/sql-minify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐚 SQL Minify β€” Bash/Perl One-Liner for Compact SQL

A blazing-fast, dependency-free SQL minify for the command line. Removes comments and collapses whitespace so your SQL is ready for logs, APIs, or inline embedding.


✨ Features

  • βœ… Removes -- style comments (outside of quotes)
  • βœ… Collapses all whitespace (tabs, newlines, spaces) into a single space
  • βœ… Preserves quoted strings (', ", `)
  • βœ… Outputs minified SQL as a single line
  • βœ… Native support on any machine with Bash + Perl (no external dependencies!)

πŸ†š Why This Tool?

Most SQL minification tools:

  • ❌ Require installing Node.js, Python packages, or NPM libraries
  • ❌ Aren't optimized for CLI usage or piping workflows
  • ❌ Ignore SQL quoting edge cases (e.g. comment symbols inside strings)

This tool is:

  • πŸ”§ 100% shell-native (just Bash and Perl)
  • πŸͺΆ Lightweight β€” under 10 lines of Perl
  • 🧠 Intelligent β€” skips -- comments unless inside quotes
  • πŸš€ Ideal for scripting, CI/CD logs, and API payloads

πŸ’» Usage

πŸ—ƒοΈ From SQL file

./minify-sql.sh path/to/query.sql > output.sql

πŸ“₯ From pipe

cat path/to/query.sql | ./minify-sql.sh

Or:

echo "SELECT * FROM users -- fetch all" | ./minify-sql.sh

πŸ§ͺ Requirements

  • bash
  • perl (standard on macOS, most Linux distributions, WSL, and Git Bash for Windows)

🧩 Alternatives?

There are currently no open source CLI tools dedicated to SQL minification.

  • JS-based tools exist in browser environments or for bundlers
  • Database tools sometimes offer formatting, but rarely minification
  • Regex hacks fail on real-world SQL with comments inside strings

This tool fills that gap for developers and ops engineers who just want clean, reliable SQL output.


πŸ€– Authorship & AI Credit

This project was written 100% using AI, specifically ChatGPT by OpenAI. It was designed, debugged, and documented with zero human coding beyond execution and copy/paste.

If you’re impressed, thank ChatGPT!


πŸ”“ License

MIT β€” free to use, copy, and share.

About

Minifies SQL by removing comments and unnecessary whitespace.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages