niceql 0.5.0 → 0.5.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 +4 -1
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +19 -20
- 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: 126874d18a0ec3ce725d5f62a63a0cc57012cee9d5268eb189f060d2d1e0b6d0
|
4
|
+
data.tar.gz: '090a0208059e848eda15e721857238c9916a97527e75b672e5216c30b3745ed9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/niceql/version.rb
CHANGED
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 =
|
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
|
-
|
70
|
+
sql_start_line_num = 3 if err.lines.length <= 3
|
70
71
|
# error not always contains HINT
|
71
|
-
|
72
|
-
|
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
|
76
|
+
return err unless sql_body_lines
|
76
77
|
|
77
|
-
#
|
78
|
-
# to
|
79
|
-
|
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
|
-
|
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..
|
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
|
-
|
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",
|