pp_sql 0.2.0 → 0.2.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/README.md +8 -15
- data/lib/pp_sql/version.rb +1 -1
- data/lib/pp_sql.rb +35 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5038184d5f8ed886733d19559eef2b1c053889e4
|
4
|
+
data.tar.gz: 4cb400cad3c8a5247f9906932a01f308aeeb9e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 916631092c11d88e5b5847b8ff5a87a04975d46c6c84975d54d67c414e7c9f8cf7ee39877d50a5c4bf1fdfe45d793db31ead30ba22cacb79a810f8f6f2fdd385
|
7
|
+
data.tar.gz: 7b8180e94856428e05fdfb0809b87ffe3aa3d6b636b498847c4c3c60ee23877a5bdc890fd1d9b2de0f12295afea9c0bd79fa623c17f3c1f58ff08eeef80c6588
|
data/README.md
CHANGED
@@ -1,20 +1,13 @@
|
|
1
1
|
# PpSql
|
2
2
|
|
3
|
-
Replace
|
4
|
-
gem for pretty SQL code output in console. Rails log will be formatted also.
|
3
|
+
Replace standard `ActiveRecord#to_sql` method with [`anbt-sql-formatter`](https://github.com/sonota88/anbt-sql-formatter)
|
4
|
+
gem for pretty SQL code output in console. Rails log will be formatted also. Example output:
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# thus
|
12
|
-
# =>
|
13
|
-
SELECT
|
14
|
-
`users`. *
|
15
|
-
FROM
|
16
|
-
`users`
|
17
|
-
```
|
6
|
+

|
7
|
+
|
8
|
+
Or in console
|
9
|
+
|
10
|
+
![console] (http://savepic.ru/12578341.png)
|
18
11
|
|
19
12
|
## Require
|
20
13
|
|
@@ -38,7 +31,7 @@ and use formatter with any String.
|
|
38
31
|
|
39
32
|
add in Gemfile
|
40
33
|
```
|
41
|
-
gem 'pp_sql', group :development
|
34
|
+
gem 'pp_sql', group: :development
|
42
35
|
```
|
43
36
|
|
44
37
|
And then execute:
|
data/lib/pp_sql/version.rb
CHANGED
data/lib/pp_sql.rb
CHANGED
@@ -22,11 +22,41 @@ module PpSql
|
|
22
22
|
puts to_sql
|
23
23
|
end
|
24
24
|
end
|
25
|
+
module Rails5PpSqlPort
|
26
|
+
# export from Rails 5 with for Rails 4.2+ versions
|
27
|
+
def colorize_payload_name(name, payload_name)
|
28
|
+
if payload_name.blank? || payload_name == "SQL" # SQL vs Model Load/Exists
|
29
|
+
color(name, ActiveSupport::LogSubscriber::MAGENTA, true)
|
30
|
+
else
|
31
|
+
color(name, ActiveSupport::LogSubscriber::CYAN, true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sql_color(sql)
|
36
|
+
case sql
|
37
|
+
when /\A\s*rollback/mi
|
38
|
+
ActiveSupport::LogSubscriber::RED
|
39
|
+
when /select .*for update/mi, /\A\s*lock/mi
|
40
|
+
ActiveSupport::LogSubscriber::WHITE
|
41
|
+
when /\A\s*select/i
|
42
|
+
ActiveSupport::LogSubscriber::BLUE
|
43
|
+
when /\A\s*insert/i
|
44
|
+
ActiveSupport::LogSubscriber::GREEN
|
45
|
+
when /\A\s*update/i
|
46
|
+
ActiveSupport::LogSubscriber::YELLOW
|
47
|
+
when /\A\s*delete/i
|
48
|
+
ActiveSupport::LogSubscriber::RED
|
49
|
+
when /transaction\s*\Z/i
|
50
|
+
ActiveSupport::LogSubscriber::CYAN
|
51
|
+
else
|
52
|
+
ActiveSupport::LogSubscriber::MAGENTA
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
25
56
|
module LogSubscriberPrettyPrint
|
26
57
|
include Formatter
|
27
58
|
def sql(event)
|
28
59
|
return unless logger.debug?
|
29
|
-
|
30
60
|
self.class.runtime += event.duration
|
31
61
|
|
32
62
|
payload = event.payload
|
@@ -38,7 +68,9 @@ module PpSql
|
|
38
68
|
binds = nil
|
39
69
|
|
40
70
|
unless (payload[:binds] || []).empty?
|
41
|
-
binds = " " + payload[:binds].map
|
71
|
+
binds = " " + payload[:binds].map do |*args|
|
72
|
+
method(:render_bind).arity.one? ? render_bind(args.first) : render_bind(*args)
|
73
|
+
end.inspect
|
42
74
|
end
|
43
75
|
|
44
76
|
name = colorize_payload_name(name, payload[:name])
|
@@ -53,6 +85,7 @@ module PpSql
|
|
53
85
|
ActiveSupport.on_load(:active_record) do
|
54
86
|
ActiveRecord::Relation.send(:prepend, ToSqlBeautify)
|
55
87
|
ActiveRecord::LogSubscriber.send(:prepend, LogSubscriberPrettyPrint)
|
88
|
+
ActiveRecord::LogSubscriber.send(:include, Rails5PpSqlPort) if Rails::VERSION::MAJOR <= 4
|
56
89
|
end
|
57
90
|
end
|
58
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pp_sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kvokka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|