Name and namespace change.

This is very much a breaking change.
remotes/1708595148460401306/master
Luka Vandervelden 2019-12-11 18:05:02 +01:00
parent ca712f98ce
commit fc21b48870
6 changed files with 34 additions and 21 deletions

View File

@ -1,10 +1,10 @@
name: fs name: fsdb
version: 0.2.0 version: 0.2.0
authors: authors:
- Luka Vandervelden <lukc@upyum.com> - Luka Vandervelden <lukc@upyum.com>
description: | description: |
Filesystem abstraction through near-native types. Simple, embeddable document-oriented database in Crystal.
license: MIT license: MIT

View File

@ -2,14 +2,14 @@
require "file_utils" require "file_utils"
require "json" require "json"
abstract class FS::Indexer(V) abstract class FSDB::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?)
abstract def name : String abstract def name : String
end end
class FS::Partition(V) < FS::Indexer(V) class FSDB::Partition(V) < FSDB::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
@ -71,7 +71,7 @@ class FS::Partition(V) < FS::Indexer(V)
end end
end end
class FS::Index(V) < FS::Indexer(V) class FSDB::Index(V) < FSDB::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
@ -136,7 +136,7 @@ class FS::Index(V) < FS::Indexer(V)
end end
end end
class FS::Tags(V) < FS::Indexer(V) class FSDB::Tags(V) < FSDB::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
@ -200,10 +200,10 @@ class FS::Tags(V) < FS::Indexer(V)
end end
end end
class FS::IndexOverload < Exception class FSDB::IndexOverload < Exception
end end
class FS::Hash(K, V) class FSDB::DataBase(K, V)
@indexers = [] of Indexer(V) @indexers = [] of Indexer(V)
def initialize(@directory_name : String) def initialize(@directory_name : String)
@ -235,20 +235,20 @@ class FS::Hash(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(FS::Index).get key index.not_nil!.as(FSDB::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(FS::Partition).get partition_name partition.not_nil!.as(FSDB::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(FS::Tags).get name, key partition.not_nil!.as(FSDB::Tags).get name, key
end end
def []?(key : K) : V? def []?(key : K) : V?

View File

@ -1,5 +1,5 @@
require "json" require "json"
require "./src/fs.cr" require "./src/fsdb.cr"
require "uuid" require "uuid"
# This test basically works if no data is obtained when fetching "broken" # This test basically works if no data is obtained when fetching "broken"
@ -21,7 +21,7 @@ class Ship
getter id getter id
end end
ships = FS::Hash(String, Ship).new "test-edit" ships = FSDB::DataBase(String, Ship).new "test-edit"
by_name = ships.new_index "name", &.name by_name = ships.new_index "name", &.name
by_class = ships.new_partition "class", &.class by_class = ships.new_partition "class", &.class
by_id = ships.new_index "id", &.id by_id = ships.new_index "id", &.id
@ -46,6 +46,8 @@ ships.each do |id, ship|
p "#{ship.name} (#{ship.class}) [#{ship.tags.join ", "}]" p "#{ship.name} (#{ship.class}) [#{ship.tags.join ", "}]"
end end
pp! by_class.get("Mutsuki").map(&.name)
no_broken = Array(Array(Ship)).new no_broken = Array(Array(Ship)).new
puts puts
puts "Partitions/indices" puts "Partitions/indices"
@ -59,3 +61,14 @@ if no_broken.flatten.size > 0
puts "ERROR: the test failed" puts "ERROR: the test failed"
end end
##
# Not implemented, will *not* work (or compile).
##
#ships.partition("class", "Mutsuki").get(min: 1, max: 3)
#ships.partition("class", "Mutsuki").get[1]
#ships.partition("class", "Mutsuki").partition("batch", "first").get
#ships.partition("class", "Mutsuki").sorted_by("name").get(min: 0, max: 2)

View File

@ -1,5 +1,5 @@
require "json" require "json"
require "./src/fs.cr" require "./src/fsdb.cr"
require "uuid" require "uuid"
# This test basically works if no data is obtained when fetching "broken" # This test basically works if no data is obtained when fetching "broken"
@ -21,7 +21,7 @@ class Ship
getter id getter id
end end
ships = FS::Hash(String, Ship).new "test-index" ships = FSDB::DataBase(String, Ship).new "test-index"
by_name = ships.new_index "name", &.name by_name = ships.new_index "name", &.name
by_class = ships.new_partition "class", &.class by_class = ships.new_partition "class", &.class
by_id = ships.new_index "id", &.id by_id = ships.new_index "id", &.id
@ -33,7 +33,7 @@ ships[ship.id] = ship
begin begin
ship = Ship.new "Mutsuki", "broken", tags: ["kuchikukan"] ship = Ship.new "Mutsuki", "broken", tags: ["kuchikukan"]
ships[ship.id] = ship ships[ship.id] = ship
rescue FS::IndexOverload rescue FSDB::IndexOverload
puts "rescue: Adding an entry that would overload an index has been prevented." puts "rescue: Adding an entry that would overload an index has been prevented."
# Should happen, ignore it. # Should happen, ignore it.
else else

View File

@ -1,6 +1,6 @@
require "json" require "json"
require "uuid/json" require "uuid/json"
require "./src/fs.cr" require "./src/fsdb.cr"
class Article class Article
JSON.mapping({ JSON.mapping({
@ -13,7 +13,7 @@ class Article
end end
end end
s = FS::Hash(String, Article).new "test-tags" s = FSDB::DataBase(String, Article).new "test-tags"
s.new_tags "tags", &.tags.map(&.downcase) s.new_tags "tags", &.tags.map(&.downcase)

View File

@ -1,9 +1,9 @@
require "json" require "json"
require "./src/fs.cr" require "./src/fsdb.cr"
# Basic mapping testing. # Basic mapping testing.
a = FS::Hash(String, JSON::Any).new "test-storage" a = FSDB::DataBase(String, JSON::Any).new "test-storage"
a["a"] = JSON::Any.new "now exists" a["a"] = JSON::Any.new "now exists"
@ -37,7 +37,7 @@ class Article
getter id getter id
end end
articles = FS::Hash(String, Article).new "articles" articles = FSDB::DataBase(String, Article).new "articles"
by_author = articles.new_partition "author", &.author by_author = articles.new_partition "author", &.author
by_id = articles.new_index "id", &.id by_id = articles.new_index "id", &.id