niceql 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -15
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +8 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2056d114407ed81b47224f1bc0f60d2e65bb88118667f074fd972149203bd6ea
|
4
|
+
data.tar.gz: 48c228ee2240a0fd8beec6ecc1c312b42197a8a259bf1d5b438e41fd55c51680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 070a9574f50f434136474dfc1b671956b8df3529434f2e13f36e4b4c952a1dbc23da5a9e81a5d8eba082154c523c6056476b25396ec52654dcbe0436ae04c18e
|
7
|
+
data.tar.gz: e8b550669250d612233b7fdbced172d12cd6d348dd8bfda21ff6ff8dda0358c6cf59e23aa917bbade0f49286017173a10099488a830d1e0802efd71faa98b35a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 0.4.0
|
2
|
+
* merged PR https://github.com/alekseyl/niceql/pull/19, now Arel is also extended with niceql methods!!
|
3
|
+
* test and better niceql comparisons assertion
|
4
|
+
* tests were trialed against rails 4.2 and some additional conditions were added for later cases
|
5
|
+
|
1
6
|
# 0.3.0
|
2
7
|
* ruby forced to >= 2.4
|
3
8
|
* String match extension no longer needed
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Niceql
|
2
2
|
|
3
|
-
This is a small, nice, simple and
|
3
|
+
This is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby.
|
4
4
|
It can be used in an irb console without any dependencies ( run bin/console and look for examples ).
|
5
5
|
|
6
|
-
Any reasonable suggestions
|
6
|
+
Any reasonable suggestions are welcome.
|
7
7
|
|
8
|
-
**Please pay attention: untill issue https://github.com/alekseyl/niceql/issues/16 is resolved any UPDATE or INSERT request
|
8
|
+
**Please pay attention: untill issue https://github.com/alekseyl/niceql/issues/16 is resolved any UPDATE or INSERT request might corrupt your data, don't use on production!**
|
9
9
|
|
10
10
|
|
11
11
|
## Before/After
|
@@ -44,9 +44,11 @@ Or install it yourself as:
|
|
44
44
|
```ruby
|
45
45
|
Niceql.configure do |c|
|
46
46
|
# Setting pg_adapter_with_nicesql to true will force formatting SQL queries
|
47
|
-
# before
|
47
|
+
# before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
|
48
48
|
# if you are using Postgresql as a data source.
|
49
|
+
#
|
49
50
|
# You can adjust pg_adapter in production but do it at your own risk!
|
51
|
+
#
|
50
52
|
# If you need to debug SQL queries in production use exec_niceql
|
51
53
|
# default: false
|
52
54
|
# uncomment next string to enable in development
|
@@ -56,7 +58,7 @@ Niceql.configure do |c|
|
|
56
58
|
# default: false
|
57
59
|
# c.prettify_active_record_log_output = true
|
58
60
|
|
59
|
-
#
|
61
|
+
# Error prettifying is also configurable
|
60
62
|
# default: defined? ::ActiveRecord::Base && ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
|
61
63
|
# c.prettify_pg_errors = defined? ::ActiveRecord::Base && ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
|
62
64
|
|
@@ -85,7 +87,7 @@ end
|
|
85
87
|
### With ActiveRecord
|
86
88
|
|
87
89
|
```ruby
|
88
|
-
# puts colorized
|
90
|
+
# puts colorized and formatted corresponding SQL query
|
89
91
|
Model.scope.niceql
|
90
92
|
|
91
93
|
# only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
|
@@ -110,23 +112,23 @@ end
|
|
110
112
|
#=>
|
111
113
|
#=> SELECT *
|
112
114
|
#=> FROM table
|
113
|
-
|
114
|
-
|
115
|
-
|
115
|
+
|
116
116
|
|
117
|
-
|
118
|
-
puts Niceql::Prettifier.prettify_pg_err( "#{pg_err_output}\n#{sql_query}" )
|
117
|
+
puts Niceql::Prettifier.prettify_pg_err( pg_err_output, sql_query )
|
119
118
|
|
120
119
|
# to get real nice result you should execute prettified version (i.e. execute( prettified_sql ) !) of query on your DB!
|
121
120
|
# otherwise you will not get such a nice output
|
122
|
-
|
121
|
+
raw_sql = <<~SQL
|
122
|
+
SELECT err
|
123
|
+
FROM ( VALUES(1), (2) )
|
124
|
+
ORDER BY 1
|
125
|
+
SQL
|
126
|
+
|
127
|
+
puts Niceql::Prettifier.prettify_pg_err(<<~ERR, raw_sql )
|
123
128
|
ERROR: VALUES in FROM must have an alias
|
124
129
|
LINE 2: FROM ( VALUES(1), (2) )
|
125
130
|
^
|
126
131
|
HINT: For example, FROM (VALUES ...) [AS] foo.
|
127
|
-
SELECT err
|
128
|
-
FROM ( VALUES(1), (2) )
|
129
|
-
ORDER BY 1
|
130
132
|
ERR
|
131
133
|
|
132
134
|
|
data/lib/niceql/version.rb
CHANGED
data/lib/niceql.rb
CHANGED
@@ -4,15 +4,15 @@ module Niceql
|
|
4
4
|
|
5
5
|
module StringColorize
|
6
6
|
def self.colorize_verb( str)
|
7
|
-
#yellow ANSI color
|
7
|
+
# yellow ANSI color
|
8
8
|
"\e[0;33;49m#{str}\e[0m"
|
9
9
|
end
|
10
10
|
def self.colorize_str(str)
|
11
|
-
#cyan ANSI color
|
11
|
+
# cyan ANSI color
|
12
12
|
"\e[0;36;49m#{str}\e[0m"
|
13
13
|
end
|
14
14
|
def self.colorize_err(err)
|
15
|
-
#red ANSI color
|
15
|
+
# red ANSI color
|
16
16
|
"\e[0;31;49m#{err}\e[0m"
|
17
17
|
end
|
18
18
|
end
|
@@ -198,6 +198,7 @@ module Niceql
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
+
private_class_method
|
201
202
|
def extract_err_caret_line( err_address_line, err_line, sql_body, err )
|
202
203
|
# LINE could be quoted ( both sides and sometimes only from one ):
|
203
204
|
# "LINE 1: ...t_id\" = $13 AND \"products\".\"carrier_id\" = $14 AND \"product_t...\n",
|
@@ -289,9 +290,10 @@ module Niceql
|
|
289
290
|
@config ||= NiceQLConfig.new
|
290
291
|
end
|
291
292
|
|
292
|
-
if defined? ::ActiveRecord
|
293
|
-
::ActiveRecord::
|
294
|
-
|
293
|
+
if defined? ::ActiveRecord
|
294
|
+
[::ActiveRecord::Relation,
|
295
|
+
::Arel::TreeManager,
|
296
|
+
::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
|
295
297
|
end
|
296
298
|
|
297
299
|
end
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.0.9
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: This is simple and nice gem for sql prettifying and formatting. Niceql splits,
|