Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Philippe PITTOLI | 19d878e21c | |
Philippe PITTOLI | 179d5e6e17 |
|
@ -1,5 +1,5 @@
|
|||
name: dodb
|
||||
version: 0.5.0
|
||||
version: 0.5.1
|
||||
|
||||
authors:
|
||||
- Luka Vandervelden <lukc@upyum.com>
|
||||
|
|
|
@ -45,7 +45,7 @@ describe "tracking inconsistencies between implementations" do
|
|||
cars_ram0 = SPECDB::RAMOnly(Car).new "-0"
|
||||
cars_ram1 = SPECDB::RAMOnly(Car).new "-1"
|
||||
cars_ram2 = SPECDB::RAMOnly(Car).new "-2"
|
||||
cars_fifo = SPECDB::Common(Car).new "-2", 5
|
||||
cars_fifo = SPECDB::Common(Car).new "-3", 5
|
||||
|
||||
uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords = uncached_indexes cars_ram0
|
||||
cached_searchby_name, cached_searchby_color, cached_searchby_keywords = cached_indexes cars_ram1
|
||||
|
@ -101,3 +101,28 @@ describe "tracking inconsistencies between implementations" do
|
|||
cars_fifo.rm_storage_dir
|
||||
end
|
||||
end
|
||||
|
||||
describe "Errors" do
|
||||
it "Removing an entry which doesn't exist" do
|
||||
db = SPECDB::RAMOnly(Car).new
|
||||
searchby_name, searchby_color, searchby_keywords = uncached_indexes db
|
||||
|
||||
searchby_name.delete?( "doesn't exist").should be_nil # Should not throw an exception.
|
||||
searchby_color.delete?( "doesn't exist").should be_nil # Should not throw an exception.
|
||||
searchby_keywords.delete?("doesn't exist").should be_nil # Should not throw an exception.
|
||||
|
||||
expect_raises DODB::MissingEntry do
|
||||
searchby_name.delete "doesn't exist"
|
||||
end
|
||||
|
||||
expect_raises DODB::MissingEntry do
|
||||
searchby_color.delete "doesn't exist"
|
||||
end
|
||||
|
||||
expect_raises DODB::MissingEntry do
|
||||
searchby_keywords.delete "doesn't exist"
|
||||
end
|
||||
|
||||
db.rm_storage_dir
|
||||
end
|
||||
end
|
||||
|
|
|
@ -438,7 +438,7 @@ abstract class DODB::Storage(V)
|
|||
# Lists all the keys in the database.
|
||||
private def each_key(reversed = false)
|
||||
# Removes the first two "." and ".." directories.
|
||||
keys = Dir.entries(data_path).[2..].map(&.to_i).sort
|
||||
keys = Dir.children(data_path).map(&.to_i).sort
|
||||
(reversed ? keys.reverse : keys).each do |key|
|
||||
yield key
|
||||
end
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
# constantly ask for the same data over and over.
|
||||
#
|
||||
# ```
|
||||
# # Creates a DODB database for common usage (a limited number of cached entries).
|
||||
# car_database = DODB::Storage::Common.new "/path/to/db"
|
||||
# # Creates a DODB database for common usage (a limited number of cached entries: 100k).
|
||||
# car_database = DODB::Storage::Common.new "/path/to/db", 100_000
|
||||
#
|
||||
# # Creates a (cached) index.
|
||||
# cars_by_name = car_database.new_index "name", &.name
|
||||
|
|
|
@ -256,12 +256,25 @@ class DODB::Trigger::Index(V) < DODB::Trigger(V)
|
|||
# # Deletes the car named "Corvet".
|
||||
# car_by_name.delete "Corvet"
|
||||
# ```
|
||||
# WARNING: may throw a MissingEntry exception.
|
||||
def delete(index : String)
|
||||
key = get_key index
|
||||
|
||||
@storage.delete key
|
||||
end
|
||||
|
||||
# Deletes a value based on its index, but do ignores a MissingEntry error.
|
||||
#
|
||||
# ```
|
||||
# # Deletes the car named "Corvet" (no MissingEntry exception if the car doesn't exist).
|
||||
# car_by_name.delete? "Corvet"
|
||||
# ```
|
||||
def delete?(v : String)
|
||||
delete v
|
||||
rescue MissingEntry
|
||||
nil
|
||||
end
|
||||
|
||||
# :inherit:
|
||||
def trigger_directory : String
|
||||
"#{@storage_root}/indices/by_#{@name}"
|
||||
|
|
|
@ -153,6 +153,18 @@ class DODB::Trigger::Partition(V) < DODB::Trigger(V)
|
|||
delete partition, do true end
|
||||
end
|
||||
|
||||
# Deletes all entries within the provided partition, but do ignores a MissingEntry error.
|
||||
#
|
||||
# ```
|
||||
# # Deletes all red cars.
|
||||
# cars_by_color.delete? "red" # no MissingEntry exception if there is no red cars
|
||||
# ```
|
||||
def delete?(partition : String)
|
||||
delete partition
|
||||
rescue MissingEntry
|
||||
nil
|
||||
end
|
||||
|
||||
# Deletes entries within the provided partition and matching the provided block of code.
|
||||
#
|
||||
# ```
|
||||
|
|
|
@ -187,9 +187,22 @@ class DODB::Trigger::Tags(V) < DODB::Trigger(V)
|
|||
# cars_by_keywords.delete "slow" # Deletes all slow cars.
|
||||
# cars_by_keywords.delete ["slow", "expensive"] # Deletes all cars that are both slow and expensive.
|
||||
# ```
|
||||
# WARNING: throws an exception if no value is found.
|
||||
def delete(tag : String | Array(String))
|
||||
delete tag, do true end
|
||||
# WARNING: throws a MissingEntry exception if no value is found.
|
||||
def delete(tag_or_tags : String | Array(String))
|
||||
delete tag_or_tags, do true end
|
||||
end
|
||||
|
||||
# Deletes all entries with the provided tag, but do ignores a MissingEntry error.
|
||||
#
|
||||
# ```
|
||||
# # No MissingEntry exception will be thrown.
|
||||
# cars_by_keywords.delete? "slow" # Deletes all slow cars.
|
||||
# cars_by_keywords.delete? ["slow", "expensive"] # Deletes all cars that are both slow and expensive.
|
||||
# ```
|
||||
def delete?(tag_or_tags : String | Array(String))
|
||||
delete tag_or_tags
|
||||
rescue MissingEntry
|
||||
nil
|
||||
end
|
||||
|
||||
# Deletes entries within the provided tag index and matching the provided block of code.
|
||||
|
|
Loading…
Reference in New Issue