activetokyocabinet 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -27,7 +27,7 @@ see http://gemcutter.org/gems/activetokyocabinet
27
27
  adapter: tokyocabinet
28
28
  database: path_of_database_directory
29
29
  # ~~~~~~~~~
30
- # TokyoCabinet
30
+ # TokyoTyrant
31
31
  development:
32
32
  adapter: tokyotyrant
33
33
  database:
@@ -83,3 +83,6 @@ see http://gemcutter.org/gems/activetokyocabinet
83
83
  render :text => 'hello'
84
84
  end
85
85
  end
86
+
87
+ == Related article
88
+ * http://d.hatena.ne.jp/winebarrel/20100106/p1
@@ -28,7 +28,10 @@ module ActiveRecord
28
28
  next if rcols.nil?
29
29
 
30
30
  unless select_list.nil? or select_list.empty?
31
- rcols = select_list.each {|k| r[k] = rcols[k] }
31
+ rcols = select_list.each do |k|
32
+ k = k.split('.').last
33
+ r[k] = rcols[k]
34
+ end
32
35
  end
33
36
 
34
37
  rcols['id'] = rkey
@@ -57,6 +60,7 @@ module ActiveRecord
57
60
  cols = {}
58
61
 
59
62
  keys.zip(vals).each do |k, v|
63
+ k.split('.').last
60
64
  cols[k] = v.to_s
61
65
  end
62
66
 
@@ -82,6 +86,7 @@ module ActiveRecord
82
86
  rcols = tdb.get(rkey)
83
87
 
84
88
  set_clause_list.each do |k, v|
89
+ k.split('.').last
85
90
  rcols[k] = v.to_s
86
91
  end
87
92
 
@@ -105,9 +110,6 @@ module ActiveRecord
105
110
  parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
106
111
 
107
112
  tdbopen(parsed_sql) do |tdb|
108
- rkeys(tdb, parsed_sql)
109
- set_clause_list = parsed_sql[:set_clause_list]
110
-
111
113
  rkeys(tdb, parsed_sql).each do |rkey|
112
114
  rownum += 1
113
115
 
@@ -134,6 +136,7 @@ module ActiveRecord
134
136
 
135
137
  condition.each do |cond|
136
138
  name, op, expr = cond.values_at(:name, :op, :expr)
139
+ name = name.split('.').last
137
140
  op = @query_klass.const_get(op)
138
141
  expr = expr.kind_of?(Array) ? expr.join(' ') : expr.to_s
139
142
  qry.addcond(name, op, expr)
@@ -4,8 +4,8 @@ require 'tokyocabinet'
4
4
  module ActiveRecord
5
5
  class Base
6
6
  def self.tokyocabinet_connection(config)
7
- unless config[:database]
8
- raise ArgumentError, "No database file specified. Missing argument: database"
7
+ unless config[:database].kind_of?(String)
8
+ raise ArgumentError, "Incorrect argument: database"
9
9
  end
10
10
 
11
11
  if Object.const_defined?(:RAILS_ROOT)
@@ -4,8 +4,8 @@ require 'tokyotyrant'
4
4
  module ActiveRecord
5
5
  class Base
6
6
  def self.tokyotyrant_connection(config)
7
- unless config[:database]
8
- raise ArgumentError, "No database file specified. Missing argument: database"
7
+ unless config[:database].kind_of?(Hash)
8
+ raise ArgumentError, "Incorrect argument: database"
9
9
  end
10
10
 
11
11
  ConnectionAdapters::TokyoTyrantAdapter.new({}, logger, config)
@@ -19,7 +19,11 @@ module ActiveRecord
19
19
  @database = {}
20
20
 
21
21
  config.fetch(:database).map do |table_name, attribute|
22
- @database[table_name] = {
22
+ attribute.keys.each do |k|
23
+ attribute[k.to_s] = attribute[k]
24
+ end
25
+
26
+ @database[table_name.to_s] = {
23
27
  :host => attribute.fetch('host').to_s,
24
28
  :port => attribute.fetch('port', 0).to_i,
25
29
  :timeout => attribute.fetch('timeout', 0).to_i,
@@ -44,6 +48,10 @@ module ActiveRecord
44
48
  def tdbopen(parsed_sql)
45
49
  table_name = parsed_sql[:table]
46
50
 
51
+ unless table_exists?(table_name)
52
+ raise "Table does not exist: #{table_name}"
53
+ end
54
+
47
55
  unless (tdb = @connection[table_name])
48
56
  host, port, timeout = @database.fetch(table_name).values_at(:host, :port, :timeout)
49
57
  tdb = TokyoTyrant::RDBTBL::new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activetokyocabinet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-06 00:00:00 +09:00
12
+ date: 2010-01-08 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency