Create multi database to dupe writes

master
Bel LaPointe 2021-02-26 22:12:08 -06:00
parent 52c7b2222e
commit fc438a55f8
1 changed files with 46 additions and 0 deletions

View File

@ -1237,6 +1237,47 @@
}
}
class MultiDatabase extends Database {
constructor()
{
super();
if (arguments.length < 1)
{
throw "must supply at least one database";
}
this.databases = [];
for (var i=0; i<arguments.length; i++)
{
this.databases.push(arguments[i]);
}
}
get(key) {
return this.databases[0].get(key);
}
set(key, value)
{
this.databases.forEach((database) => {
database.set(key, value);
});
}
del(key)
{
this.databases.forEach((database) => {
database.del(key, value);
});
}
forEach(foo)
{
this.databases[0].forEach((key) => {
foo(key);
});
}
}
class NamespacedDatabase extends Database {
constructor(namespace, database)
{
@ -1322,6 +1363,11 @@
}
globalStorage = new NamespacedDatabase("4", new Local());
globalStorage = new MultiDatabase(
new NamespacedDatabase("A", new Local()),
new NamespacedDatabase("B", new Local()),
);
globalStorage = new NamespacedDatabase("B", new Local());
/*
* poor man's error handling -- $fixme