Name and namespace change.
This is very much a breaking change.remotes/1708105384931250775/master
parent
ca712f98ce
commit
fc21b48870
|
@ -1,10 +1,10 @@
|
|||
name: fs
|
||||
name: fsdb
|
||||
version: 0.2.0
|
||||
|
||||
authors:
|
||||
- Luka Vandervelden <lukc@upyum.com>
|
||||
|
||||
description: |
|
||||
Filesystem abstraction through near-native types.
|
||||
Simple, embeddable document-oriented database in Crystal.
|
||||
|
||||
license: MIT
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
require "file_utils"
|
||||
require "json"
|
||||
|
||||
abstract class FS::Indexer(V)
|
||||
abstract class FSDB::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?)
|
||||
abstract def name : String
|
||||
end
|
||||
|
||||
class FS::Partition(V) < FS::Indexer(V)
|
||||
class FSDB::Partition(V) < FSDB::Indexer(V)
|
||||
property name : String
|
||||
property key_proc : Proc(V, String)
|
||||
getter storage_root : String
|
||||
|
@ -71,7 +71,7 @@ class FS::Partition(V) < FS::Indexer(V)
|
|||
end
|
||||
end
|
||||
|
||||
class FS::Index(V) < FS::Indexer(V)
|
||||
class FSDB::Index(V) < FSDB::Indexer(V)
|
||||
property name : String
|
||||
property key_proc : Proc(V, String)
|
||||
getter storage_root : String
|
||||
|
@ -136,7 +136,7 @@ class FS::Index(V) < FS::Indexer(V)
|
|||
end
|
||||
end
|
||||
|
||||
class FS::Tags(V) < FS::Indexer(V)
|
||||
class FSDB::Tags(V) < FSDB::Indexer(V)
|
||||
property name : String
|
||||
property key_proc : Proc(V, Array(String))
|
||||
getter storage_root : String
|
||||
|
@ -200,10 +200,10 @@ class FS::Tags(V) < FS::Indexer(V)
|
|||
end
|
||||
end
|
||||
|
||||
class FS::IndexOverload < Exception
|
||||
class FSDB::IndexOverload < Exception
|
||||
end
|
||||
|
||||
class FS::Hash(K, V)
|
||||
class FSDB::DataBase(K, V)
|
||||
@indexers = [] of Indexer(V)
|
||||
|
||||
def initialize(@directory_name : String)
|
||||
|
@ -235,20 +235,20 @@ class FS::Hash(K, V)
|
|||
def get_index(name : String, key)
|
||||
index = @indexers.find &.name.==(name)
|
||||
|
||||
index.not_nil!.as(FS::Index).get key
|
||||
index.not_nil!.as(FSDB::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(FS::Partition).get partition_name
|
||||
partition.not_nil!.as(FSDB::Partition).get partition_name
|
||||
end
|
||||
|
||||
def get_tags(name, key : K)
|
||||
partition = @indexers.find &.name.==(name)
|
||||
|
||||
partition.not_nil!.as(FS::Tags).get name, key
|
||||
partition.not_nil!.as(FSDB::Tags).get name, key
|
||||
end
|
||||
|
||||
def []?(key : K) : V?
|
17
test-edit.cr
17
test-edit.cr
|
@ -1,5 +1,5 @@
|
|||
require "json"
|
||||
require "./src/fs.cr"
|
||||
require "./src/fsdb.cr"
|
||||
require "uuid"
|
||||
|
||||
# This test basically works if no data is obtained when fetching "broken"
|
||||
|
@ -21,7 +21,7 @@ class Ship
|
|||
getter id
|
||||
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_class = ships.new_partition "class", &.class
|
||||
by_id = ships.new_index "id", &.id
|
||||
|
@ -46,6 +46,8 @@ ships.each do |id, ship|
|
|||
p "#{ship.name} (#{ship.class}) [#{ship.tags.join ", "}]"
|
||||
end
|
||||
|
||||
pp! by_class.get("Mutsuki").map(&.name)
|
||||
|
||||
no_broken = Array(Array(Ship)).new
|
||||
puts
|
||||
puts "Partitions/indices"
|
||||
|
@ -59,3 +61,14 @@ if no_broken.flatten.size > 0
|
|||
puts "ERROR: the test failed"
|
||||
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)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require "json"
|
||||
require "./src/fs.cr"
|
||||
require "./src/fsdb.cr"
|
||||
require "uuid"
|
||||
|
||||
# This test basically works if no data is obtained when fetching "broken"
|
||||
|
@ -21,7 +21,7 @@ class Ship
|
|||
getter id
|
||||
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_class = ships.new_partition "class", &.class
|
||||
by_id = ships.new_index "id", &.id
|
||||
|
@ -33,7 +33,7 @@ ships[ship.id] = ship
|
|||
begin
|
||||
ship = Ship.new "Mutsuki", "broken", tags: ["kuchikukan"]
|
||||
ships[ship.id] = ship
|
||||
rescue FS::IndexOverload
|
||||
rescue FSDB::IndexOverload
|
||||
puts "rescue: Adding an entry that would overload an index has been prevented."
|
||||
# Should happen, ignore it.
|
||||
else
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "json"
|
||||
require "uuid/json"
|
||||
require "./src/fs.cr"
|
||||
require "./src/fsdb.cr"
|
||||
|
||||
class Article
|
||||
JSON.mapping({
|
||||
|
@ -13,7 +13,7 @@ class Article
|
|||
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)
|
||||
|
||||
|
|
6
test.cr
6
test.cr
|
@ -1,9 +1,9 @@
|
|||
require "json"
|
||||
require "./src/fs.cr"
|
||||
require "./src/fsdb.cr"
|
||||
|
||||
# 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"
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Article
|
|||
getter id
|
||||
end
|
||||
|
||||
articles = FS::Hash(String, Article).new "articles"
|
||||
articles = FSDB::DataBase(String, Article).new "articles"
|
||||
by_author = articles.new_partition "author", &.author
|
||||
by_id = articles.new_index "id", &.id
|
||||
|
||||
|
|
Loading…
Reference in New Issue