Git Product home page Git Product logo

sublime-uroborosql-formatter's Introduction

Sublime uroboroSQL Formatter

Package Control

Sublime uroboroSQL Formatter is often used in enterprise systems, For formatting to a highly maintainable style even for very long SQL (1 K step or more) It is a plug-in of Sublime Text 3.

In particular, in countries where English is not their mother tongue, such as Japan, comments may be included in SELECT clauses. In that case, we will align the vertical position of the AS clause and the comment, pursuing the viewability which can be said as artistic anymore, This was developed to realize this automatically.

for Japanese, Readme.ja.md

In case of general formatter

SELECT MI.MAKER_CD AS ITEM_MAKER_CD -- maker code
,
       MI.BRAND_CD AS ITEM_BRAND_CD -- brand code
,
       MI.ITEM_CD AS ITEM_CD -- item code
,
       MI.CATEGORY AS ITEM_CATEGORY -- item category
FROM M_ITEM MI -- item master

WHERE 1 = 1
  AND MI.ARRIVAL_DATE = '2016-12-01' -- arrival date

In case of Sublime uroboroSQL Formatter

SELECT
    MI.MAKER_CD AS  ITEM_MAKER_CD   -- maker code
,   MI.BRAND_CD AS  ITEM_BRAND_CD   -- brand code
,   MI.ITEM_CD  AS  ITEM_CD         -- item code
,   MI.CATEGORY AS  ITEM_CATEGORY   -- item category
FROM
    M_ITEM  MI  -- item master
WHERE
    1               =   1
AND MI.ARRIVAL_DATE =   '2016-12-01'    -- arrival date

Features

  • Formatting by aligning the vertical position of AS and operator in SELECT clause, WHERE clause
  • Even if there is a comment at the end of each line, the format

How to Use

  • Select "SQL Format" from the Edit menu
  • Select "SQL Format" from the context menu on the editor
  • Select "uroboroSQL Formatter: Format SQL" from the command Palette
  • ctrl + cmd + f on OS X, or ctrl + alt + f on Windows

Settings

{
    "uf_tab_size": 4,
    "uf_translate_tabs_to_spaces": true,
    "uf_case": "upper", // "upper" or "lower" or "capitalize" or "nochange"
    "uf_reserved_case": "upper", // "upper" or "lower" or "capitalize" or "nochange"
    "uf_reserved_words":"SELECT, FROM, WHERE, CREATE", // Put commas to separate reserved words
    "uf_comment_syntax": "uroboroSQL", // "uroboroSQL" or "doma2"
    "uf_escapesequence_u005c": false,
    "uf_save_on_format": true,
    "uf_save_on_format_extensions": [".sql"]
}
  • uf_tab_size
    • Specify the tab size of the indent after formatting. We recommend 4.
  • uf_translate_tabs_to_spaces
    • Specify whether the indent after formatting is tab or space. It becomes a space by setting it to true.
  • uf_case
    • If you want to convert all words to a specific case, set "upper", "lower", "capitalize". If the "nochange" option is selected, the word cases will not be changed from the original.
  • uf_reserved_case
    • If you want to convert reserved words to a specific case, set "upper", "lower" or "capitalize". If the "nochange" option is selected, it will not change the cases of resered words and they will be changed based on the "uf_case" setting.
  • uf_reserved_words
    • If you want to convert only reserved words to a specific case, please input reserved words sepalated by a comma. (The input is not case sensitive. So you can input reserved words in any case.)
  • uf_comment_syntax
    • It specifies the comment syntax format.
    • You can specify the "uroboroSQL" or "doma2".
      • In the case of normal SQL, you can specify either.
  • uf_escapesequence_u005c
    • If you have specified the escape sequence with a backslash in the SQL to specify the true.
  • uf_save_on_format
    • Specify true when formatting automatically when saving files.
  • uf_save_on_format_extensions
    • Specify the extension of the file to be formatted in a list.

License

python-sqlparse library and this code are both on 2-clauses BSD


Copyright 2018 by Future Architect.

sublime-uroborosql-formatter's People

Contributors

mehmetkz61 avatar ota-meshi avatar shun7 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

Watchers

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

sublime-uroborosql-formatter's Issues

How do you change and/or disable the keybinding?

I can't figure out how you are supposed to change the key binding.

I have several formatters installed, and right now, it seems that this particular one has won somehow, and it seems to be applied when I press ctrl+alt+f no matter what the file type (C++ becomes really interesting when fed through the SQL formatter, incidentally).

How can I change (or preferably disable) the shortcut key?

Update sqlparse to last version 0.3.0

Pls update sqlparse:

#
# Copyright (C) 2009-2018 the sqlparse authors and contributors
# <see AUTHORS file>
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause

"""Parse SQL statements."""

# Setup namespace
from sqlparse import sql
from sqlparse import cli
from sqlparse import engine
from sqlparse import tokens
from sqlparse import filters
from sqlparse import formatter

from sqlparse.compat import text_type

__version__ = '0.3.0'

uppercase switch

Greetings, First of all, nice package.

The package option uf_uppercase (boolean) changes reserved words and tables/columns indifferently. In MySQL without lower_case_table_names set to 1 this breaks queries. Can you please be more open allowing:

  • uf_all_uppercase actual behavior
  • uf_reserved_case for reserved words
  • uf_tables_case for tables
  • uf_columns_case for columns
  • uf_reserved_words with a list of words to be considered in uf_reserved_case

Better handle for weird LIMIT param

Hi,

I have the following sql and the formatter would not reformat it
SELECT * FROM table DESC LIMIT ?,?

However, it will reformat the sql if I remove the "?,?" at the end like:
SELECT * FROM table DESC LIMIT

I know that ?,? is not a valid input for sql, but would you consider supporting this user case?

Thank You.

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.