sql_beautifier 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/sql_beautifier/delete_query.rb +2 -1
- data/lib/sql_beautifier/dml_rendering.rb +9 -4
- data/lib/sql_beautifier/query.rb +15 -3
- data/lib/sql_beautifier/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1cd21cc5cba64d3579b6d403693f139a96c958d3d5676a885745dee86ca4cb8
|
|
4
|
+
data.tar.gz: 03f72e555878220eed0b09646c262e1b70efd678b55fb130d83f8b17d0dcc149
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed584adbe928ae529abd6f3a67896f31d846064795a317e61a3f8074c59e20d27898c5e17e39b78f5d40b74e6e9c4a2bfd7aa99ec6a9cc6ab4ce7fcd776bc31a
|
|
7
|
+
data.tar.gz: 9bc2a921e9ba76d00e55fad61f5d34999267d926aed65069981fb3e81b215968c2e60f3958fbf8a67aa645ac13495573396d38f8249bc9871c2df3658ac6c418
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## [X.X.X] - YYYY-MM-DD
|
|
4
4
|
|
|
5
|
+
## [0.10.1] - 2026-03-30
|
|
6
|
+
|
|
7
|
+
- Fix nested subquery indentation growing excessively at each depth level — `subquery_base_indent_for` was adding the parent formatter's `depth` to the base indent calculation for subqueries on `from`/`where` lines, double-counting indentation that the parent's `format_as_subquery` would also apply; the method now computes base indentation relative to column 0 of the clause text
|
|
8
|
+
- Fix subqueries on non-clause continuation lines (e.g. `inner join lateral (select...)`) using the formatter depth instead of the line's leading spaces for base indentation, causing misaligned closing parentheses
|
|
9
|
+
- Fix subqueries in DML `WHERE` clauses (`DELETE`, `UPDATE`, `INSERT`) not being expanded — `DmlRendering#render_where` now applies `Query.format_subqueries_in_text` to the rendered WHERE output
|
|
10
|
+
- Fix subqueries in DELETE `USING` clauses not being expanded — `DeleteQuery#render_using` now applies `Query.format_subqueries_in_text`, and `using` is recognized as a clause keyword for subquery base indentation
|
|
11
|
+
|
|
5
12
|
## [0.10.0] - 2026-03-30
|
|
6
13
|
|
|
7
14
|
- Add CASE expression formatting — searched CASE (`CASE WHEN ... THEN ... ELSE ... END`) and simple CASE (`CASE expr WHEN value THEN ... END`) are detected and formatted with consistent indentation of `when`/`else`/`end` lines relative to the `case` keyword
|
|
@@ -118,7 +118,8 @@ module SqlBeautifier
|
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
def render_using
|
|
121
|
-
"\n#{Util.keyword_padding('using')}#{@using_clause}"
|
|
121
|
+
formatted_using_text = "\n#{Util.keyword_padding('using')}#{@using_clause}"
|
|
122
|
+
Query.format_subqueries_in_text(formatted_using_text, depth: @depth)
|
|
122
123
|
end
|
|
123
124
|
end
|
|
124
125
|
end
|
|
@@ -8,11 +8,16 @@ module SqlBeautifier
|
|
|
8
8
|
keyword_column_width = SqlBeautifier.config_for(:keyword_column_width)
|
|
9
9
|
conditions = Condition.parse_all(@where_clause)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
formatted_where_text = begin
|
|
12
|
+
if conditions.length <= 1 && conditions.first&.leaf?
|
|
13
|
+
"\n#{Util.keyword_padding('where')}#{@where_clause.strip}"
|
|
14
|
+
else
|
|
15
|
+
formatted_conditions = Condition.render_all(conditions, indent_width: keyword_column_width)
|
|
16
|
+
"\n#{formatted_conditions.sub(Util.continuation_padding, Util.keyword_padding('where'))}"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"\n#{formatted_conditions.sub(Util.continuation_padding, Util.keyword_padding('where'))}"
|
|
20
|
+
Query.format_subqueries_in_text(formatted_where_text, depth: @depth)
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
def render_returning
|
data/lib/sql_beautifier/query.rb
CHANGED
|
@@ -11,7 +11,7 @@ module SqlBeautifier
|
|
|
11
11
|
].freeze
|
|
12
12
|
|
|
13
13
|
LEADING_WHITESPACE_PATTERN = %r{\A[[:space:]]*}
|
|
14
|
-
CLAUSE_KEYWORD_PREFIX_PATTERN = %r{\A(?:where|from)(?:[[:space:]]|$)}i
|
|
14
|
+
CLAUSE_KEYWORD_PREFIX_PATTERN = %r{\A(?:where|from|using)(?:[[:space:]]|$)}i
|
|
15
15
|
|
|
16
16
|
attr_reader :clauses
|
|
17
17
|
attr_reader :depth
|
|
@@ -87,10 +87,22 @@ module SqlBeautifier
|
|
|
87
87
|
line_start_position = line_start_position ? line_start_position + 1 : 0
|
|
88
88
|
line_before_subquery = text[line_start_position...subquery_position]
|
|
89
89
|
line_leading_spaces = line_before_subquery[LEADING_WHITESPACE_PATTERN].to_s.length
|
|
90
|
+
keyword_column_width = SqlBeautifier.config_for(:keyword_column_width)
|
|
91
|
+
paren_position_on_line = subquery_position - line_start_position
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
clause_body_position = line_leading_spaces + keyword_column_width
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
if line_before_subquery.lstrip.match?(CLAUSE_KEYWORD_PREFIX_PATTERN)
|
|
96
|
+
if paren_position_on_line == clause_body_position
|
|
97
|
+
default_base_indent.zero? ? clause_body_position : line_leading_spaces
|
|
98
|
+
else
|
|
99
|
+
clause_body_position
|
|
100
|
+
end
|
|
101
|
+
elsif paren_position_on_line > line_leading_spaces
|
|
102
|
+
line_leading_spaces
|
|
103
|
+
else
|
|
104
|
+
default_base_indent
|
|
105
|
+
end
|
|
94
106
|
end
|
|
95
107
|
|
|
96
108
|
def self.select_follows?(text, position)
|