diff --git a/shard.yml b/shard.yml index 8b460c8..f1d8e80 100644 --- a/shard.yml +++ b/shard.yml @@ -1,10 +1,10 @@ -name: fsdb +name: dodb version: 0.2.0 authors: - Luka Vandervelden description: | - Simple, embeddable document-oriented database in Crystal. + Simple, embeddable Document-Oriented DataBase in Crystal. license: MIT diff --git a/spec/test.cr b/spec/test.cr index 8f9b40f..f2e4b22 100644 --- a/spec/test.cr +++ b/spec/test.cr @@ -57,7 +57,7 @@ class Ship end end -class FSDB::SpecDataBase < FSDB::DataBase(String, Ship) +class DODB::SpecDataBase < DODB::DataBase(String, Ship) def initialize ::FileUtils.rm_rf "test-storage" @@ -65,10 +65,10 @@ class FSDB::SpecDataBase < FSDB::DataBase(String, Ship) end end -describe "FSDB::DataBase" do +describe "DODB::DataBase" do describe "basics" do it "store and get data" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new Ship.all_ships.each do |ship| db[ship.id] = ship @@ -80,7 +80,7 @@ describe "FSDB::DataBase" do end it "rewrite already stored data" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new ship = Ship.all_ships[0] db[ship.id] = Ship.new "broken", id: ship.id @@ -90,7 +90,7 @@ describe "FSDB::DataBase" do end it "properly remove data" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new Ship.all_ships.each do |ship| db[ship.id] = ship @@ -102,7 +102,7 @@ describe "FSDB::DataBase" do Ship.all_ships.each do |ship| # FIXME: Should it raise a particular exception? - expect_raises FSDB::MissingEntry do + expect_raises DODB::MissingEntry do db[ship.id] end @@ -113,7 +113,7 @@ describe "FSDB::DataBase" do describe "indices" do it "do basic indexing" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_name = db.new_index "name", &.name @@ -127,7 +127,7 @@ describe "FSDB::DataBase" do end it "raise on index overload" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_name = db.new_index "name", &.name @@ -137,13 +137,13 @@ describe "FSDB::DataBase" do # Should not be allowed to store an entry whose “name” field # already exists. - expect_raises(FSDB::IndexOverload) do + expect_raises(DODB::IndexOverload) do db["another id"] = some_ship end end it "properly deindex" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_name = db.new_index "name", &.name @@ -161,7 +161,7 @@ describe "FSDB::DataBase" do end it "properly reindex" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_name = db.new_index "name", &.name @@ -184,7 +184,7 @@ describe "FSDB::DataBase" do describe "partitions" do it "do basic partitioning" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_class = db.new_partition "class", &.class @@ -212,7 +212,7 @@ describe "FSDB::DataBase" do describe "tags" do it "do basic tagging" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_tags = db.new_tags "tags", &.tags @@ -233,7 +233,7 @@ describe "FSDB::DataBase" do end it "properly removes tags" do - db = FSDB::SpecDataBase.new + db = DODB::SpecDataBase.new db_ships_by_tags = db.new_tags "tags", &.tags diff --git a/src/fsdb.cr b/src/fsdb.cr index b1256ee..2bbb203 100644 --- a/src/fsdb.cr +++ b/src/fsdb.cr @@ -3,7 +3,7 @@ require "json" require "./fsdb/*" -class FSDB::DataBase(K, V) +class DODB::DataBase(K, V) @indexers = [] of Indexer(V) def initialize(@directory_name : String) @@ -35,20 +35,20 @@ class FSDB::DataBase(K, V) def get_index(name : String, key) index = @indexers.find &.name.==(name) - index.not_nil!.as(FSDB::Index).get key + index.not_nil!.as(DODB::Index).get key end # FIXME: Is this “key” really a K, not just a String? def get_partition(table_name : String, partition_name : String) partition = @indexers.find &.name.==(table_name) - partition.not_nil!.as(FSDB::Partition).get partition_name + partition.not_nil!.as(DODB::Partition).get partition_name end def get_tags(name, key : K) partition = @indexers.find &.name.==(name) - partition.not_nil!.as(FSDB::Tags).get name, key + partition.not_nil!.as(DODB::Tags).get name, key end def []?(key : K) : V? diff --git a/src/fsdb/exceptions.cr b/src/fsdb/exceptions.cr index ea89972..0628304 100644 --- a/src/fsdb/exceptions.cr +++ b/src/fsdb/exceptions.cr @@ -1,5 +1,5 @@ -class FSDB::MissingEntry < Exception +class DODB::MissingEntry < Exception getter index : String? getter key : String @@ -12,6 +12,6 @@ class FSDB::MissingEntry < Exception end end -class FSDB::IndexOverload < Exception +class DODB::IndexOverload < Exception end diff --git a/src/fsdb/index.cr b/src/fsdb/index.cr index a67d6b3..8609f96 100644 --- a/src/fsdb/index.cr +++ b/src/fsdb/index.cr @@ -4,7 +4,7 @@ require "json" require "./exceptions.cr" require "./indexer.cr" -class FSDB::Index(V) < FSDB::Indexer(V) +class DODB::Index(V) < DODB::Indexer(V) property name : String property key_proc : Proc(V, String) getter storage_root : String diff --git a/src/fsdb/indexer.cr b/src/fsdb/indexer.cr index c6fa90b..4a237c7 100644 --- a/src/fsdb/indexer.cr +++ b/src/fsdb/indexer.cr @@ -1,5 +1,5 @@ -abstract class FSDB::Indexer(V) +abstract class DODB::Indexer(V) abstract def index (key : String, value : V) abstract def deindex (key : String, value : V) abstract def check! (key : String, value : V, old_value : V?) diff --git a/src/fsdb/partition.cr b/src/fsdb/partition.cr index 345c195..bb92439 100644 --- a/src/fsdb/partition.cr +++ b/src/fsdb/partition.cr @@ -3,7 +3,7 @@ require "json" require "./indexer.cr" -class FSDB::Partition(V) < FSDB::Indexer(V) +class DODB::Partition(V) < DODB::Indexer(V) property name : String property key_proc : Proc(V, String) getter storage_root : String diff --git a/src/fsdb/tags.cr b/src/fsdb/tags.cr index 3f781d9..434c811 100644 --- a/src/fsdb/tags.cr +++ b/src/fsdb/tags.cr @@ -1,7 +1,7 @@ require "file_utils" require "json" -class FSDB::Tags(V) < FSDB::Indexer(V) +class DODB::Tags(V) < DODB::Indexer(V) property name : String property key_proc : Proc(V, Array(String)) getter storage_root : String