This extension was primarily built out of a very specific, niche scenario in my latest co-op. It provides two tools:
Formatter for SQL queries embedded within Python Files for SQL queries embedded within Python Files
Syntax Highlighting
Formatter:
Syntax Highlighter Before:
Syntax Highlighter After:
The utilty of this comes with the fact that SQL errors can be caught immediately instead of run-time:
How To Use
Within Python files, this extension uses a TextMate grammar selector that detects embedded SQL as follows:
.execute(""" begins a SQL code block, and """ is what ends it - everything in between will be rendered as SQL instead of a raw Python string.
There's also a built in selector-based formatter for Python embedded SQL, called Format Embedded SQL in Python
NOTE: The formatter is specially designed to handle SQL queries with placeholder values ?, in addition to {}
NOTE: To format these embedded SQL queries, you need to select the text within your editor, and then open the command palette (CMD + shift + P) and run the Format Embedded SQL command.
Requirements
Everything should work out of the box. Note that this extension will install the npm package sql-formatter