niceql 0.1.22 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/CHANGELOG.md +19 -0
- data/README.md +5 -2
- data/lib/benchmark/cat.rb +20 -66
- data/lib/benchmark/gsub.rb +23 -14
- data/lib/benchmark/txt +748 -748
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +17 -18
- data/niceql.gemspec +6 -2
- metadata +43 -16
data/lib/niceql/version.rb
CHANGED
data/lib/niceql.rb
CHANGED
@@ -35,7 +35,7 @@ module Niceql
|
|
35
35
|
|
36
36
|
module Prettifier
|
37
37
|
INLINE_VERBS = %w(WITH ASC (IN\s) COALESCE AS WHEN THEN ELSE END AND UNION ALL ON DISTINCT INTERSECT EXCEPT EXISTS NOT COUNT ROUND CAST).join('| ')
|
38
|
-
NEW_LINE_VERBS = 'SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|(RIGHT |LEFT )*(INNER |OUTER )*JOIN
|
38
|
+
NEW_LINE_VERBS = 'SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|(RIGHT |LEFT )*(INNER |OUTER )*JOIN( LATERAL)*|HAVING|OFFSET|UPDATE'
|
39
39
|
POSSIBLE_INLINER = /(ORDER BY|CASE)/
|
40
40
|
VERBS = "#{NEW_LINE_VERBS}|#{INLINE_VERBS}"
|
41
41
|
STRINGS = /("[^"]+")|('[^']+')/
|
@@ -49,7 +49,6 @@ module Niceql
|
|
49
49
|
Niceql.config
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
52
|
def self.prettify_err(err)
|
54
53
|
prettify_pg_err( err.to_s )
|
55
54
|
end
|
@@ -229,15 +228,20 @@ module Niceql
|
|
229
228
|
|
230
229
|
module ErrorExt
|
231
230
|
def to_s
|
232
|
-
|
233
|
-
Prettifier.prettify_err(super)
|
234
|
-
else
|
235
|
-
super
|
236
|
-
end
|
231
|
+
Niceql.config.prettify_pg_errors ? Prettifier.prettify_err(super) : super
|
237
232
|
end
|
238
233
|
end
|
239
234
|
|
240
235
|
class NiceQLConfig
|
236
|
+
def ar_using_pg_adapter?
|
237
|
+
return false unless defined?(::ActiveRecord::Base)
|
238
|
+
|
239
|
+
adapter = ActiveRecord::Base.try(:connection_db_config).try(:adapter) ||
|
240
|
+
ActiveRecord::Base.try(:connection_config)&.with_indifferent_access&.dig(:adapter)
|
241
|
+
|
242
|
+
adapter == 'postgresql'
|
243
|
+
end
|
244
|
+
|
241
245
|
attr_accessor :pg_adapter_with_nicesql,
|
242
246
|
:indentation_base,
|
243
247
|
:open_bracket_is_newliner,
|
@@ -250,25 +254,20 @@ module Niceql
|
|
250
254
|
self.indentation_base = 2
|
251
255
|
self.open_bracket_is_newliner = false
|
252
256
|
self.prettify_active_record_log_output = false
|
253
|
-
self.prettify_pg_errors =
|
257
|
+
self.prettify_pg_errors = ar_using_pg_adapter?
|
254
258
|
end
|
255
259
|
end
|
256
260
|
|
257
|
-
|
258
261
|
def self.configure
|
259
262
|
yield( config )
|
260
263
|
|
261
|
-
|
262
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
|
263
|
-
end
|
264
|
+
return unless defined? ::ActiveRecord::Base
|
264
265
|
|
265
|
-
if config.
|
266
|
-
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier )
|
267
|
-
end
|
266
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL) if config.pg_adapter_with_nicesql
|
268
267
|
|
269
|
-
if config.
|
270
|
-
|
271
|
-
|
268
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
|
269
|
+
|
270
|
+
::ActiveRecord::StatementInvalid.include( Niceql::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
|
272
271
|
end
|
273
272
|
|
274
273
|
def self.config
|
data/niceql.gemspec
CHANGED
@@ -30,11 +30,15 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.
|
34
|
-
spec.add_development_dependency "
|
33
|
+
spec.required_ruby_version = '>= 2.3'
|
34
|
+
spec.add_development_dependency "activerecord", ">= 6.1"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", ">= 1"
|
37
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
35
38
|
spec.add_development_dependency "minitest", "~> 5.0"
|
36
39
|
|
37
40
|
spec.add_development_dependency "differ"
|
38
41
|
spec.add_development_dependency "pry-byebug"
|
39
42
|
spec.add_development_dependency "benchmark-ips"
|
43
|
+
spec.add_development_dependency 'sqlite3'
|
40
44
|
end
|
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niceql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - "
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
33
|
+
version: '1'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
40
|
+
version: '1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 12.3.3
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 12.3.3
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: 'This is simple and nice sql prettifier, it splits, indent and colorize
|
98
126
|
SQL query and PG error if any '
|
99
127
|
email:
|
@@ -128,7 +156,7 @@ licenses:
|
|
128
156
|
- MIT
|
129
157
|
metadata:
|
130
158
|
allowed_push_host: https://rubygems.org
|
131
|
-
post_install_message:
|
159
|
+
post_install_message:
|
132
160
|
rdoc_options: []
|
133
161
|
require_paths:
|
134
162
|
- lib
|
@@ -136,16 +164,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
164
|
requirements:
|
137
165
|
- - ">="
|
138
166
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
167
|
+
version: '2.3'
|
140
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
169
|
requirements:
|
142
170
|
- - ">="
|
143
171
|
- !ruby/object:Gem::Version
|
144
172
|
version: '0'
|
145
173
|
requirements: []
|
146
|
-
|
147
|
-
|
148
|
-
signing_key:
|
174
|
+
rubygems_version: 3.1.4
|
175
|
+
signing_key:
|
149
176
|
specification_version: 4
|
150
177
|
summary: This is simple and nice sql prettifier, it splits, indent and colorize SQL
|
151
178
|
query and PG errors if any
|