niceql 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61e17e9e56ddebb633c9ff0051e0fc400842f030a9d89236d484107dbf55389d
4
- data.tar.gz: a80a5c8720b2da17f44e37e56a4543360e1424fad18c67d869ca466bbe19c0e0
3
+ metadata.gz: 126874d18a0ec3ce725d5f62a63a0cc57012cee9d5268eb189f060d2d1e0b6d0
4
+ data.tar.gz: '090a0208059e848eda15e721857238c9916a97527e75b672e5216c30b3745ed9'
5
5
  SHA512:
6
- metadata.gz: 83302f8bff5ec7942338b93ec77739948606a34a85480e38ee19b16785391081d99865b6f31dd86ede787aef17061d0918bb8c77cb3eb84aa2bca3030bce30a2
7
- data.tar.gz: 3ab3a19673a3e6d47d1d344c38bb42717526ca84e39a999c7933a15cfbaf07a361c6b7789089f3bc4c0dcb224d2d596050141ee460c5c6d3a532ea240505450a
6
+ metadata.gz: 400ee6d267eb95de34d1c1e018fceaab42dac6054f08d4bbe90c45c4ea7c366855c45da67b0f3d963d880893e21cbcb70117aa46f7ffe3aff8eacce1aa5d8f75
7
+ data.tar.gz: 7417f1ddf85cb2959f8eb59a6997154f721dc7696ca66caf60d16b095f7390e17233915680fa176b455a761b135582b76c085ae92b0d89fb53d6a2043c36fc1e
data/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
+ # 0.5.1
2
+ * No features just some code refactoring
3
+
1
4
  # 0.5.0
2
5
  * BREAKING CHANGE! ActiveRecord compatibility extracted to the rails_sql_prettifier gem!
3
6
  If you need niceql funcitonality with rails / active_record plz include rails_sql_prettifier has a
4
- a versioning aligned to the active_record versions and has same DSL for AR niceql provide prior.
7
+ a versioning aligned to the active_record versions and has same DSL for ActiveRecord the niceql was providing prior.
5
8
 
6
9
  # 0.4.1
7
10
  * description update
@@ -1,3 +1,3 @@
1
1
  module Niceql
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
data/lib/niceql.rb CHANGED
@@ -62,36 +62,31 @@ module Niceql
62
62
  # don't mess with original sql query, or prettify_pg_err will deliver incorrect results
63
63
  def prettify_pg_err(err, original_sql_query = nil)
64
64
  return err if err[/LINE \d+/].nil?
65
- err_line_num = err[/LINE \d+/][5..-1].to_i
65
+ # LINE 2: ... -> err_line_num = 2
66
+ err_line_num = err.match(/LINE (\d+):/)[1].to_i
66
67
  # LINE 1: SELECT usr FROM users ORDER BY 1
67
68
  err_address_line = err.lines[1]
68
69
 
69
- start_sql_line = 3 if err.lines.length <= 3
70
+ sql_start_line_num = 3 if err.lines.length <= 3
70
71
  # error not always contains HINT
71
- start_sql_line ||= err.lines[3][/(HINT|DETAIL)/] ? 4 : 3
72
- sql_body = start_sql_line < err.lines.length ? err.lines[start_sql_line..-1] : original_sql_query&.lines
72
+ sql_start_line_num ||= err.lines[3][/(HINT|DETAIL)/] ? 4 : 3
73
+ sql_body_lines = sql_start_line_num < err.lines.length ? err.lines[sql_start_line_num..-1] : original_sql_query&.lines
73
74
 
74
75
  # this means original query is missing so it's nothing to prettify
75
- return err unless sql_body
76
+ return err unless sql_body_lines
76
77
 
77
- # err line will be painted in red completely, so we just remembering it and use
78
- # to replace after painting the verbs
79
- err_line = sql_body[err_line_num - 1]
78
+ # this is an SQL line with an error.
79
+ # we need err_line to properly align the caret in the caret line
80
+ # and to apply a full red colorizing schema on an SQL line with error
81
+ err_line = sql_body_lines[err_line_num - 1]
80
82
 
83
+ #colorizing verbs, strings and error line
84
+ err_body = sql_body_lines.map { |ln| ln == err_line ? StringColorize.colorize_err( ln ) : colorize_err_line(ln) }
81
85
 
82
- #colorizing verbs and strings
83
- colorized_sql_body = sql_body.join.gsub(/#{VERBS}/ ) { |verb| StringColorize.colorize_verb(verb) }
84
- .gsub(STRINGS){ |str| StringColorize.colorize_str(str) }
85
-
86
- #reassemling error message
87
- err_body = colorized_sql_body.lines
88
- # replacing colorized line contained error and adding caret line
89
- err_body[err_line_num - 1]= StringColorize.colorize_err( err_line )
90
-
91
- err_caret_line = extract_err_caret_line( err_address_line, err_line, sql_body, err )
86
+ err_caret_line = extract_err_caret_line( err_address_line, err_line, sql_body_lines, err )
92
87
  err_body.insert( err_line_num, StringColorize.colorize_err( err_caret_line ) )
93
88
 
94
- err.lines[0..start_sql_line-1].join + err_body.join
89
+ err.lines[0..sql_start_line_num-1].join + err_body.join
95
90
  end
96
91
 
97
92
  def prettify_sql( sql, colorize = true )
@@ -183,7 +178,11 @@ module Niceql
183
178
  end
184
179
  end
185
180
 
186
- private_class_method
181
+ def colorize_err_line( line )
182
+ line.gsub(/#{VERBS}/ ) { |verb| StringColorize.colorize_verb(verb) }
183
+ .gsub(STRINGS) { |str| StringColorize.colorize_str(str) }
184
+ end
185
+
187
186
  def extract_err_caret_line( err_address_line, err_line, sql_body, err )
188
187
  # LINE could be quoted ( both sides and sometimes only from one ):
189
188
  # "LINE 1: ...t_id\" = $13 AND \"products\".\"carrier_id\" = $14 AND \"product_t...\n",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: niceql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl