active_record-mod_sql_log_subscriber 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -3
- data/lib/active_record/mod_sql_log_subscriber.rb +2 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4db0c79ca185a749a8aed8dc821e28f3c7de8ef6932e4069b3dfd904fb588e9e
|
4
|
+
data.tar.gz: 80524d959e775f16eef4dd27775e2612f3fe2f6d17d3a64e1e6fbfe1cc4250c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d5ec3e856157e2587e39f8d64a66f91eb1ebe094a66c7e533bc41466b4f7bdd2e9841c965ca04db34bce67ae1050444afa51f186b0a229d720737fa218ef387
|
7
|
+
data.tar.gz: ed104846206719ec342e6c74df977283eb04b1230bf5d1578275c5e93a46f4daca4f1ba7dec2f54c1aeb0360797a4dd0ff8c78d3fbf728c049588cfe66b69408
|
data/README.md
CHANGED
@@ -25,6 +25,10 @@ The mod-SQL is shown as follows.
|
|
25
25
|
* I want to write logs only mod-SQL(INSERT, UPDATE, DELETE, ...) and transaction SQL(BEGIN, COMMIT, ROLLBACK, ...).
|
26
26
|
So I create this gem.
|
27
27
|
|
28
|
+
## Requirements
|
29
|
+
|
30
|
+
* Rails >= 5.1.5
|
31
|
+
|
28
32
|
## Installation
|
29
33
|
|
30
34
|
Add this line to your application's Gemfile:
|
@@ -89,18 +93,18 @@ $ bin/console
|
|
89
93
|
|
90
94
|
> User.create!(name: 'name', age: 20, birth_date: Date.new(2000, 1, 1))
|
91
95
|
# => I, [2019-02-05T11:04:07.489057 #42019] INFO -- : begin transaction
|
92
|
-
# I, [2019-02-05T11:04:07.490495 #42019] INFO -- : INSERT INTO "users" ("name", "age", "birth_date", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [
|
96
|
+
# I, [2019-02-05T11:04:07.490495 #42019] INFO -- : INSERT INTO "users" ("name", "age", "birth_date", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) ["name", 20, "2000-01-01", "2019-02-20 05:00:13.175405", "2019-02-20 05:00:13.175405"]
|
93
97
|
# I, [2019-02-05T11:04:07.492610 #42019] INFO -- : commit transaction
|
94
98
|
|
95
99
|
> user = User.last # => no log
|
96
100
|
> user.update_attributes(name: 'new name')
|
97
101
|
# => I, [2019-02-05T11:04:52.971503 #42019] INFO -- : begin transaction
|
98
|
-
# I, [2019-02-05T11:04:52.973071 #42019] INFO -- : UPDATE "users" SET "name" = ?, "updated_at" = ? WHERE "users"."id" = ? [
|
102
|
+
# I, [2019-02-05T11:04:52.973071 #42019] INFO -- : UPDATE "users" SET "name" = ?, "updated_at" = ? WHERE "users"."id" = ? ["new name", "2019-02-20 05:00:37.983816", 2]
|
99
103
|
# I, [2019-02-05T11:04:52.974081 #42019] INFO -- : commit transaction
|
100
104
|
|
101
105
|
> user.destroy
|
102
106
|
# => I, [2019-02-05T11:05:13.765564 #42019] INFO -- : begin transaction
|
103
|
-
# I, [2019-02-05T11:05:13.775460 #42019] INFO -- : DELETE FROM "users" WHERE "users"."id" = ? [
|
107
|
+
# I, [2019-02-05T11:05:13.775460 #42019] INFO -- : DELETE FROM "users" WHERE "users"."id" = ? [2]
|
104
108
|
# I, [2019-02-05T11:05:13.776722 #42019] INFO -- : commit transaction
|
105
109
|
```
|
106
110
|
|
@@ -10,7 +10,7 @@ module ActiveRecord
|
|
10
10
|
class ModSqlLogSubscriber < ::ActiveRecord::LogSubscriber
|
11
11
|
include ActiveSupport::Configurable
|
12
12
|
|
13
|
-
VERSION = "0.1.
|
13
|
+
VERSION = "0.1.2"
|
14
14
|
|
15
15
|
config_accessor :disable, :log_level, :log_format, :target_statements
|
16
16
|
|
@@ -31,7 +31,7 @@ module ActiveRecord
|
|
31
31
|
return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
32
32
|
return unless target_sql_checker.match?(sql)
|
33
33
|
|
34
|
-
binds =
|
34
|
+
binds = type_casted_binds(payload[:type_casted_binds])
|
35
35
|
send(self.log_level, formatter.call(sql, binds))
|
36
36
|
end
|
37
37
|
|
@@ -41,18 +41,6 @@ module ActiveRecord
|
|
41
41
|
@target_sql_checker ||= /\A\s*(#{self.target_statements.join('|')})/mi
|
42
42
|
end
|
43
43
|
|
44
|
-
def extract_binds(payload)
|
45
|
-
binds = []
|
46
|
-
unless (payload[:binds] || []).empty?
|
47
|
-
casted_params = type_casted_binds(payload[:type_casted_binds])
|
48
|
-
payload[:binds].zip(casted_params).map do |attr, value|
|
49
|
-
key, val = render_bind(attr, value)
|
50
|
-
binds << [key, val]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
binds
|
54
|
-
end
|
55
|
-
|
56
44
|
def formatter
|
57
45
|
@formatter ||=
|
58
46
|
case self.log_format
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-mod_sql_log_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryu39
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|