Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>SQL in Python Highlighter/FormatterNew to Visual Studio Code? Get it now.

SQL in Python Highlighter/Formatter

jerrdeh

|
19 installs
| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

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 embedded within Python Files for SQL queries 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

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft