Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/purcell/sqlformat
Reformat SQL code inside Emacs using sqlformat or pgformatter
https://github.com/purcell/sqlformat
Last synced: about 2 months ago
JSON representation
Reformat SQL code inside Emacs using sqlformat or pgformatter
- Host: GitHub
- URL: https://github.com/purcell/sqlformat
- Owner: purcell
- Created: 2018-10-19T02:02:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-06T20:27:18.000Z (3 months ago)
- Last Synced: 2024-11-06T21:29:46.394Z (3 months ago)
- Language: Emacs Lisp
- Size: 31.3 KB
- Stars: 110
- Watchers: 3
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
[![Melpa Status](http://melpa.org/packages/sqlformat-badge.svg)](http://melpa.org/#/sqlformat)
[![Melpa Stable Status](http://stable.melpa.org/packages/sqlformat-badge.svg)](http://stable.melpa.org/#/sqlformat)
[![Build Status](https://github.com/purcell/sqlformat/actions/workflows/test.yml/badge.svg)](https://github.com/purcell/sqlformat/actions/workflows/test.yml)sqlformat.el
============This Emacs library provides commands and a minor mode for easily reformatting
SQL using any one of several popular SQL formatters (see Usage below for a list).Installation
=============If you choose not to use one of the convenient
packages in [MELPA][melpa], you'll need to
add the directory containing `sqlformat.el` to your `load-path`, and
then `(require 'sqlformat)`.Usage
=====To set your preferred formatter, customise the `sqlformat-command` variable or set it as a file/directory local variable.
The variable should be assigned one of the following symbol values:* [`sqlformat`][sqlformat]
* [`pgformatter`][pgformatter]
* [`sqlfluff`][sqlfluff]
* [`sql-formatter`][sql-formatter]
* [`sqlfmt`][sqlfmt]For example, to use [pgformatter][pgformatter] (i.e., the `pg_format` command) with
two-character indent and no statement grouping,``` el
(setq sqlformat-command 'pgformatter)
;; Optional additional args
(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:
```el
(add-hook 'sql-mode-hook 'sqlformat-on-save-mode)
```or locally to your project with a form in your .dir-locals.el like
this:```el
((sql-mode
(mode . sqlformat-on-save)))
```You might like to bind `sqlformat` or `sqlformat-buffer` to a key,
e.g. with:```el
(define-key sql-mode-map (kbd "C-c C-f") 'sqlformat)
```[melpa]: http://melpa.org
[sqlformat]: https://sqlformat.org/
[pgformatter]: https://github.com/darold/pgFormatter
[sqlfluff]: https://www.sqlfluff.com
[sql-formatter]: https://github.com/sql-formatter-org/sql-formatter
[sqlfmt]: https://docs.sqlfmt.com/
[💝 Support this project and my other Open Source work](https://www.patreon.com/sanityinc)
[💼 LinkedIn profile](https://uk.linkedin.com/in/stevepurcell)
[✍ sanityinc.com](http://www.sanityinc.com/)