Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Persist to disk (switch to StorageSqlite) #1

Closed
4 tasks done
cinnamon-bun opened this issue Jun 4, 2020 · 1 comment
Closed
4 tasks done

Persist to disk (switch to StorageSqlite) #1

cinnamon-bun opened this issue Jun 4, 2020 · 1 comment
Labels

Comments

@cinnamon-bun
Copy link
Member

cinnamon-bun commented Jun 4, 2020

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:

Changes:

  • Add an option to switch between in-memory and sqlite storage
  • Add an option for a directory in which to store the sqlite files
  • Generate safe filenames for the sqlite files, from the workspace address (see below)
  • 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
}
@cinnamon-bun cinnamon-bun changed the title Persist to disk (switch to storeSqlite) Persist to disk (switch to StorageSqlite) Jun 25, 2020
@cinnamon-bun
Copy link
Member Author

Done! Also updated the demo pub:

https://earthstar-demo-pub-v5-a.glitch.me/

https://glitch.com/~earthstar-demo-pub-v5-a

This is released as earthstar-pub 5.3.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant