niceql 0.6.0 → 0.6.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: '0339306d10ce7dc5085193472b48e3570c0746078e9facdc8c21c75983ca075d'
4
- data.tar.gz: 79b513131cbc2ccc1afb4275e749e10078dcba15ed6fc05647b8877f3d149a3d
3
+ metadata.gz: 286318425292a968afb8fd83fc05d8067bb03432bdf120ab3412a23119cc4128
4
+ data.tar.gz: 1a694bab19fb2281ad3e6b013b4527db6233d55885641eb2b2c76d513309b979
5
5
  SHA512:
6
- metadata.gz: 7383d5b1b5c737fb8da4c877d5d96ca119081b53dc07377af216eda7a07276f480e98e70f6a30d887cee5d0f6df3b1e2762b907de0cc960870a10bd58fe5ad9c
7
- data.tar.gz: 29ad243cab8a66210070cf43b3072e4977b6fc1ed56fae41cfe9bba27de4b185fb80a76516ae498c0ef5c844f165ad15caac4001b243d6c3185bf3c873cfdd33
6
+ metadata.gz: 7398eac94842f0f457e7323603ec21ecdae146b9ceccc84e7191f0d2d4539b8de4447f1fa33206c124bc39b5572d1df8eb054d469ea3f39b929cf6b717367d83
7
+ data.tar.gz: f9f4da9487a41a117f08c20416dac9ba8146597301a40c62d162b44013460337ed7015e2674b05d679488b7b6fe7ea9420ae36a244f90c21203eb872b7f0412c
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -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"]
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,8 @@
1
+ # 0.6.1
2
+ * github CI added ( PR: https://github.com/alekseyl/niceql/pull/22 many thnx to @petergoldstein )
3
+ * issue fixed https://github.com/alekseyl/niceql/issues/23
4
+ * dropped support for 2.4 ( transform_keys is missing, and I'm too lazy to backward reimplement it you can do PR if needed )
5
+
1
6
  # 0.6.0
2
7
  * Huge core-logic refactoring and simplification
3
8
  * dollar signed literals/strings added
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Niceql
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
data/lib/niceql.rb CHANGED
@@ -6,24 +6,26 @@ require "forwardable"
6
6
 
7
7
  module Niceql
8
8
  module StringColorize
9
- def self.colorize_keyword(str)
10
- # yellow ANSI color
11
- "\e[0;33;49m#{str}\e[0m"
12
- end
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
- def self.colorize_str(str)
15
- # cyan ANSI color
16
- "\e[0;36;49m#{str}\e[0m"
17
- end
15
+ def colorize_str(str)
16
+ # cyan ANSI color
17
+ "\e[0;36;49m#{str}\e[0m"
18
+ end
18
19
 
19
- def self.colorize_err(err)
20
- # red ANSI color
21
- "\e[0;31;49m#{err}\e[0m"
22
- end
20
+ def colorize_err(err)
21
+ # red ANSI color
22
+ "\e[0;31;49m#{err}\e[0m"
23
+ end
23
24
 
24
- def self.colorize_comment(comment)
25
- # bright black bold ANSI color
26
- "\e[0;90;1;49m#{comment}\e[0m"
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|INTERSECT|EXCEPT|EXISTS|NOT|COUNT|ROUND|CAST|IN"
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 ? err.lines[sql_start_line_num..-1] : original_sql_query&.lines
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 and immutable ( see the typing and formatting rules below )
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
@@ -210,7 +218,7 @@ module Niceql
210
218
  # but right now there is no difference between the
211
219
  # newline_wrapped_comment, newline_start_comment, newline_end_comment, they all will be wrapped in newlines
212
220
  COMMENT_AND_LITERAL_TYPES = [:immutable_string, :indentable_string, :inline_comment, :newline_wrapped_comment,
213
- :newline_start_comment, :newline_end_comment]
221
+ :newline_start_comment, :newline_end_comment,]
214
222
 
215
223
  attr_reader :parametrized_sql, :initial_sql, :string_regex, :literals_and_comments_types, :colorize
216
224
 
@@ -246,7 +254,8 @@ module Niceql
246
254
  post_match_str = Regexp.last_match.post_match
247
255
 
248
256
  if ["SELECT", "UPDATE", "INSERT"].include?(matched_part)
249
- indent += config.indentation_base if !config.open_bracket_is_newliner || brackets.last.nil? || brackets.last[:nested]
257
+ indent_block = !config.open_bracket_is_newliner || brackets.last.nil? || brackets.last[:nested]
258
+ indent += config.indentation_base if indent_block
250
259
  brackets.last[:nested] = true if brackets.last
251
260
  add_new_line = !first_keyword
252
261
  elsif matched_part == "("
@@ -334,6 +343,7 @@ module Niceql
334
343
  # when comment ending with newline followed by a keyword we should remove double newlines
335
344
  def clear_extra_newline_after_comments
336
345
  newlined_comments = @literals_and_comments_types.select { |k,| new_line_ending_comment?(k) }
346
+ return if newlined_comments.length == 0
337
347
  parametrized_sql.gsub!(/(#{newlined_comments.keys.join("}\n|")}}\n)/, &:chop)
338
348
  end
339
349
 
@@ -446,11 +456,13 @@ module Niceql
446
456
  end
447
457
  end
448
458
 
449
- def self.configure
450
- yield(config)
451
- end
459
+ class << self
460
+ def configure
461
+ yield(config)
462
+ end
452
463
 
453
- def self.config
454
- @config ||= NiceQLConfig.new
464
+ def config
465
+ @config ||= NiceQLConfig.new
466
+ end
455
467
  end
456
468
  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.4"
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.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.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-16 00:00:00.000000000 Z
11
+ date: 2022-11-19 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.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.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,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
179
  requirements:
178
180
  - - ">="
179
181
  - !ruby/object:Gem::Version
180
- version: '2.4'
182
+ version: '2.5'
181
183
  required_rubygems_version: !ruby/object:Gem::Requirement
182
184
  requirements:
183
185
  - - ">="
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4
5
- - 2.5
6
- - 2.3
7
- - 2.6