pg-connection-general_log 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1d256e00f37404799aeb51dc7f5dd6aab648eb2
4
- data.tar.gz: b4380f27151de0fbcb30e5920ee519c9f8c3e2da
3
+ metadata.gz: 732973316459a5617236cac69c99e26c8bc0b108
4
+ data.tar.gz: dfc8204ba19f9c962f2c1a7aeb0708e372e2bab3
5
5
  SHA512:
6
- metadata.gz: e1237391687bdbe6a51421c385492c5983bdd29d5436c79c0b7b927fbc137ecda28e5209eaba84f00690af16cc67e9b75c3a905eaa872efccb11cafafbd21346
7
- data.tar.gz: 811f8a7dee59434860f688f370013b672b6a8ebb09cced6c2b1e342646499324268119aaab250ccf1d6dc8a21d86db20eb189b3e5b5a7e2ab01abcbc322468e8
6
+ metadata.gz: 3b8bc83c051c3cfbb81bdc55a8aba42e3aaf45c97c40b93cd92b427d633574a6e30c1304998f5b78feb29d6850d982cde40b78518485b53dae0a91badbffa624
7
+ data.tar.gz: 8e82a0bbd54b50036461c95b67f4737eab973870e61194c598d3a574e233ff0ce2915cfc105c74bdce3d1906451af4a94f235ffea1136e425110fcc0251bdcbc
@@ -17,7 +17,7 @@ module PG
17
17
  end
18
18
 
19
19
  def general_log_with_request_id(request_id)
20
- Thread.current[:general_log]&.fetch(request_id)
20
+ Thread.current[:general_log]&.fetch(request_id, nil)
21
21
  end
22
22
 
23
23
  def delete_general_log(request_id)
@@ -43,6 +43,16 @@ module PG
43
43
  GeneralLog.general_log.push(sql, params, caller_locations, time)
44
44
  ret
45
45
  end
46
+
47
+ def async_exec(*args)
48
+ sql, params = args
49
+ ret = nil
50
+ time = Benchmark.realtime do
51
+ ret = super
52
+ end
53
+ GeneralLog.general_log.push(sql, params || [], caller_locations, time)
54
+ ret
55
+ end
46
56
  end
47
57
  end
48
58
  end
@@ -1,7 +1,7 @@
1
1
  module PG
2
2
  class Connection
3
3
  module GeneralLog
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
6
6
  end
7
7
  end
@@ -122,6 +122,30 @@ module PGConnectionGeneralLogTest
122
122
  end
123
123
  end
124
124
 
125
+ def test_async_values(t)
126
+ db_init
127
+ ret = @client.async_exec("SELECT * FROM users WHERE name = '#{'hoge'}'").first
128
+ @client.async_exec("SELECT * FROM users WHERE name = '#{'bar'}'")
129
+ @client.async_exec("SELECT * FROM users WHERE name = '#{'foo'}'")
130
+
131
+ if PG::Connection::GeneralLog.general_log.length != 3
132
+ t.error("expect log length 3 got #{PG::Connection::GeneralLog.general_log.length}")
133
+ end
134
+ if PG::Connection::GeneralLog.general_log.any?{|log| !log.is_a?(PG::Connection::GeneralLog::Log)}
135
+ t.error("expect all collection item is instance of PG::Connection::GeneralLog::Log got #{PG::Connection::GeneralLog.general_log.map(&:class).uniq}")
136
+ end
137
+ expect = { 'id' => '1', 'name' => 'hoge', 'password' => 'cheap-pass' }
138
+ if ret != expect
139
+ t.error("expect exec output not change from #{expect} got #{ret}")
140
+ end
141
+ unless PG::Connection::GeneralLog.general_log.first.format =~ /^SQL\t\(\d+\.\d+ms\)\tSELECT \* FROM users WHERE name = 'hoge'\t\[\]$/
142
+ t.error("expect log format not correct got `#{PG::Connection::GeneralLog.general_log.first.format}`")
143
+ end
144
+ unless PG::Connection::GeneralLog.general_log.first.format(true) =~ /^SQL\t\(\d+\.\d+ms\)\tSELECT \* FROM users WHERE name = 'hoge'\t\[\].+in `test_async_values'$/
145
+ t.error("expect log format not correct got `#{PG::Connection::GeneralLog.general_log.first.format(true)}`")
146
+ end
147
+ end
148
+
125
149
  def test_log_class(t)
126
150
  if PG::Connection::GeneralLog::Log.members != %i[sql args backtrace time]
127
151
  t.error("expect PG::Connection::GeneralLog::Log.members is [:sql, :args, :backtrace, :time] got #{PG::Connection::GeneralLog::Log.members}")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg-connection-general_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - abcang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-18 00:00:00.000000000 Z
11
+ date: 2017-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg