niceql 0.4.1 → 0.5.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +4 -78
- data/niceql.gemspec +1 -2
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61e17e9e56ddebb633c9ff0051e0fc400842f030a9d89236d484107dbf55389d
|
4
|
+
data.tar.gz: a80a5c8720b2da17f44e37e56a4543360e1424fad18c67d869ca466bbe19c0e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83302f8bff5ec7942338b93ec77739948606a34a85480e38ee19b16785391081d99865b6f31dd86ede787aef17061d0918bb8c77cb3eb84aa2bca3030bce30a2
|
7
|
+
data.tar.gz: 3ab3a19673a3e6d47d1d344c38bb42717526ca84e39a999c7933a15cfbaf07a361c6b7789089f3bc4c0dcb224d2d596050141ee460c5c6d3a532ea240505450a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 0.5.0
|
2
|
+
* BREAKING CHANGE! ActiveRecord compatibility extracted to the rails_sql_prettifier gem!
|
3
|
+
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.
|
5
|
+
|
1
6
|
# 0.4.1
|
2
7
|
* description update
|
3
8
|
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Niceql
|
2
2
|
|
3
|
+
ATTENTION: Since ver 0.5.0 the ActiveRecord integration will be provided via standalone gem: [rails_sql_prettifier](https://github.com/alekseyl/rails_sql_prettifier)!
|
4
|
+
|
3
5
|
This is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby.
|
4
6
|
It can be used in an irb console without any dependencies ( run bin/console and look for examples ).
|
5
7
|
|
data/lib/niceql/version.rb
CHANGED
data/lib/niceql.rb
CHANGED
@@ -17,21 +17,6 @@ module Niceql
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
module ArExtentions
|
21
|
-
def exec_niceql
|
22
|
-
connection.execute( to_niceql )
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_niceql
|
26
|
-
Prettifier.prettify_sql(to_sql, false)
|
27
|
-
end
|
28
|
-
|
29
|
-
def niceql( colorize = true )
|
30
|
-
puts Prettifier.prettify_sql( to_sql, colorize )
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
20
|
module Prettifier
|
36
21
|
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('| ')
|
37
22
|
NEW_LINE_VERBS = 'SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|(RIGHT |LEFT )*(INNER |OUTER )*JOIN( LATERAL)*|HAVING|OFFSET|UPDATE'
|
@@ -202,7 +187,7 @@ module Niceql
|
|
202
187
|
def extract_err_caret_line( err_address_line, err_line, sql_body, err )
|
203
188
|
# LINE could be quoted ( both sides and sometimes only from one ):
|
204
189
|
# "LINE 1: ...t_id\" = $13 AND \"products\".\"carrier_id\" = $14 AND \"product_t...\n",
|
205
|
-
err_quote = (err_address_line.match(/\.\.\.(.+)\.\.\./) || err_address_line.match(/\.\.\.(.+)/) )
|
190
|
+
err_quote = (err_address_line.match(/\.\.\.(.+)\.\.\./) || err_address_line.match(/\.\.\.(.+)/) )&.send(:[], 1)
|
206
191
|
|
207
192
|
# line[2] is original err caret line i.e.: ' ^'
|
208
193
|
# err_address_line[/LINE \d+:/].length+1..-1 - is a position from error quote begin
|
@@ -224,76 +209,17 @@ module Niceql
|
|
224
209
|
end
|
225
210
|
end
|
226
211
|
|
227
|
-
module PostgresAdapterNiceQL
|
228
|
-
def exec_query(sql, name = "SQL", binds = [], prepare: false)
|
229
|
-
# replacing sql with prettified sql, thats all
|
230
|
-
super( Prettifier.prettify_sql(sql, false), name, binds, prepare: prepare )
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
module AbstractAdapterLogPrettifier
|
235
|
-
def log( sql, *args, &block )
|
236
|
-
# \n need to be placed because AR log will start with action description + time info.
|
237
|
-
# rescue sql - just to be sure Prettifier wouldn't break production
|
238
|
-
formatted_sql = "\n" + Prettifier.prettify_sql(sql) rescue sql
|
239
|
-
super( formatted_sql, *args, &block )
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
module ErrorExt
|
244
|
-
def to_s
|
245
|
-
# older rails version do not provide sql as a standalone query, instead they
|
246
|
-
# deliver joined message
|
247
|
-
Niceql.config.prettify_pg_errors ? Prettifier.prettify_err(super, try(:sql) ) : super
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
212
|
class NiceQLConfig
|
252
|
-
|
253
|
-
return false unless defined?(::ActiveRecord::Base)
|
254
|
-
|
255
|
-
adapter = ActiveRecord::Base.try(:connection_db_config).try(:adapter) ||
|
256
|
-
ActiveRecord::Base.try(:connection_config)&.with_indifferent_access&.dig(:adapter)
|
257
|
-
|
258
|
-
adapter == 'postgresql'
|
259
|
-
end
|
260
|
-
|
261
|
-
attr_accessor :pg_adapter_with_nicesql,
|
262
|
-
:indentation_base,
|
263
|
-
:open_bracket_is_newliner,
|
264
|
-
:prettify_active_record_log_output,
|
265
|
-
:prettify_pg_errors
|
266
|
-
|
213
|
+
attr_accessor :indentation_base, :open_bracket_is_newliner
|
267
214
|
|
268
215
|
def initialize
|
269
|
-
self.pg_adapter_with_nicesql = false
|
270
216
|
self.indentation_base = 2
|
271
217
|
self.open_bracket_is_newliner = false
|
272
|
-
self.prettify_active_record_log_output = false
|
273
|
-
self.prettify_pg_errors = ar_using_pg_adapter?
|
274
218
|
end
|
275
219
|
end
|
276
220
|
|
277
|
-
def self.configure
|
278
|
-
yield( config )
|
279
|
-
|
280
|
-
return unless defined? ::ActiveRecord::Base
|
221
|
+
def self.configure; yield( config ) end
|
281
222
|
|
282
|
-
|
283
|
-
|
284
|
-
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
|
285
|
-
|
286
|
-
::ActiveRecord::StatementInvalid.include( Niceql::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
|
287
|
-
end
|
288
|
-
|
289
|
-
def self.config
|
290
|
-
@config ||= NiceQLConfig.new
|
291
|
-
end
|
292
|
-
|
293
|
-
if defined? ::ActiveRecord
|
294
|
-
[::ActiveRecord::Relation,
|
295
|
-
::Arel::TreeManager,
|
296
|
-
::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
|
297
|
-
end
|
223
|
+
def self.config; @config ||= NiceQLConfig.new end
|
298
224
|
|
299
225
|
end
|
data/niceql.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["leshchuk@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{This is a simple and nice gem for SQL prettifying and formatting. Niceql splits, indent and colorize SQL query and PG errors if any. }
|
13
|
-
spec.description = %q{This is a simple and nice gem for SQL prettifying and formatting. Niceql splits, indent and colorize SQL query and PG errors if any. Could be used as a standalone gem without any dependencies. Seamless ActiveRecord integration. }
|
13
|
+
spec.description = %q{This is a simple and nice gem for SQL prettifying and formatting. Niceql splits, indent and colorize SQL query and PG errors if any. Could be used as a standalone gem without any dependencies. Seamless ActiveRecord integration via rails_sql_prettifier gem. }
|
14
14
|
spec.homepage = "https://github.com/alekseyl/niceql"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
33
|
spec.required_ruby_version = '>= 2.4'
|
34
|
-
spec.add_development_dependency "activerecord", ">= 6.1"
|
35
34
|
|
36
35
|
spec.add_development_dependency "bundler", ">= 1"
|
37
36
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niceql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-08 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'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +110,8 @@ dependencies:
|
|
124
110
|
version: '0'
|
125
111
|
description: 'This is a simple and nice gem for SQL prettifying and formatting. Niceql
|
126
112
|
splits, indent and colorize SQL query and PG errors if any. Could be used as a standalone
|
127
|
-
gem without any dependencies. Seamless ActiveRecord integration
|
113
|
+
gem without any dependencies. Seamless ActiveRecord integration via rails_sql_prettifier
|
114
|
+
gem. '
|
128
115
|
email:
|
129
116
|
- leshchuk@gmail.com
|
130
117
|
executables: []
|