simple-sql 0.5.6 → 0.5.7
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/lib/simple/sql/connection/insert.rb +2 -2
- data/lib/simple/sql/connection_adapter.rb +3 -3
- data/lib/simple/sql/logging.rb +4 -4
- data/lib/simple/sql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d0a4a51efce9ee15d5162be03fc204009535caab84adbec768090dc1b33358a
|
4
|
+
data.tar.gz: 161edc1c790492df3c7fec4a0933826adcd6757d1a267fa119dbe75cab856416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
66
|
+
@connection.transaction do
|
67
67
|
records.map do |record|
|
68
|
-
|
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 =
|
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
|
data/lib/simple/sql/logging.rb
CHANGED
@@ -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 =
|
91
|
+
query_plan = connection.all "EXPLAIN #{sql}", *args
|
92
92
|
|
93
93
|
<<~MSG
|
94
94
|
=== slow query detected: (#{'%.3f secs' % runtime}) ===================================================================================
|
data/lib/simple/sql/version.rb
CHANGED