From e457a8039920de4629be5ca71c14facef217446b Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sun, 19 Apr 2020 18:18:53 +0200 Subject: [PATCH] index#update(new_value) : index is automatically retrieved. --- shard.yml | 3 ++- src/dodb/index.cr | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shard.yml b/shard.yml index 43fbac1..124b49b 100644 --- a/shard.yml +++ b/shard.yml @@ -1,8 +1,9 @@ name: dodb -version: 0.2.1 +version: 0.2.2 authors: - Luka Vandervelden + - Philippe Pittoli description: | Simple, embeddable Document-Oriented DataBase in Crystal. diff --git a/src/dodb/index.cr b/src/dodb/index.cr index 5e5bb9e..962d69b 100644 --- a/src/dodb/index.cr +++ b/src/dodb/index.cr @@ -87,6 +87,12 @@ class DODB::Index(V) < DODB::Indexer(V) {value, key} end + # in case new_value hasn't change its index + def update(new_value : V) + index = key_proc.call new_value + update index, new_value + end + def update(index : String, new_value : V) _, key = get_with_key index