niceql 0.3.1 → 0.4.0

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: cfbeddac683e41bcbbc3d8fc2c42fcbb505a6d129c58dc9653a93650317c8125
4
- data.tar.gz: e4de50a94af55592a2f31ced37b6a1986abdea37ca462ce529bd7bdfabde08be
3
+ metadata.gz: 2056d114407ed81b47224f1bc0f60d2e65bb88118667f074fd972149203bd6ea
4
+ data.tar.gz: 48c228ee2240a0fd8beec6ecc1c312b42197a8a259bf1d5b438e41fd55c51680
5
5
  SHA512:
6
- metadata.gz: 64dc4d5869ee5e79b408b99fe963bcafd595d44a8c8495e72429d104478ee6811b8eba211ef13527e060746a52e4c4a6c192e17aef95237c6d79248b0a421a12
7
- data.tar.gz: 865161e1af50386a06a98ba9e1af708f388f44f96f2566fb3f0695ac4756a66030731c8f8e603d5f7c88a009d4a6f4d840c0c2d9f140e81500411cccba17ee41
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 no-dependency solution for SQL prettifying for Ruby.
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 on formatting/coloring are welcome
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 will corrupt your data, don't use on production!**
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 executing them, this will lead to better SQL-query debugging and much more clearer error messages
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
- # now error prettifying is configurable
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 ( or not if you are willing so ) to_niceql ( you need to call puts otherwise to_niceql looks ugly )
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
- # rails combines err with query, so don't forget to do it yourself:
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
- puts Niceql::Prettifier.prettify_pg_err(<<~ERR )
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
 
@@ -1,3 +1,3 @@
1
1
  module Niceql
2
- VERSION = "0.3.1"
2
+ VERSION = '0.4.0'
3
3
  end
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::Base
293
- ::ActiveRecord::Base.extend ArExtentions
294
- [::ActiveRecord::Relation, ::ActiveRecord::Associations::CollectionProxy].each { |klass| klass.send(:include, ArExtentions) }
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.3.1
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-10-12 00:00:00.000000000 Z
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.1.4
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,