Skip to content

future-architect/uroborosql-fmt

Repository files navigation

uroboroSQL-fmt

logo

demo

uroboroSQL-fmt is a tool that formats SQL statements according to SQL coding standards created by Future Corporation (Japanese only).

It instantly converts indentation, line breaks, and case distinctions in SQL statements to improve readability and manageability.

Our previous tool, uroboroSQL formatter, was made in python and used lexical analysis to format.

Tools based on lexical analysis had difficulty in processing parentheses, etc., and because it was made in Python, it was difficult to make it a VSCode extension.

Therefore, we have created this tool made in Rust, which formats using parsing.

The main features:

  • Written in Rust.

  • Only PostgreSQL is supported.

    • However, not all PostgreSQL syntax is supported.
  • Supports 2way-sql such as uroboroSQL and doma2.

  • Some Auto Fix functions are available.

  • All indentation is done in tabs.

  • Leading comma style, not a trailing comma style.

     SELECT
     	A	AS	A
     ,	B	AS	B
     ,	C	AS	C
  • VSCode extension is available.

  • You can try the demo by wasm (Japanese).

wasm_demo

Install

Please install Rust before installing.

cargo install --git https://github.com/future-architect/uroborosql-fmt

Usage

Command line output

uroborosql-fmt-cli input.sql

The formatting result of input.sql will output to the command line.

File output

uroborosql-fmt-cli input.sql result.sql

The formatting result of input.sql will output to result.sql.

Configuration options

Create .uroborosqlfmtrc.json in the directory where you run the command and write the configuration there.

If there is no configuration file, the default values are used.

name type description default
debug bool Run in debug mode. false
tab_size int Tab size used for formatting. 4
complement_alias bool Complement aliases. Currently, column names are auto-completed with the same name. (e.g. COL1COL1 AS COL1) true
trim_bind_param bool Trim the contents of the bind parameters. (e.g. /* foo *//*foo*/) false
keyword_case ["upper", "lower", "preserve"] Unify the case of keywords. (No conversion in case of "preserve") lower
identifier_case ["upper", "lower", "preserve"] Unify the case of identifiers. (No conversion in case of "preserve") lower
max_char_per_line int If the total number of characters in the function name and arguments exceeds max_char_per_line, the arguments are formatted with new lines. 50
complement_outer_keyword bool Complement the optional OUTER. (e.g. LEFT JOINLEFT OUTER JOIN) true
complement_column_as_keyword bool Complement AS in column aliases. true
remove_table_as_keyword bool Remove AS in table aliases. true
remove_redundant_nest bool Remove redundant parentheses. (e.g. (((foo)))(foo)) true
complement_sql_id bool Complement SQL ID. false
convert_double_colon_cast bool Convert casts by X::type to the form CAST(X AS type). true
unify_not_equal bool Convert comparison operator <> to != true

Structure

License

Business Source License 1.1