Skip to content

jerryzhou196/sql-embed-in-python

Repository files navigation

SQL Embed in Python

Features

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

Formatter:

Syntax Highlighter Before:

image

Syntax Highlighter After:

image

The utilty of this comes with the fact that SQL errors can be caught immediately instead of run-time:


image

How To Use

  1. 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.

  2. 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

Release Notes

1.0.0 - Intial Implementation