Name change.

This time it follows our project conventions.
master
Luka Vandervelden 2019-12-11 23:18:20 +01:00
parent 472f173f6e
commit aec1dc2011
8 changed files with 26 additions and 26 deletions

View File

@ -1,10 +1,10 @@
name: fsdb name: dodb
version: 0.2.0 version: 0.2.0
authors: authors:
- Luka Vandervelden <lukc@upyum.com> - Luka Vandervelden <lukc@upyum.com>
description: | description: |
Simple, embeddable document-oriented database in Crystal. Simple, embeddable Document-Oriented DataBase in Crystal.
license: MIT license: MIT

View File

@ -57,7 +57,7 @@ class Ship
end end
end end
class FSDB::SpecDataBase < FSDB::DataBase(String, Ship) class DODB::SpecDataBase < DODB::DataBase(String, Ship)
def initialize def initialize
::FileUtils.rm_rf "test-storage" ::FileUtils.rm_rf "test-storage"
@ -65,10 +65,10 @@ class FSDB::SpecDataBase < FSDB::DataBase(String, Ship)
end end
end end
describe "FSDB::DataBase" do describe "DODB::DataBase" do
describe "basics" do describe "basics" do
it "store and get data" do it "store and get data" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
Ship.all_ships.each do |ship| Ship.all_ships.each do |ship|
db[ship.id] = ship db[ship.id] = ship
@ -80,7 +80,7 @@ describe "FSDB::DataBase" do
end end
it "rewrite already stored data" do it "rewrite already stored data" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
ship = Ship.all_ships[0] ship = Ship.all_ships[0]
db[ship.id] = Ship.new "broken", id: ship.id db[ship.id] = Ship.new "broken", id: ship.id
@ -90,7 +90,7 @@ describe "FSDB::DataBase" do
end end
it "properly remove data" do it "properly remove data" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
Ship.all_ships.each do |ship| Ship.all_ships.each do |ship|
db[ship.id] = ship db[ship.id] = ship
@ -102,7 +102,7 @@ describe "FSDB::DataBase" do
Ship.all_ships.each do |ship| Ship.all_ships.each do |ship|
# FIXME: Should it raise a particular exception? # FIXME: Should it raise a particular exception?
expect_raises FSDB::MissingEntry do expect_raises DODB::MissingEntry do
db[ship.id] db[ship.id]
end end
@ -113,7 +113,7 @@ describe "FSDB::DataBase" do
describe "indices" do describe "indices" do
it "do basic indexing" do it "do basic indexing" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_name = db.new_index "name", &.name db_ships_by_name = db.new_index "name", &.name
@ -127,7 +127,7 @@ describe "FSDB::DataBase" do
end end
it "raise on index overload" do it "raise on index overload" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_name = db.new_index "name", &.name 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 # Should not be allowed to store an entry whose “name” field
# already exists. # already exists.
expect_raises(FSDB::IndexOverload) do expect_raises(DODB::IndexOverload) do
db["another id"] = some_ship db["another id"] = some_ship
end end
end end
it "properly deindex" do it "properly deindex" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_name = db.new_index "name", &.name db_ships_by_name = db.new_index "name", &.name
@ -161,7 +161,7 @@ describe "FSDB::DataBase" do
end end
it "properly reindex" do it "properly reindex" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_name = db.new_index "name", &.name db_ships_by_name = db.new_index "name", &.name
@ -184,7 +184,7 @@ describe "FSDB::DataBase" do
describe "partitions" do describe "partitions" do
it "do basic partitioning" do it "do basic partitioning" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_class = db.new_partition "class", &.class db_ships_by_class = db.new_partition "class", &.class
@ -212,7 +212,7 @@ describe "FSDB::DataBase" do
describe "tags" do describe "tags" do
it "do basic tagging" do it "do basic tagging" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_tags = db.new_tags "tags", &.tags db_ships_by_tags = db.new_tags "tags", &.tags
@ -233,7 +233,7 @@ describe "FSDB::DataBase" do
end end
it "properly removes tags" do it "properly removes tags" do
db = FSDB::SpecDataBase.new db = DODB::SpecDataBase.new
db_ships_by_tags = db.new_tags "tags", &.tags db_ships_by_tags = db.new_tags "tags", &.tags

View File

@ -3,7 +3,7 @@ require "json"
require "./fsdb/*" require "./fsdb/*"
class FSDB::DataBase(K, V) class DODB::DataBase(K, V)
@indexers = [] of Indexer(V) @indexers = [] of Indexer(V)
def initialize(@directory_name : String) def initialize(@directory_name : String)
@ -35,20 +35,20 @@ class FSDB::DataBase(K, V)
def get_index(name : String, key) def get_index(name : String, key)
index = @indexers.find &.name.==(name) index = @indexers.find &.name.==(name)
index.not_nil!.as(FSDB::Index).get key index.not_nil!.as(DODB::Index).get key
end end
# FIXME: Is this “key” really a K, not just a String? # FIXME: Is this “key” really a K, not just a String?
def get_partition(table_name : String, partition_name : String) def get_partition(table_name : String, partition_name : String)
partition = @indexers.find &.name.==(table_name) 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 end
def get_tags(name, key : K) def get_tags(name, key : K)
partition = @indexers.find &.name.==(name) partition = @indexers.find &.name.==(name)
partition.not_nil!.as(FSDB::Tags).get name, key partition.not_nil!.as(DODB::Tags).get name, key
end end
def []?(key : K) : V? def []?(key : K) : V?

View File

@ -1,5 +1,5 @@
class FSDB::MissingEntry < Exception class DODB::MissingEntry < Exception
getter index : String? getter index : String?
getter key : String getter key : String
@ -12,6 +12,6 @@ class FSDB::MissingEntry < Exception
end end
end end
class FSDB::IndexOverload < Exception class DODB::IndexOverload < Exception
end end

View File

@ -4,7 +4,7 @@ require "json"
require "./exceptions.cr" require "./exceptions.cr"
require "./indexer.cr" require "./indexer.cr"
class FSDB::Index(V) < FSDB::Indexer(V) class DODB::Index(V) < DODB::Indexer(V)
property name : String property name : String
property key_proc : Proc(V, String) property key_proc : Proc(V, String)
getter storage_root : String getter storage_root : String

View File

@ -1,5 +1,5 @@
abstract class FSDB::Indexer(V) abstract class DODB::Indexer(V)
abstract def index (key : String, value : V) abstract def index (key : String, value : V)
abstract def deindex (key : String, value : V) abstract def deindex (key : String, value : V)
abstract def check! (key : String, value : V, old_value : V?) abstract def check! (key : String, value : V, old_value : V?)

View File

@ -3,7 +3,7 @@ require "json"
require "./indexer.cr" require "./indexer.cr"
class FSDB::Partition(V) < FSDB::Indexer(V) class DODB::Partition(V) < DODB::Indexer(V)
property name : String property name : String
property key_proc : Proc(V, String) property key_proc : Proc(V, String)
getter storage_root : String getter storage_root : String

View File

@ -1,7 +1,7 @@
require "file_utils" require "file_utils"
require "json" require "json"
class FSDB::Tags(V) < FSDB::Indexer(V) class DODB::Tags(V) < DODB::Indexer(V)
property name : String property name : String
property key_proc : Proc(V, Array(String)) property key_proc : Proc(V, Array(String))
getter storage_root : String getter storage_root : String