niceql 0.6.0 → 0.6.2
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/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +23 -0
- data/.github/workflows/rubocop.yml +17 -0
- data/CHANGELOG.md +9 -0
- data/README.md +1 -5
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +42 -25
- data/niceql.gemspec +2 -2
- metadata +9 -7
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f62d4429294ec7ef47e564052b2f5707db818fbb38509bcfc77fdcdc4bb0351f
|
4
|
+
data.tar.gz: bfd07f10dc1b7bd99ce81e727eb3afb23bf34dc00fdf2ccf2fcfa9257cb26727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4985d9e128475c93ac6dced329409fc2c6c544de35e6216e723f7d3fbc5baf94584e375d5991fb707f219b57e6129f78d410be24866b1f8e91b79ba5d5f65df7
|
7
|
+
data.tar.gz: 7bd016c10244cb5cbb6197e6add3973c47471c7b59f539d0285ca6c5bff04e351df1fbf2c8f77ea2aff4854adca5ec47d6dd1c0666eaec15caf38a854b411a17
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "3.3", "3.4"]
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true # 'bundle install' and cache gems
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rake test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: RuboCop
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v3
|
11
|
+
- name: Set up Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 2.7
|
15
|
+
bundler-cache: true # 'bundle install' and cache
|
16
|
+
- name: Run RuboCop
|
17
|
+
run: bundle exec rubocop --parallel
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 0.6.2
|
2
|
+
* github CI added 3.2, 3.3, 3.4 to matrix
|
3
|
+
* fixed: https://github.com/alekseyl/niceql/issues/25
|
4
|
+
|
5
|
+
# 0.6.1
|
6
|
+
* github CI added ( PR: https://github.com/alekseyl/niceql/pull/22 many thnx to @petergoldstein )
|
7
|
+
* issue fixed https://github.com/alekseyl/niceql/issues/23
|
8
|
+
* dropped support for 2.4 ( transform_keys is missing, and I'm too lazy to backward reimplement it you can do PR if needed )
|
9
|
+
|
1
10
|
# 0.6.0
|
2
11
|
* Huge core-logic refactoring and simplification
|
3
12
|
* dollar signed literals/strings added
|
data/README.md
CHANGED
@@ -5,11 +5,7 @@
|
|
5
5
|
This is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby.
|
6
6
|
It can be used in an irb console without any dependencies ( run bin/console and look for examples ).
|
7
7
|
|
8
|
-
Any reasonable suggestions are welcome.
|
9
|
-
|
10
|
-
**Please pay attention: even though issue https://github.com/alekseyl/niceql/issues/16 is resolved
|
11
|
-
still potentially UPDATE or INSERT request might corrupt your data, please don't patch pg_adapter on production!**
|
12
|
-
|
8
|
+
Any reasonable suggestions are welcome.
|
13
9
|
|
14
10
|
## Before/After
|
15
11
|
### SQL prettifier:
|
data/lib/niceql/version.rb
CHANGED
data/lib/niceql.rb
CHANGED
@@ -6,24 +6,26 @@ require "forwardable"
|
|
6
6
|
|
7
7
|
module Niceql
|
8
8
|
module StringColorize
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
class << self
|
10
|
+
def colorize_keyword(str)
|
11
|
+
# yellow ANSI color
|
12
|
+
"\e[0;33;49m#{str}\e[0m"
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def colorize_str(str)
|
16
|
+
# cyan ANSI color
|
17
|
+
"\e[0;36;49m#{str}\e[0m"
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def colorize_err(err)
|
21
|
+
# red ANSI color
|
22
|
+
"\e[0;31;49m#{err}\e[0m"
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def colorize_comment(comment)
|
26
|
+
# bright black bold ANSI color
|
27
|
+
"\e[0;90;1;49m#{comment}\e[0m"
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -31,7 +33,8 @@ module Niceql
|
|
31
33
|
# ?= -- should be present but without being added to MatchData
|
32
34
|
AFTER_KEYWORD_SPACE = '(?=\s{1})'
|
33
35
|
JOIN_KEYWORDS = '(RIGHT\s+|LEFT\s+){0,1}(INNER\s+|OUTER\s+){0,1}JOIN(\s+LATERAL){0,1}'
|
34
|
-
INLINE_KEYWORDS = "WITH|ASC|COALESCE|AS|WHEN|THEN|ELSE|END|AND|UNION|ALL|ON|DISTINCT|
|
36
|
+
INLINE_KEYWORDS = "WITH|ASC|COALESCE|AS|WHEN|THEN|ELSE|END|AND|UNION|ALL|ON|DISTINCT|"\
|
37
|
+
"INTERSECT|EXCEPT|EXISTS|NOT|COUNT|ROUND|CAST|IN"
|
35
38
|
NEW_LINE_KEYWORDS = "SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|HAVING|OFFSET|UPDATE|SET|#{JOIN_KEYWORDS}"
|
36
39
|
|
37
40
|
POSSIBLE_INLINER = /(ORDER BY|CASE)/
|
@@ -94,7 +97,11 @@ module Niceql
|
|
94
97
|
sql_start_line_num = 3 if err.lines.length <= 3
|
95
98
|
# error not always contains HINT
|
96
99
|
sql_start_line_num ||= err.lines[3][/(HINT|DETAIL)/] ? 4 : 3
|
97
|
-
sql_body_lines = sql_start_line_num < err.lines.length
|
100
|
+
sql_body_lines = if sql_start_line_num < err.lines.length
|
101
|
+
err.lines[sql_start_line_num..-1]
|
102
|
+
else
|
103
|
+
original_sql_query&.lines
|
104
|
+
end
|
98
105
|
|
99
106
|
# this means original query is missing so it's nothing to prettify
|
100
107
|
return err unless sql_body_lines
|
@@ -164,7 +171,8 @@ module Niceql
|
|
164
171
|
# 1. Split the original query onto the query part + literals + comments
|
165
172
|
# a. find all potential dollar-signed separators
|
166
173
|
# b. prepare full literal extractor regex
|
167
|
-
# 2. Find and separate all literals and comments into mutable/format-able types
|
174
|
+
# 2. Find and separate all literals and comments into mutable/format-able types
|
175
|
+
# and immutable ( see the typing and formatting rules below )
|
168
176
|
# 3. Replace all literals and comments with uniq ids on the original query to get the parametrized query
|
169
177
|
# 4. Format parametrized query alongside with mutable/format-able comments and literals
|
170
178
|
# a. clear space characters: replace all \s+ to \s, remove all "\n" e.t.c
|
@@ -228,7 +236,11 @@ module Niceql
|
|
228
236
|
end
|
229
237
|
|
230
238
|
def prettified_sql
|
231
|
-
|
239
|
+
# sprintf or % interpolation will throw an error with standalone '%', but
|
240
|
+
# % is a legit operand: https://github.com/alekseyl/niceql/issues/25
|
241
|
+
# so it should be escaped via doubling, the easiest way is to do it twice,
|
242
|
+
# doubling every %, and then restoring single % for the combination of %%{
|
243
|
+
@parametrized_sql.gsub("%", "%%").gsub("%%{", "%{") % @guids_to_content.transform_keys(&:to_sym)
|
232
244
|
end
|
233
245
|
|
234
246
|
private
|
@@ -246,7 +258,8 @@ module Niceql
|
|
246
258
|
post_match_str = Regexp.last_match.post_match
|
247
259
|
|
248
260
|
if ["SELECT", "UPDATE", "INSERT"].include?(matched_part)
|
249
|
-
|
261
|
+
indent_block = !config.open_bracket_is_newliner || brackets.last.nil? || brackets.last[:nested]
|
262
|
+
indent += config.indentation_base if indent_block
|
250
263
|
brackets.last[:nested] = true if brackets.last
|
251
264
|
add_new_line = !first_keyword
|
252
265
|
elsif matched_part == "("
|
@@ -334,6 +347,8 @@ module Niceql
|
|
334
347
|
# when comment ending with newline followed by a keyword we should remove double newlines
|
335
348
|
def clear_extra_newline_after_comments
|
336
349
|
newlined_comments = @literals_and_comments_types.select { |k,| new_line_ending_comment?(k) }
|
350
|
+
return if newlined_comments.empty?
|
351
|
+
|
337
352
|
parametrized_sql.gsub!(/(#{newlined_comments.keys.join("}\n|")}}\n)/, &:chop)
|
338
353
|
end
|
339
354
|
|
@@ -446,11 +461,13 @@ module Niceql
|
|
446
461
|
end
|
447
462
|
end
|
448
463
|
|
449
|
-
|
450
|
-
|
451
|
-
|
464
|
+
class << self
|
465
|
+
def configure
|
466
|
+
yield(config)
|
467
|
+
end
|
452
468
|
|
453
|
-
|
454
|
-
|
469
|
+
def config
|
470
|
+
@config ||= NiceQLConfig.new
|
471
|
+
end
|
455
472
|
end
|
456
473
|
end
|
data/niceql.gemspec
CHANGED
@@ -36,13 +36,13 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
37
|
spec.require_paths = ["lib"]
|
38
38
|
|
39
|
-
spec.required_ruby_version = ">= 2.
|
39
|
+
spec.required_ruby_version = ">= 2.5"
|
40
40
|
|
41
41
|
spec.add_development_dependency("awesome_print")
|
42
42
|
spec.add_development_dependency("bundler", ">= 1")
|
43
43
|
spec.add_development_dependency("minitest", "~> 5.0")
|
44
44
|
spec.add_development_dependency("rake", ">= 12.3.3")
|
45
|
-
spec.add_development_dependency("rubocop-shopify", "~> 2.0
|
45
|
+
spec.add_development_dependency("rubocop-shopify", "~> 2.0")
|
46
46
|
|
47
47
|
spec.add_development_dependency("benchmark-ips")
|
48
48
|
spec.add_development_dependency("differ")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niceql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.0
|
75
|
+
version: '2.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.0
|
82
|
+
version: '2.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: benchmark-ips
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,9 +146,11 @@ executables: []
|
|
146
146
|
extensions: []
|
147
147
|
extra_rdoc_files: []
|
148
148
|
files:
|
149
|
+
- ".github/dependabot.yml"
|
150
|
+
- ".github/workflows/ci.yml"
|
151
|
+
- ".github/workflows/rubocop.yml"
|
149
152
|
- ".gitignore"
|
150
153
|
- ".rubocop.yml"
|
151
|
-
- ".travis.yml"
|
152
154
|
- CHANGELOG.md
|
153
155
|
- Gemfile
|
154
156
|
- LICENSE.txt
|
@@ -177,14 +179,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
179
|
requirements:
|
178
180
|
- - ">="
|
179
181
|
- !ruby/object:Gem::Version
|
180
|
-
version: '2.
|
182
|
+
version: '2.5'
|
181
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
184
|
requirements:
|
183
185
|
- - ">="
|
184
186
|
- !ruby/object:Gem::Version
|
185
187
|
version: '0'
|
186
188
|
requirements: []
|
187
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.3.26
|
188
190
|
signing_key:
|
189
191
|
specification_version: 4
|
190
192
|
summary: This is a simple and nice gem for SQL prettifying and formatting. Niceql
|