rdo 0.1.0 → 0.1.1
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.
- data/lib/rdo/colored_logger.rb +19 -7
- data/lib/rdo/connection.rb +10 -2
- data/lib/rdo/result.rb +8 -0
- data/lib/rdo/statement.rb +10 -2
- data/lib/rdo/version.rb +1 -1
- data/spec/rdo/statement_spec.rb +1 -1
- metadata +2 -2
data/lib/rdo/colored_logger.rb
CHANGED
@@ -10,16 +10,28 @@ require "logger"
|
|
10
10
|
module RDO
|
11
11
|
# A Logger that outputs using color to highlight errors etc.
|
12
12
|
class ColoredLogger < Logger
|
13
|
-
def
|
14
|
-
|
15
|
-
self.formatter =
|
13
|
+
def formatter
|
14
|
+
@formatter ||=
|
16
15
|
Proc.new do |severity, time, prog, msg|
|
17
16
|
case severity
|
18
|
-
when "DEBUG"
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
when "DEBUG"
|
18
|
+
format_sql(msg)
|
19
|
+
when "FATAL"
|
20
|
+
format_err(msg)
|
21
|
+
else
|
22
|
+
"%s ~ %s" % [severity, msg]
|
23
|
+
end + $/
|
22
24
|
end
|
23
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def format_sql(sql)
|
30
|
+
"\033[35mSQL\033[0m \033[36m~\033[0m %s" % sql
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_err(msg)
|
34
|
+
"\033[31mERROR ~ %s\033[0m" % msg
|
35
|
+
end
|
24
36
|
end
|
25
37
|
end
|
data/lib/rdo/connection.rb
CHANGED
@@ -95,9 +95,17 @@ module RDO
|
|
95
95
|
# @return [Result]
|
96
96
|
# the result of the query
|
97
97
|
def execute(statement, *bind_values)
|
98
|
-
|
98
|
+
t = Time.now
|
99
|
+
@driver.execute(statement, *bind_values).tap do |rs|
|
100
|
+
rs.info[:execution_time] ||= Time.now - t
|
99
101
|
if logger.debug?
|
100
|
-
logger.debug(
|
102
|
+
logger.debug(
|
103
|
+
"(%.6fs) %s%s" % [
|
104
|
+
rs.execution_time,
|
105
|
+
statement,
|
106
|
+
("<Bind: #{bind_values.inspect}>" unless bind_values.empty?)
|
107
|
+
]
|
108
|
+
)
|
101
109
|
end
|
102
110
|
end
|
103
111
|
rescue RDO::Exception => e
|
data/lib/rdo/result.rb
CHANGED
@@ -85,6 +85,14 @@ module RDO
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
# Get the time spent processing the statement.
|
89
|
+
#
|
90
|
+
# @return [Float]
|
91
|
+
# the time in seconds spent executing the query
|
92
|
+
def execution_time
|
93
|
+
info[:execution_time].to_f
|
94
|
+
end
|
95
|
+
|
88
96
|
# Iterate over all rows returned by the connection.
|
89
97
|
#
|
90
98
|
# For each row, a Symbol-keyed Hash is yielded into the block.
|
data/lib/rdo/statement.rb
CHANGED
@@ -31,9 +31,17 @@ module RDO
|
|
31
31
|
# @param [Object...] args
|
32
32
|
# bind parameters to use in place of '?'
|
33
33
|
def execute(*bind_values)
|
34
|
-
|
34
|
+
t = Time.now
|
35
|
+
@executor.execute(*bind_values).tap do |rs|
|
36
|
+
rs.info[:execution_time] ||= Time.now - t
|
35
37
|
if logger.debug?
|
36
|
-
logger.debug(
|
38
|
+
logger.debug(
|
39
|
+
"(%.6fs) %s %s" % [
|
40
|
+
rs.execution_time,
|
41
|
+
command,
|
42
|
+
("<Bind: #{bind_values.inspect}>" unless bind_values.empty?)
|
43
|
+
]
|
44
|
+
)
|
37
45
|
end
|
38
46
|
end
|
39
47
|
rescue RDO::Exception => e
|
data/lib/rdo/version.rb
CHANGED
data/spec/rdo/statement_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe RDO::Statement do
|
|
17
17
|
|
18
18
|
describe "#execute" do
|
19
19
|
let(:executor) { double(command: "SELECT * FROM bob WHERE ?", execute: result) }
|
20
|
-
let(:result) { stub(:result) }
|
20
|
+
let(:result) { stub(:result, info: {}, execution_time: 0.0) }
|
21
21
|
|
22
22
|
it "delegates to the executor" do
|
23
23
|
executor.should_receive(:execute).with(1, 2).and_return(result)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|