rffdb 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rffdb/document.rb +6 -4
- data/lib/rffdb/document_collection.rb +5 -1
- data/lib/rffdb/index.rb +13 -0
- data/lib/rffdb/storage_engine.rb +2 -2
- data/lib/rffdb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc4467ccd374f36f1a5793286254b9e0f5e0d7ca
|
4
|
+
data.tar.gz: ecd7ed58e3635b2f9ca2494b6dfb69f32f772db8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d35ee19ff25eefb271ff21df71882056e8a989be0024ab261f63b094cc0943c9e68f0671e09bb6410fb668e0ceecb38f1b2a73492a097ad770b1821a3a72dc83
|
7
|
+
data.tar.gz: f8dc378ee8c4e67a9ae4bfb80c4a30db378d65af261e00a96cfdb20006cdfebc1c865dd291a3a15bef2bf87d5a4d253011321d972fd3759c6534de193f1fee42
|
data/lib/rffdb/document.rb
CHANGED
@@ -202,14 +202,16 @@ module RubyFFDB
|
|
202
202
|
|
203
203
|
# Query for Documents based on an attribute
|
204
204
|
# @see DocumentCollection#where
|
205
|
-
def self.where(attribute, value,
|
206
|
-
if
|
205
|
+
def self.where(attribute, value, comp_op = '==')
|
206
|
+
if indexed_column?(attribute)
|
207
207
|
DocumentCollection.new(
|
208
|
-
storage.index_lookup(self, attribute, value).collect
|
208
|
+
storage.index_lookup(self, attribute, value, comp_op).collect do |did|
|
209
|
+
load(did)
|
210
|
+
end,
|
209
211
|
self
|
210
212
|
)
|
211
213
|
else
|
212
|
-
all.where(attribute, value,
|
214
|
+
all.where(attribute, value, comp_op)
|
213
215
|
end
|
214
216
|
end
|
215
217
|
|
@@ -133,7 +133,11 @@ module RubyFFDB
|
|
133
133
|
end
|
134
134
|
self.class.new(
|
135
135
|
@list.collect do |item|
|
136
|
-
|
136
|
+
if item.send(attribute).nil?
|
137
|
+
nil
|
138
|
+
else
|
139
|
+
item if item.send(attribute).send(comparison_method.to_sym, value)
|
140
|
+
end
|
137
141
|
end.compact,
|
138
142
|
@type
|
139
143
|
)
|
data/lib/rffdb/index.rb
CHANGED
@@ -54,10 +54,23 @@ module RubyFFDB
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
# Complex queries of the index can be done with this method
|
58
|
+
# @return [Array] An array of object ids matching the query
|
59
|
+
def query(q, operator = '==')
|
60
|
+
datum = []
|
61
|
+
GDBM.open(file_path, 0664, GDBM::READER) do |index|
|
62
|
+
index.each_pair do |key, value|
|
63
|
+
datum += Marshal.load(value) if key.send(operator.to_sym, q)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
datum.uniq.compact
|
67
|
+
end
|
68
|
+
|
57
69
|
# Evict keys (column data) with no associated Documents
|
58
70
|
def prune
|
59
71
|
GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
|
60
72
|
index.delete_if { |key, value| Marshal.load(value).empty? }
|
73
|
+
index.reorganize # clear up wasted disk space
|
61
74
|
end
|
62
75
|
end
|
63
76
|
end
|
data/lib/rffdb/storage_engine.rb
CHANGED
@@ -161,9 +161,9 @@ module RubyFFDB
|
|
161
161
|
# @param type [Document] the document type
|
162
162
|
# @param column [String,Symbol] the column / attribute for the index
|
163
163
|
# @param data [String] column data to use for the lookup
|
164
|
-
def self.index_lookup(type, column, data)
|
164
|
+
def self.index_lookup(type, column, data, operator = '==')
|
165
165
|
i = index(type, column)
|
166
|
-
i.
|
166
|
+
i.query(data, operator)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
data/lib/rffdb/version.rb
CHANGED