module SQLBeautifier
Extended Modules
Defined in:
sql_beautifier/sql_beautifier.crConstant Summary
-
BRACKETS =
"[\\(\\)]"
-
COMMENT_CONTENT =
/[\S]+[\s\S]*[\S]+/
-
INLINE_VERBS =
(["WITHASC", "IN", "COALESCE", "AS", "WHEN", "THEN", "ELSE", "END", "AND", "UNION", "ALL", "ON", "DISTINCT", "INTERSECT", "EXCEPT", "EXISTS", "NOT", "COUNT", "ROUND", "CAST"] of ::String).join("\\b|\\b")
-
NEW_LINE_VERBS =
"SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|(RIGHT |LEFT )*(INNER |OUTER )*JOIN( LATERAL)*|HAVING|OFFSET|UPDATE"
-
POSSIBLE_INLINER =
/(ORDER BY|CASE)/
-
SQL_COMMENTS =
/(\s*?--.+\s*)|(\s*?\/\*[^\/\*]*\*\/\s*)/
-
STRINGS =
/("[^"]+")|('[^']+')/
-
VERBS =
"#{NEW_LINE_VERBS}|#{INLINE_VERBS}"
Instance Method Summary
-
#beautify(sql : String, indentation_base = 2, open_bracket_is_newliner = false) : String
This code is basically a stripped port of https://github.com/alekseyl/niceql.
Instance Method Detail
This code is basically a stripped port of https://github.com/alekseyl/niceql. Some pieces of code were removed to simplify it, some were changed to support queries in lower case, the code removals injected some minor bugs, but this is ok while we don't have a SQL parser to do the job.