Giter Club home page Giter Club logo

sqlbeautifier's People

Contributors

smanolloff avatar svandragt avatar zsong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlbeautifier's Issues

Autoformat on save

Options to "autoformat on save", similar to settings as seen in prettier (or JsPrettier for Sublime Text 3) would be useful. Shown below is a snippet copied from JsPrettier.sublime-settings:

	// Whether or not to automatically format the file on save.
	// ----------------------------------------------------------------------

	"auto_format_on_save": false,

	// ----------------------------------------------------------------------
	// Auto Format on Save Excludes
	// ----------------------------------------------------------------------
	//
	// @param {array} "auto_format_on_save_excludes"
	// @default []
	//
	// Ignore auto formatting when the target file, or its path resides in a
	// particular location, and when `auto_format_on_save` is turned on.
	//
	// Example:
	//
	//     "auto_format_on_save_excludes": [
	//         "*/node_modules/*",
	//         "*/file.js",
	//         "*.json"
	//     ]

Enhancement: convert lists into new indents

It's easier to demonstrate with an example, instead of the current formatting like below

SELECT col2,
if(y IN ('a', 'b', 'c'), 1, 0) AS col2
FROM TABLE_NAME

I wonder if the list 'a', 'b', 'c' could be aligned like

SELECT col2,
if(y IN (
'a',
'b',
'c'
), 1, 0) AS col2
FROM TABLE_NAME

Add a Context.sublime-menu file

As the issue #3, may I suggest you to add a Context.sublime-menu file to your plugin. This file controls the right-click menu on a file being edited. This will provide the ability to beautify the current file or selection without the obligation to use the keyboard shortcut.

Sample content tested with Sublime Text 3 Build 3126:

[
    { "caption": "-" },
    {
        "caption": "SQL Beautifier",
        "command": "sql_beautifier"
    },
    { "caption": "-" }
]

Note: I don't know if ST3 is able to display context menu depending on the selected syntax. This would be chic.

indentation bug

consider such a case

SELECT *
FROM
  (SELECT `problem`.`title` AS `title`,
          `problem`.`problem_id` AS `pid`,
          source AS source,
          author AS author,
          contest_problem.num AS pnum
   FROM `contest_problem`,
        `problem`)

when run the beautifier, it becomes:

SELECT *
FROM
  (SELECT `problem`.`title` AS `title`,
          `problem`.`problem_id` AS `pid`,
          SOURCE AS SOURCE,
                    author AS author,
                    contest_problem.num AS pnum
   FROM `contest_problem`,
        `problem`)

the source is changed to uppercase
and one more indentation was add to the line after the source

Not working on Sublime Text 3126

Not working on Sublime Text 3126

I just installed it, and run the command and nothing changed, and this popped up on the console.

Traceback (most recent call last):
  File "D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\sublime_plugin.py", line 818, in run_
    return self.run(edit)
  File "sqlbeautifier in D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Installed Packages\SqlBeautifier.sublime-package", line 50, in run
  File "sqlbeautifier in D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Installed Packages\SqlBeautifier.sublime-package", line 41, in replace_region_with_formatted_sql
  File "D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\sublime.py", line 823, in replace
    sublime_api.view_replace(self.view_id, edit.edit_token, r, text)
TypeError: String required

Feature Request: Configurable list of additional keywords

Very useful plugin, but a configurable list of additional keywords to fix-case etc. would be handy.

Currently the sqlparse list misses analytical functions (OVER etc) a quick fix to add those would remedy the problem to an extent. Still, a better solution would be to make a configurable list of additional keywords, for custom or platform-specific stored procedures, system schemas/tables and so on.

Is there an easy way to add a minifier?

I love this plugin, it works wonderfully. However it'd be nice to have a way to undo the beautification after I've made edits. Is that possible?

keywords: minify minifier unbeautify unbeautifier

Add a Default.sublime-commands file

Might I suggest that you add a Default.sublime-commands file to this package, so that its command shows up when you trigger Sublime's command palette (Ctrl-Shift-P on Windows/Linux, Cmd-Shift-P on Mac)

Like this one from a competing SQL formatter:

[
    {
        "caption": "FormatSQL: Format SQL statement",
        "command": "format_sql"
    }
]

For me, unless the command's in the palette, I completely forget that it exists.

change key binding

Is there a way to change key binding value? I've tried to add a new value at Preferences > Key Binding but this doesn't seems to work

Nice plugin though

Multi-value inserts get formatted awkwardly

This SQL fragment

INSERT INTO bla VALUES (1, 2), (3, 4), (5, 6);

gets formatted into this

INSERT INTO bla
VALUES (1,
        2), (3,
             4), (5,
                  6);

Instead I would expect something like:

INSERT INTO bla
VALUES 
    (1, 2),
    (3, 4),
    (5, 6)
;

No indent?

Sometimes code doesn't get indented at all.

For example, this valid Sql statement (MySql):

select *
from setup.trans_bases t
join setup.hier_bases_total b on b.azienda=t.azienda
and b.idhier_bases=t.idhier_bases_start
and year(b.fine_validita)=9999
join setup.hier_bases_total b1 on b1.azienda=t.azienda
and b1.idhier_bases=t.idhier_bases_end
and year(b1.fine_validita)=9999
where t.idtrans_anag=7;

..after SQL Beautifier, remains the same.

My user preferences:

{
    "keyword_case": "lower",
    "identifier_case": "lower",
    "strip_comments": false,
    "indent_tabs": false,
    "indent_width": 4,
    "reindent": true
}

Sublime Text 3, build 3083.

Thank you!

Support wrap_after option

Please add support for wrap_after.

If my sql has many params ('?' chars separated by comma), they will be formatted as ?, on each line.
Not very producting when having 100+ lines almost empty...

bug with "indent_tabs": true

Using these settings:
{ "indent_tabs": true, "indent_width": 1, "reindent": true }

The SQL code gets this nice format:

SELECT foo,
       bar AS BAR
FROM TABLE
WHERE stuff = stuff2
 AND other_stuff NOT IN ('TH',
                         'AN',
                         'KS')
 AND blah = bleh

But I want to use tabs instead of spaces, so now with plugin settings:
{ "indent_tabs": true, "indent_width": 1, "reindent": true }

The code gets formatted to (had to use an image):
example

I guess the problem is that the number of tabs used is the same number of the calculated spaces, is there any way to read the user's customized tab size to do the math?
Congratulations for the great plugin.

Enhancement Request #2

Just as previous guy mentioned, great plugin. Thanks for your hard work.
One enhancement request that I have is:
It would be nice to have a setting/option to pick which key words are to not be followed by anything (other than newline).

Note: xxxx replaces spaces (you can't use spaces or tabs in here for some strange reason

Current way:
SELECT A.COL1 AS COL1,
xxxxxxxxA.COL2 AS COL2,
xxxxxxxxB.COL3 AS COL3
FROM APPLES A
INNER JOIN BANANAS B ON A.SOLDTO=B.SOLDTO
WHERE A.SOLDTO = "Peter"

proposed setting/option:
"newLineAfterKeywords": [SELECT,FROM,WHERE]

New formatting:
SELECT
xxxxxxxA.COL1 AS COL1,
xxxxxxxA.COL2 AS COL2,
xxxxxxxB.COL3 AS COL3
FROM
xxxxxxxAPPLES A
INNER JOIN BANANAS B ON A.SOLDTO=B.SOLDTO
WHERE
xxxxxxxA.SOLDTO = "Peter"

bonus points given if you can format the FROM section as following:
FROM
xxxxxxxxxxxxxxxxxAPPLES A
INNER JOINxxxxxBANANAS B ONxxxxxxxxxxxxxxxxxxA.SOLDTO = B.SOLDTO
INNER JOINxxPINEAPPLES P ON A.SOMELONGCOLUMNNAME = P.COLUMN

basically have the table names right aligned and indented so that the "ON" is always in same position. and the same thing for "=" being in the same position

How to use it?

Not seen button in edit bar or any hotkey? After selecting the whole document, how exactly this plugin can be ran?

Enhancement request

Wonderful plugin! Would love to see two new config options. One to not split up values inside of an IN clause to new lines but instead just put a space between values.
for example
current method:
IN (1,
2,
3,
4)

option to disable this:
IN (1, 2, 3, 4)

The other requested option would be to indent AND criteria as part of an JOIN xx ON statement the same way that they are indented for WHERE clauses.
For example
current method:
JOIN xxx ON blah = blah
AND foo = foo
AND xyz = xyz

option enabled to indent:
JOIN xxx ON blah = blah
AND foo = foo
AND xyz = xyz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.