From 355f85d6352cc3b53f18c77a3b78f2f6b6691505 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Sun, 2 Feb 2020 14:18:03 +0100 Subject: [PATCH] Index#update_or_create(key, value) added. --- src/dodb/index.cr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dodb/index.cr b/src/dodb/index.cr index 5f9ea3a..5e5bb9e 100644 --- a/src/dodb/index.cr +++ b/src/dodb/index.cr @@ -93,6 +93,12 @@ class DODB::Index(V) < DODB::Indexer(V) @storage[key] = new_value end + def update_or_create(index : String, new_value : V) + update index, new_value + rescue MissingEntry + @storage << new_value + end + def delete(index : String) key = get_key index