rffdb 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.
- checksums.yaml +4 -4
- data/lib/rffdb/document.rb +1 -3
- data/lib/rffdb/index.rb +11 -0
- data/lib/rffdb/storage_engine.rb +26 -0
- data/lib/rffdb/storage_engines/json_engine.rb +4 -0
- data/lib/rffdb/storage_engines/yaml_engine.rb +3 -0
- data/lib/rffdb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15e3dfa89e73ac4a581282ea7b7cbcc67f463786
|
4
|
+
data.tar.gz: 718a382be6454b1abcf2a000c506fefb88d7f834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b62bc3138cfb47330c901c8dc380e7f776c7ff7fb93bff8898832953b0a3951af12802b24f7b3b6dafec1f10d009ea14d0c0f323cc2c0d618a44e754ca4e17ba
|
7
|
+
data.tar.gz: e2e86990656d89f1eaf3db4596a79f5b732dac3d53be1b54ca5dbc2a03a662a55bc5ba22315d24ffd7b0fffd2d40c82f1a9a38253022f502146b7a13331cdca8
|
data/lib/rffdb/document.rb
CHANGED
@@ -205,7 +205,7 @@ module RubyFFDB
|
|
205
205
|
def self.where(attribute, value, comparison_method = '==')
|
206
206
|
if comparison_method.to_s == '==' && indexed_column?(attribute)
|
207
207
|
DocumentCollection.new(
|
208
|
-
storage.
|
208
|
+
storage.index_lookup(self, attribute, value).collect { |did| load(did) },
|
209
209
|
self
|
210
210
|
)
|
211
211
|
else
|
@@ -260,9 +260,7 @@ module RubyFFDB
|
|
260
260
|
@read_lock.synchronize do
|
261
261
|
@write_lock.synchronize do
|
262
262
|
if valid
|
263
|
-
storage.index(self.class, key).delete(@data[key.to_s], id) if indexed_column?(key)
|
264
263
|
@data[key.to_s] = args.last
|
265
|
-
storage.index(self.class, key).put(args.last, id) if indexed_column?(key)
|
266
264
|
end
|
267
265
|
end
|
268
266
|
end
|
data/lib/rffdb/index.rb
CHANGED
@@ -31,6 +31,7 @@ module RubyFFDB
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
# Remove a specific Document association with a key
|
34
35
|
def delete(key, value)
|
35
36
|
previous = get(key)
|
36
37
|
GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
|
@@ -38,16 +39,26 @@ module RubyFFDB
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
# Remove all associations with a specific key (column data)
|
41
43
|
def truncate(key)
|
42
44
|
GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
|
43
45
|
index.delete(key.to_s)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
49
|
+
# All keys (column data) in the index
|
50
|
+
# @return [Array] An array of object ids
|
47
51
|
def keys
|
48
52
|
GDBM.open(file_path, 0664, GDBM::READER) do |index|
|
49
53
|
index.keys
|
50
54
|
end
|
51
55
|
end
|
56
|
+
|
57
|
+
# Evict keys (column data) with no associated Documents
|
58
|
+
def prune
|
59
|
+
GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
|
60
|
+
index.delete_if { |key, value| Marshal.load(value).empty? }
|
61
|
+
end
|
62
|
+
end
|
52
63
|
end
|
53
64
|
end
|
data/lib/rffdb/storage_engine.rb
CHANGED
@@ -139,5 +139,31 @@ module RubyFFDB
|
|
139
139
|
@indexes[type] ||= {}
|
140
140
|
@indexes[type][column.to_sym] ||= Index.new(type, column.to_sym)
|
141
141
|
end
|
142
|
+
|
143
|
+
# Update the index for a column
|
144
|
+
# @param type [Document] the document type
|
145
|
+
# @param column [String,Symbol] the column / attribute for the index
|
146
|
+
# @param object_id [Object] unique identifier for the document
|
147
|
+
# @param data [String] column data to be stored
|
148
|
+
def self.index_update(type, column, object_id, data)
|
149
|
+
i = index(type, column)
|
150
|
+
# Delete all previous entries in this index
|
151
|
+
oldkeys = i.keys.collect { |k| k if i.get(k).include?(object_id) }.compact
|
152
|
+
oldkeys.each do |k|
|
153
|
+
i.delete(k, object_id)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Add the new indexed version
|
157
|
+
i.put(data, object_id)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Query an index for column data
|
161
|
+
# @param type [Document] the document type
|
162
|
+
# @param column [String,Symbol] the column / attribute for the index
|
163
|
+
# @param data [String] column data to use for the lookup
|
164
|
+
def self.index_lookup(type, column, data)
|
165
|
+
i = index(type, column)
|
166
|
+
i.get(data)
|
167
|
+
end
|
142
168
|
end
|
143
169
|
end
|
@@ -11,6 +11,10 @@ module RubyFFDB
|
|
11
11
|
File.open(path, 'w') do |file|
|
12
12
|
file.puts JSON.dump(data)
|
13
13
|
end
|
14
|
+
# Update all indexed columns
|
15
|
+
type.structure.collect {|k,v| k if v[:index] }.compact.each do |col|
|
16
|
+
index_update(type, col, object_id, data[col.to_s])
|
17
|
+
end
|
14
18
|
cache_store(type, object_id, data)
|
15
19
|
end
|
16
20
|
true
|
@@ -11,6 +11,9 @@ module RubyFFDB
|
|
11
11
|
File.open(path, 'w') do |file|
|
12
12
|
file.puts YAML.dump(data)
|
13
13
|
end
|
14
|
+
type.structure.collect {|k,v| k if v[:index] }.compact.each do |col|
|
15
|
+
index_update(type, col, object_id, data[col.to_s])
|
16
|
+
end
|
14
17
|
cache_store(type, object_id, data)
|
15
18
|
end
|
16
19
|
true
|
data/lib/rffdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rffdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gnagy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|