active_record-mod_sql_log_subscriber 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +33 -0
- data/active_record-mod_sql_log_subscriber.gemspec +2 -1
- data/bin/connect_db.rb +10 -0
- data/bin/console +10 -1
- data/bin/setup +2 -0
- data/bin/setup_db.rb +25 -0
- data/lib/active_record/mod_sql_log_subscriber.rb +3 -3
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c54b21fd7a68cb5810c3133e11c170252c498c50ac5ca27636d12ed22a5dd66c
|
4
|
+
data.tar.gz: 3d1dd5f24f747bd4ec8e16275ceb50f50250113b858b42c958bd993d338166fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 679d7aba887b8640ae1fdce95d63ea51b3e2c3c2c0f70695666c9f493f9e0dc4e15a7518fc5666def3511ace0b259e75f99e33cacf04b13547293a23336bf063
|
7
|
+
data.tar.gz: 587fb2221a219be48a20216faa56c1d3c4ba7afeb43dba7abe485502d715c93671c494bd038daa5c4351a885eb37e39755a86b0d48da6d30643e86eb06efefa7
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -71,6 +71,39 @@ $ rails c
|
|
71
71
|
# => "UPDATE users SET name = 'New name' WHERE id = $1 {:id=>1}"
|
72
72
|
```
|
73
73
|
|
74
|
+
### Try console
|
75
|
+
|
76
|
+
You can try this gem by cloning this repo and run `bin/setup` and `bin/console`.
|
77
|
+
|
78
|
+
```
|
79
|
+
$ git clone https://github.com/ryu39/active_record-mod_sql_log_subscriber.git
|
80
|
+
$ cd active_record-mod_sql_log_subscriber
|
81
|
+
|
82
|
+
# Run bundle install and create sqlite3 database.
|
83
|
+
$ bin/setup
|
84
|
+
|
85
|
+
# Connect sqlite3 database and start IRB.
|
86
|
+
$ bin/console
|
87
|
+
|
88
|
+
> User.count # => no log
|
89
|
+
|
90
|
+
> User.create!(name: 'name', age: 20, birth_date: Date.new(2000, 1, 1))
|
91
|
+
# => 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 (?, ?, ?, ?, ?) [["name", "name"], ["age", 20], ["birth_date", "2000-01-01"], ["created_at", "2019-02-05 02:04:07.489226"], ["updated_at", "2019-02-05 02:04:07.489226"]]
|
93
|
+
# I, [2019-02-05T11:04:07.492610 #42019] INFO -- : commit transaction
|
94
|
+
|
95
|
+
> user = User.last # => no log
|
96
|
+
> user.update_attributes(name: 'new name')
|
97
|
+
# => 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" = ? [["name", "new name"], ["updated_at", "2019-02-05 02:04:52.971865"], ["id", 2]]
|
99
|
+
# I, [2019-02-05T11:04:52.974081 #42019] INFO -- : commit transaction
|
100
|
+
|
101
|
+
> user.destroy
|
102
|
+
# => 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" = ? [["id", 2]]
|
104
|
+
# I, [2019-02-05T11:05:13.776722 #42019] INFO -- : commit transaction
|
105
|
+
```
|
106
|
+
|
74
107
|
## Configuration
|
75
108
|
|
76
109
|
You can configure this subscriber before attaching to :active_record namespace
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
22
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(config|db|test|spec|features)/}) }
|
24
24
|
end
|
25
25
|
spec.bindir = "exe"
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.17"
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
34
34
|
spec.add_development_dependency "rspec"
|
35
|
+
spec.add_development_dependency "sqlite3", "~> 1.3.6"
|
35
36
|
end
|
data/bin/connect_db.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'yaml'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
config_file = File.expand_path('../../config/database.yml', __FILE__)
|
8
|
+
config = YAML.load(ERB.new(IO.read(config_file)).result)['db']
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection(config)
|
data/bin/console
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "active_record/mod_sql_log_subscriber"
|
5
4
|
|
6
5
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
6
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +9,15 @@ require "active_record/mod_sql_log_subscriber"
|
|
10
9
|
# require "pry"
|
11
10
|
# Pry.start
|
12
11
|
|
12
|
+
require 'logger'
|
13
|
+
require 'active_record'
|
14
|
+
load File.expand_path('../connect_db.rb', __FILE__)
|
15
|
+
|
16
|
+
require "active_record/mod_sql_log_subscriber"
|
17
|
+
require File.expand_path('../../db/user.rb', __FILE__)
|
18
|
+
|
19
|
+
::ActiveRecord::Base.logger = ::Logger.new(STDOUT, level: :info)
|
20
|
+
::ActiveRecord::ModSqlLogSubscriber.attach_to(:active_record)
|
21
|
+
|
13
22
|
require "irb"
|
14
23
|
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
data/bin/setup_db.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'yaml'
|
5
|
+
require 'active_record'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
config_file = File.expand_path('../../config/database.yml', __FILE__)
|
9
|
+
config = YAML.load(ERB.new(IO.read(config_file)).result)['db']
|
10
|
+
|
11
|
+
if ::File.exist?(config['database'])
|
12
|
+
::FileUtils.rm_f(config['database'])
|
13
|
+
end
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection(config)
|
16
|
+
|
17
|
+
ActiveRecord::Base.connection.create_table :users do |t|
|
18
|
+
t.string :type
|
19
|
+
t.string :name, null: false
|
20
|
+
t.integer :age, null: false
|
21
|
+
t.date :birth_date, null: false
|
22
|
+
t.boolean :disabled, null: false, default: false
|
23
|
+
|
24
|
+
t.timestamps
|
25
|
+
end
|
@@ -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.1"
|
14
14
|
|
15
15
|
config_accessor :disable, :log_level, :log_format, :target_statements
|
16
16
|
|
@@ -42,12 +42,12 @@ module ActiveRecord
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def extract_binds(payload)
|
45
|
-
binds =
|
45
|
+
binds = []
|
46
46
|
unless (payload[:binds] || []).empty?
|
47
47
|
casted_params = type_casted_binds(payload[:type_casted_binds])
|
48
48
|
payload[:binds].zip(casted_params).map do |attr, value|
|
49
49
|
key, val = render_bind(attr, value)
|
50
|
-
binds[key
|
50
|
+
binds << [key, val]
|
51
51
|
end
|
52
52
|
end
|
53
53
|
binds
|
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.1
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.6
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.6
|
83
97
|
description: An ActiveRecord::LogSubscriber which records only mod sql.
|
84
98
|
email:
|
85
99
|
- dev.ryu39@gmail.com
|
@@ -94,8 +108,10 @@ files:
|
|
94
108
|
- README.md
|
95
109
|
- Rakefile
|
96
110
|
- active_record-mod_sql_log_subscriber.gemspec
|
111
|
+
- bin/connect_db.rb
|
97
112
|
- bin/console
|
98
113
|
- bin/setup
|
114
|
+
- bin/setup_db.rb
|
99
115
|
- lib/active_record/mod_sql_log_subscriber.rb
|
100
116
|
homepage: https://github.com/ryu39/active_record-mod_sql_log_subscriber
|
101
117
|
licenses:
|