monetdb 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjA0NTQ0M2UwZDAxMjUxNjFiZTFkMjc5MjUzYmY2MWIyNWY2MTc1ZQ==
4
+ ZWIxMjU2MTVlNWE5OGI2NmM5OTM5MjljZWVkNTQ2NzViOTUxMDAyOA==
5
5
  data.tar.gz: !binary |-
6
- NjM3MWRlZGQ4MmI5YjIwZTdkYjM0MmEzNzQ3M2Y4NDJjZmRjZjUwZA==
6
+ ZmU2YTQ4ZDhkOTk0NGVlMDY0ZTg4ODU4NjA5MThhM2U1YTc1ZjNmZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mjc4ZGU5NzJkYWUzZGQ3ZDIzODVkN2UyZGMzMzUyZmFiNWYyNTZiY2YxMzU5
10
- MmE4OWRhMWE5Mjk2Yjc4YjE2M2VkYTQ2ZTU2ZjQ5ODY3NDAzNzg1YTJhOGIz
11
- ZWM1ODdmOTg1MjhjZTljNDg3NmU1OWFhZjEyYWQyZDhmOWEyYjM=
9
+ NjJmYzAxZGQ1MmY0ZDk4OWU3MzViNzYyYTNhMTVmYjhiZWEyZWM2YjZlMmYw
10
+ YWVhOTA5NWM1YWNlZmM3NTc5ZDJhNjQ1MDU4NWJlZTQyYTIwZWEyNzcxNjM4
11
+ N2VlZTc2ZGY4OGM4N2Y2MjBiYjZiYmFhYzU3Y2JiMzIxNTU2ZmU=
12
12
  data.tar.gz: !binary |-
13
- ZjkxYWY4ZTQwYWU5MWZiNzk0MmE2NzJkZTYzYzRiZjFlMTE4NDA1NmY4YWU5
14
- N2Y5Y2UyYTVjYmEzMmFhMDE3ZDU3YjE0YzA3ODVjYjg3YWVlZGZkMmUzMmRm
15
- MzI2ZmViNGQxNjcwOTA4Mjc2MTc1MmQ4ZGE2NmQ5NTRiZmY4YzE=
13
+ NDM2MWJlNjg0NTkzNTY5ZjhmNTdhM2E0M2I4MjIzZDYyZjMwMjdjN2VhMmY3
14
+ OGU1MzQ0YWE2NzczNjhjODAyOTI3MTgyZTExYTc5Yzg1OGEwOGNlN2JkY2Y1
15
+ NGI2YTg3MjUxYjkxYWFmMWVmNmIyYjY3ZmVmNzE0YzhlMDI1MGU=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = MonetDB CHANGELOG
2
2
 
3
+ == Version 0.2.3 (October 22, 2014)
4
+
5
+ * Dropped activesupport dependency
6
+ * Extracted logging related method to MonetDB::Connection::Logger
7
+ * Logging query info
8
+
3
9
  == Version 0.2.2 (October 13, 2014)
4
10
 
5
11
  * Added MonetDB::Connection#select_values
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/lib/monetdb.rb CHANGED
@@ -1,5 +1,3 @@
1
- require "active_support/core_ext/hash/reverse_merge"
2
-
3
1
  require "monetdb/connection"
4
2
  require "monetdb/error"
5
3
  require "monetdb/version"
@@ -3,6 +3,7 @@ require "monetdb/connection/io"
3
3
  require "monetdb/connection/messages"
4
4
  require "monetdb/connection/setup"
5
5
  require "monetdb/connection/query"
6
+ require "monetdb/connection/logger"
6
7
 
7
8
  module MonetDB
8
9
  class Connection
@@ -11,6 +12,7 @@ module MonetDB
11
12
  include Messages
12
13
  include Setup
13
14
  include Query
15
+ include Logger
14
16
 
15
17
  Q_TABLE = "1" # SELECT statement
16
18
  Q_UPDATE = "2" # INSERT/UPDATE statement
@@ -80,9 +82,5 @@ module MonetDB
80
82
  @socket
81
83
  end
82
84
 
83
- def log(type, msg)
84
- MonetDB.logger.send(type, msg) if MonetDB.logger
85
- end
86
-
87
85
  end
88
86
  end
@@ -0,0 +1,12 @@
1
+ module MonetDB
2
+ class Connection
3
+ module Logger
4
+ private
5
+
6
+ def log(type, msg)
7
+ MonetDB.logger.send(type, msg) if MonetDB.logger
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -5,16 +5,20 @@ module MonetDB
5
5
  def query(statement)
6
6
  raise ConnectionError, "Not connected to server" unless connected?
7
7
 
8
+ start = Time.now
9
+
8
10
  write "s#{statement};"
9
11
  response = read.split("\n")
10
12
 
13
+ log :info, "\n SQL (#{((Time.now - start) * 1000).round(1)}ms) #{statement}"
14
+
11
15
  query_header, table_header = extract_headers!(response)
12
16
 
13
17
  if query_header[:type] == Q_TABLE
14
18
  unless query_header[:rows] == response.size
15
19
  raise QueryError, "Amount of fetched rows does not match header value (#{response.size} instead of #{query_header[:rows]})"
16
20
  end
17
- response = parse_rows(table_header, response.join("\n"))
21
+ response = parse_rows(query_header, table_header, response.join("\n"))
18
22
  else
19
23
  response = true
20
24
  end
@@ -83,14 +87,18 @@ module MonetDB
83
87
  {:table_name => table_name, :column_names => column_names, :column_types => column_types, :column_lengths => column_lengths}.freeze
84
88
  end
85
89
 
86
- def parse_rows(table_header, response)
90
+ def parse_rows(query_header, table_header, response)
91
+ start = Time.now
87
92
  column_types = table_header[:column_types]
93
+
88
94
  response.slice(0..-3).split("\t]\n").collect do |row|
89
95
  parsed, values = [], row.slice(1..-1).split(",\t")
90
96
  values.each_with_index do |value, index|
91
97
  parsed << parse_value(column_types[index], value.strip)
92
98
  end
93
99
  parsed
100
+ end.tap do
101
+ log :info, " RUBY (#{((Time.now - start) * 1000).round(1)}ms) [ Rows: #{query_header[:rows]}, Bytesize: #{response.bytesize} bytes ]"
94
102
  end
95
103
  end
96
104
 
@@ -1,7 +1,7 @@
1
1
  module MonetDB
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- TINY = 2
4
+ TINY = 3
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
data/monetdb.gemspec CHANGED
@@ -15,8 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = MonetDB::VERSION
17
17
 
18
- gem.add_dependency "activesupport"
19
-
20
18
  gem.add_development_dependency "rake"
21
19
  gem.add_development_dependency "yard"
22
20
  gem.add_development_dependency "pry"
@@ -0,0 +1,35 @@
1
+ require_relative "../../test_helper"
2
+
3
+ module Unit
4
+ module Connection
5
+ class TestLogger < MiniTest::Test
6
+
7
+ class Connection < SimpleConnection
8
+ include MonetDB::Connection::Logger
9
+ end
10
+
11
+ describe MonetDB::Connection::Logger do
12
+ before do
13
+ @connection = Connection.new
14
+ end
15
+
16
+ describe "#log" do
17
+ describe "when MonetDB.logger" do
18
+ it "delegates to MonetDB.logger" do
19
+ (logger = mock).expects(:info, "Hello world!")
20
+ MonetDB.expects(:logger).returns(logger).twice
21
+ @connection.send :log, :info, "Hello world!"
22
+ end
23
+ end
24
+
25
+ describe "when no MonetDB.logger" do
26
+ it "does nothing" do
27
+ assert_nil @connection.send(:log, :info, "Boo!")
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -7,6 +7,7 @@ module Unit
7
7
  class Connection < SimpleConnection
8
8
  include MonetDB::Connection::Messages
9
9
  include MonetDB::Connection::Query
10
+ include MonetDB::Connection::Logger
10
11
  end
11
12
 
12
13
  describe MonetDB::Connection::Query do
@@ -263,19 +264,23 @@ module Unit
263
264
 
264
265
  describe "#parse_rows" do
265
266
  it "returns an array of hashes" do
267
+ query_header = {
268
+ :rows => 2
269
+ }
270
+
266
271
  table_header = {
267
272
  :column_types => [:varchar, :date, :double]
268
273
  }
269
274
 
270
275
  response = [
271
- "[ \"Paul Engel\",\t1982-08-01,\t19.82\t]",
272
- "[ \"Ken Adams\",\t1980-10-13,\t20.47\t]"
276
+ "[ \"Paul Engel\",\t1982-08-01,\t1709.34\t]",
277
+ "[ \"Ken Adams\",\t1980-10-31,\t2003.47\t]"
273
278
  ].join("\n")
274
279
 
275
280
  assert_equal [
276
- ["Paul Engel", Date.parse("1982-08-01"), 19.82],
277
- ["Ken Adams", Date.parse("1980-10-13"), 20.47]
278
- ], @connection.send(:parse_rows, table_header, response)
281
+ ["Paul Engel", Date.parse("1982-08-01"), 1709.34],
282
+ ["Ken Adams", Date.parse("1980-10-31"), 2003.47]
283
+ ], @connection.send(:parse_rows, query_header, table_header, response)
279
284
  end
280
285
  end
281
286
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monetdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +112,7 @@ files:
126
112
  - lib/monetdb.rb
127
113
  - lib/monetdb/connection.rb
128
114
  - lib/monetdb/connection/io.rb
115
+ - lib/monetdb/connection/logger.rb
129
116
  - lib/monetdb/connection/messages.rb
130
117
  - lib/monetdb/connection/query.rb
131
118
  - lib/monetdb/connection/setup.rb
@@ -138,6 +125,7 @@ files:
138
125
  - test/test_helper/minitest.rb
139
126
  - test/test_helper/simple_connection.rb
140
127
  - test/unit/connection/test_io.rb
128
+ - test/unit/connection/test_logger.rb
141
129
  - test/unit/connection/test_messages.rb
142
130
  - test/unit/connection/test_query.rb
143
131
  - test/unit/connection/test_setup.rb
@@ -172,6 +160,7 @@ test_files:
172
160
  - test/test_helper/minitest.rb
173
161
  - test/test_helper/simple_connection.rb
174
162
  - test/unit/connection/test_io.rb
163
+ - test/unit/connection/test_logger.rb
175
164
  - test/unit/connection/test_messages.rb
176
165
  - test/unit/connection/test_query.rb
177
166
  - test/unit/connection/test_setup.rb