[x] Add an option to switch between in-memory and sqlite storage
[x] Add an option for a directory in which to store the sqlite files
[x] Generate safe filenames for the sqlite files, from the workspace address (see below)
[x] Instantiate a StorageSqlite instead of a StorageMemory.
How to validate a workspace address and use it as a filename
A workspace address looks like +gardenclub.jaoidf23jdoq9dj. Remove the leading + and append .sqlite to make a filename. Make sure to validate the string as a proper workspace address using ValidatorES4._checkWorkspaceIsValid from the earthstar package. (Valid workspace addresses are safe as filenames.)
import { ValidatorES4, isErr, notErr } from 'earthstar';
let addr = '+foo.xxxxxxx';
let err = ValidatorES4._checkWorkspaceIsValid(addr);
if (isErr(err)) {
console.error('bad workspace address: ' + err.message);
} else {
// addr is now a valid workspace address
let filename = addr.slice(1) + '.sqlite'; // remove leading '+'
// filename is now is guaranteed to be safe for use as a filename
}
Right now we're using the in-memory Earthstar storage, which forgets everything when the pub is restarted.
Add an option to store each workspace in its own sqlite file in a configurable directory.
Places to make changes:
obtainStorage
function is where Storage classes are instantiated for new workspacesChanges:
StorageSqlite
instead of aStorageMemory
.How to validate a workspace address and use it as a filename
A workspace address looks like
+gardenclub.jaoidf23jdoq9dj
. Remove the leading+
and append.sqlite
to make a filename. Make sure to validate the string as a proper workspace address usingValidatorES4._checkWorkspaceIsValid
from theearthstar
package. (Valid workspace addresses are safe as filenames.)