SQL Embed in Python
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 (supported dialects: MySQL, PostgreSQL, MsSQL) embedded within Python Files
-
Syntax Highlighting
The utilty of this comes with the fact that SQL errors can be caught immediately instead of run-time:
-
Within
Python
files, this extension uses aTextMate
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.
Everything should work out of the box. Note that this extension will install the npm package sql-formatter
1.0.0 - Intial Implementation