Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL autoformatting in codeMirror

I'm trying to "beautify" sql code in codeMirror .

Autoformatting in not supported in codeMirror since v2 (current version is v4)

I've tried to use the old module formatting.js with autoFormatRange function ( the previous question on StackOverflow here). It doesn't seem to work properly with SQL. It makes indentation without any linebreaks

Did anyone figure out how to get this feature working on codeMirror v4 with SQL?

like image 591
Bruno Avatar asked May 19 '17 09:05

Bruno


People also ask

How do I format a SQL script?

1. In a SQL document, right-click the SQL script, click Active Format Profile, and select the required format. 2. To apply the selected format profile, select the SQL document or the fragment of the code and press Ctrl+K, then Ctrl+F.

What is SQL Formatter?

The SQL Formatter is used with the purpose to beautify the SQL statements. It formats the code automatically and its working is based on simple algorithms. It formats the code based on easy rules and helps to write fancy SQL code.


1 Answers

I've solved the problem using this js auto-formatter : https://github.com/zeroturnaround/sql-formatter

It does an excellent job at formatting SQL (demo here)

like image 85
Bruno Avatar answered Oct 09 '22 20:10

Bruno