All Projects → purcell → sqlformat

purcell / sqlformat

Licence: other
Reformat SQL code inside Emacs using sqlformat or pgformatter

Programming Languages

emacs lisp
2029 projects
Makefile
30231 projects

Melpa Status Melpa Stable Status Build Status Support me

sqlformat.el

This Emacs library provides commands and a minor mode for easily reformatting SQL using external programs such as sqlformat, sqlfluff or pg_format.

Installation

If you choose not to use one of the convenient packages in MELPA, you'll need to add the directory containing sqlformat.el to your load-path, and then (require 'sqlformat).

Usage

Customise the sqlformat-command variable as desired. For example, to use pgformatter (i.e., the pg_format command) with two-character indent and no statement grouping,

(setq sqlformat-command 'pgformatter)
(setq sqlformat-args '("-s2" "-g"))

Then call sqlformat, sqlformat-buffer or sqlformat-region as convenient.

Enable sqlformat-on-save-mode in SQL buffers like this:

(add-hook 'sql-mode-hook 'sqlformat-on-save-mode)

or locally to your project with a form in your .dir-locals.el like this:

((sql-mode
   (mode . sqlformat-on-save)))

You might like to bind sqlformat or sqlformat-buffer to a key, e.g. with:

(define-key sql-mode-map (kbd "C-c C-f") 'sqlformat)

Install the sqlparse (Python) package to get "sqlformat", or pgformatter to get "pg_format"


💝 Support this project and my other Open Source work

💼 LinkedIn profile

sanityinc.com

🐦 @sanityinc

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].