simple-sql 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41c7ddee7b4212971585f7b12249d3eb37a7dc5f2c4d4553404b30bc496c2f07
4
- data.tar.gz: e24b684824bdfe76191fc347ed038588bd26a5fc2860a551a7270c44c681f665
3
+ metadata.gz: 0d0a4a51efce9ee15d5162be03fc204009535caab84adbec768090dc1b33358a
4
+ data.tar.gz: 161edc1c790492df3c7fec4a0933826adcd6757d1a267fa119dbe75cab856416
5
5
  SHA512:
6
- metadata.gz: 69fb213cb019c41e7425423b7f7791de730a70e4beb4f5aeff0a1179a927efa8e249ff27189160c5fca1bc4854c7b00eac395e0e0c257a9dc591c38663839841
7
- data.tar.gz: 1f99c960752ba291a1f4a6d1c9a31e9075990acd70c903d43e37cbd28ff01ba7c33c17b9a31f0903dfa00193386606644a889d00999834970deb343946d0b79c
6
+ metadata.gz: 67be2270fd3b1e456bc573aca3c6afa25bbb070766edbf11bdf4bece2037fd91f636d12b1861f8899106874e995808e876f5fa13f697dc24508ea66bac7ff8f8
7
+ data.tar.gz: f06e19bd48a24dded429f6155442748944ee3f61e0e1e5cfb58248a64fa2f0133781d9bd49a90897271cb759a6f1fe1c86d55b8e88d162cdda96f8f9a90e4420
@@ -63,9 +63,9 @@ class Simple::SQL::Connection
63
63
  end
64
64
 
65
65
  def insert(records:)
66
- SQL.transaction do
66
+ @connection.transaction do
67
67
  records.map do |record|
68
- SQL.ask @sql, *record.values_at(*@columns), into: @into
68
+ @connection.ask @sql, *record.values_at(*@columns), into: @into
69
69
  end
70
70
  end
71
71
  end
@@ -11,7 +11,7 @@ module Simple::SQL::ConnectionAdapter
11
11
  # arguments - since the pg client does not support this - but it allows to
12
12
  # run multiple sql statements separated by ";"
13
13
  def exec(sql)
14
- Logging.with_logged_query sql do
14
+ Logging.with_logged_query self, sql do
15
15
  raw_connection.exec sql
16
16
  end
17
17
  end
@@ -91,7 +91,7 @@ module Simple::SQL::ConnectionAdapter
91
91
 
92
92
  # returns an Array [min_cost, max_cost] based on the database's estimation
93
93
  def costs(sql, *args)
94
- explanation_first = Simple::SQL.ask "EXPLAIN #{sql}", *args
94
+ explanation_first = ask "EXPLAIN #{sql}", *args
95
95
  unless explanation_first =~ /cost=(\d+(\.\d+))\.+(\d+(\.\d+))/
96
96
  raise "Cannot determine cost"
97
97
  end
@@ -129,7 +129,7 @@ module Simple::SQL::ConnectionAdapter
129
129
  sql = sql_or_scope
130
130
  end
131
131
 
132
- Logging.with_logged_query sql, *args do
132
+ Logging.with_logged_query self, sql, *args do
133
133
  raw_connection.exec_params(sql, Encoder.encode_args(raw_connection, args))
134
134
  end
135
135
  end
@@ -54,7 +54,7 @@ module Simple
54
54
  @slow_query_treshold = slow_query_treshold
55
55
  end
56
56
 
57
- def with_logged_query(sql, *args, &_block)
57
+ def with_logged_query(connection, sql, *args, &_block)
58
58
  r0 = Time.now
59
59
  rv = yield
60
60
  runtime = Time.now - r0
@@ -64,7 +64,7 @@ module Simple
64
64
  end
65
65
 
66
66
  if slow_query_treshold && runtime > slow_query_treshold
67
- log_slow_query(sql, *args, runtime: runtime)
67
+ log_slow_query(connection, sql, *args, runtime: runtime)
68
68
  end
69
69
 
70
70
  rv
@@ -81,14 +81,14 @@ module Simple
81
81
 
82
82
  Formatting = ::Simple::SQL::Formatting
83
83
 
84
- def log_slow_query(sql, *args, runtime:)
84
+ def log_slow_query(connection, sql, *args, runtime:)
85
85
  # Do not try to analyze an EXPLAIN query. This prevents endless recursion here
86
86
  # (and, in general, would not be useful anyways.)
87
87
  return if sql =~ /^EXPLAIN /
88
88
 
89
89
  log_multiple_lines ::Logger::WARN, prefix: "[sql-slow]" do
90
90
  formatted_query = Formatting.format(sql, *args)
91
- query_plan = ::Simple::SQL.all "EXPLAIN #{sql}", *args
91
+ query_plan = connection.all "EXPLAIN #{sql}", *args
92
92
 
93
93
  <<~MSG
94
94
  === slow query detected: (#{'%.3f secs' % runtime}) ===================================================================================
@@ -1,5 +1,5 @@
1
1
  module Simple
2
2
  module SQL
3
- VERSION = "0.5.6"
3
+ VERSION = "0.5.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel