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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9557199079511cec5188c694dd32e2d114aaedebb896b90dc4ebe9e95308f116
4
- data.tar.gz: da7fe2c4ff35032c6908a8ea10b5e8c4482cb607a78ac3c241b7d4f2093bbc88
3
+ metadata.gz: a1cd21cc5cba64d3579b6d403693f139a96c958d3d5676a885745dee86ca4cb8
4
+ data.tar.gz: 03f72e555878220eed0b09646c262e1b70efd678b55fb130d83f8b17d0dcc149
5
5
  SHA512:
6
- metadata.gz: d363570c1c0add348461b8b9069eb4f7075036140f6c7b86f03130c88903f5fcf17613123841a28ca28b55eeb6b3f16905572017222904a58595586dbb782134
7
- data.tar.gz: da33c33ada19314d1421d7a1cab384b9f6fa25b456909f2086b662bf8c235089443a8513b95049bbebe7db70d4535d32cefec664de3927a0d5ca7a0f9da10c87
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
- return "\n#{Util.keyword_padding('where')}#{@where_clause.strip}" if conditions.length <= 1 && conditions.first&.leaf?
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
- formatted_conditions = Condition.render_all(conditions, indent_width: keyword_column_width)
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
@@ -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
- return default_base_indent unless line_before_subquery.lstrip.match?(CLAUSE_KEYWORD_PREFIX_PATTERN)
93
+ clause_body_position = line_leading_spaces + keyword_column_width
92
94
 
93
- default_base_indent + line_leading_spaces + SqlBeautifier.config_for(:keyword_column_width)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SqlBeautifier
4
- VERSION = "0.10.0"
4
+ VERSION = "0.10.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_beautifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kinnell Shah