Create multi database to dupe writes
parent
52c7b2222e
commit
fc438a55f8
|
|
@ -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 {
|
class NamespacedDatabase extends Database {
|
||||||
constructor(namespace, database)
|
constructor(namespace, database)
|
||||||
{
|
{
|
||||||
|
|
@ -1322,6 +1363,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
globalStorage = new NamespacedDatabase("4", new Local());
|
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
|
* poor man's error handling -- $fixme
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue