activetokyocabinet 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -15,31 +15,16 @@ module ActiveRecord
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def select(sql, name = nil)
|
18
|
-
rows =
|
18
|
+
rows = nil
|
19
19
|
|
20
20
|
log(sql, name) do
|
21
21
|
parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
|
22
22
|
|
23
23
|
tdbopen(parsed_sql) do |tdb|
|
24
|
-
select_list = parsed_sql[:select_list]
|
25
|
-
|
26
24
|
if (count = parsed_sql[:count])
|
27
|
-
rows = [{count =>
|
25
|
+
rows = [{count => rnum(tdb, parsed_sql)}]
|
28
26
|
else
|
29
|
-
|
30
|
-
rcols = tdb.get(rkey)
|
31
|
-
next if rcols.nil?
|
32
|
-
|
33
|
-
unless select_list.nil? or select_list.empty?
|
34
|
-
rcols = select_list.each do |k|
|
35
|
-
k = k.split('.').last
|
36
|
-
r[k] = rcols[k]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
rcols['id'] = rkey.to_i
|
41
|
-
rows << rcols
|
42
|
-
end
|
27
|
+
rows = search(tdb, parsed_sql)
|
43
28
|
end
|
44
29
|
end
|
45
30
|
end
|
@@ -104,35 +89,59 @@ module ActiveRecord
|
|
104
89
|
end
|
105
90
|
|
106
91
|
def delete_sql(sql, name = nil)
|
107
|
-
rownum = 0
|
108
|
-
|
109
92
|
log(sql, name) do
|
110
93
|
parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
|
111
94
|
|
112
95
|
tdbopen(parsed_sql) do |tdb|
|
113
|
-
|
114
|
-
|
96
|
+
unless query(tdb, parsed_sql).searchout
|
97
|
+
ecode = tdb.ecode
|
98
|
+
raise '%s: %s' % [tdb.errmsg(ecode), sql]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
115
102
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
103
|
+
# XXX:
|
104
|
+
return 1
|
105
|
+
end
|
106
|
+
|
107
|
+
def search(tdb, parsed_sql)
|
108
|
+
rows = []
|
109
|
+
select_list = parsed_sql[:select_list]
|
110
|
+
|
111
|
+
rkeys(tdb, parsed_sql).each do |rkey|
|
112
|
+
rcols = tdb.get(rkey)
|
113
|
+
next if rcols.nil?
|
114
|
+
|
115
|
+
unless select_list.nil? or select_list.empty?
|
116
|
+
rcols = select_list.each do |k|
|
117
|
+
k = k.split('.').last
|
118
|
+
r[k] = rcols[k]
|
120
119
|
end
|
121
120
|
end
|
121
|
+
|
122
|
+
rcols['id'] = rkey.to_i
|
123
|
+
rows << rcols
|
122
124
|
end
|
123
125
|
|
124
|
-
return
|
126
|
+
return rows
|
127
|
+
end
|
128
|
+
private :search
|
129
|
+
|
130
|
+
def cond?(condition)
|
131
|
+
condition.kind_of?(Array) and condition.all? {|i| i.kind_of?(Hash) }
|
125
132
|
end
|
133
|
+
private :cond?
|
126
134
|
|
127
135
|
def rkeys(tdb, parsed_sql)
|
128
136
|
condition = parsed_sql[:condition] || []
|
129
137
|
|
130
|
-
unless
|
138
|
+
unless cond?(condition)
|
131
139
|
return [condition].flatten
|
132
140
|
end
|
133
141
|
|
134
142
|
query(tdb, parsed_sql).search
|
135
143
|
end
|
144
|
+
private :rkeys
|
136
145
|
|
137
146
|
def query(tdb, parsed_sql)
|
138
147
|
condition, order, limit, offset = parsed_sql.values_at(:condition, :order, :limit, :offset)
|
@@ -61,14 +61,14 @@ module ActiveRecord
|
|
61
61
|
end
|
62
62
|
private :tdbpath
|
63
63
|
|
64
|
-
def
|
64
|
+
def rnum(tdb, parsed_sql)
|
65
65
|
if (parsed_sql[:condition] || []).empty?
|
66
66
|
tdb.rnum
|
67
67
|
else
|
68
68
|
rkeys(tdb, parsed_sql).length
|
69
69
|
end
|
70
70
|
end
|
71
|
-
private :
|
71
|
+
private :rnum
|
72
72
|
|
73
73
|
def setindex(table_name, name, type)
|
74
74
|
type = {
|
@@ -67,14 +67,36 @@ module ActiveRecord
|
|
67
67
|
end
|
68
68
|
private :tdbopen
|
69
69
|
|
70
|
-
def
|
70
|
+
def search(tdb, parsed_sql)
|
71
|
+
condition = parsed_sql[:condition] || []
|
72
|
+
|
73
|
+
unless cond?(condition)
|
74
|
+
super(tdb, parsed_sql)
|
75
|
+
else
|
76
|
+
select_list = parsed_sql[:select_list]
|
77
|
+
|
78
|
+
if select_list.nil? or select_list.empty?
|
79
|
+
names = nil
|
80
|
+
else
|
81
|
+
names = select_list.map {|i| i.split('.').last }
|
82
|
+
end
|
83
|
+
|
84
|
+
rows = query(tdb, parsed_sql).searchget
|
85
|
+
rows.each {|i| i['id'] = i[""].to_i }
|
86
|
+
|
87
|
+
return rows
|
88
|
+
end
|
89
|
+
end
|
90
|
+
private :search
|
91
|
+
|
92
|
+
def rnum(tdb, parsed_sql)
|
71
93
|
if (parsed_sql[:condition] || []).empty?
|
72
94
|
tdb.rnum
|
73
95
|
else
|
74
96
|
query(tdb, parsed_sql).searchcount
|
75
97
|
end
|
76
98
|
end
|
77
|
-
private :
|
99
|
+
private :rnum
|
78
100
|
|
79
101
|
def setindex(table_name, name, type)
|
80
102
|
type = {
|
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.
|
4
|
+
version: 0.1.7
|
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-
|
12
|
+
date: 2010-01-12 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|