Skip to content

[web] How can I open the sqlite database in memory instead of using LocalStorage #1082

Answered by simolus3
thachnb85 asked this question in Q&A
Discussion options

You must be logged in to vote

That's an interesting question! You could write a custom MoorWebStorage that just stores data in memory:

class InMemoryWebStorage implements MoorWebStorage {
  Uint8List? _storedData;

  @override
  Future<void> close() => Future.value();

  @override
  Future<void> open() => Future.value();

  @override
  Future<Uint8List?> restore() => Future.value(_storedData);

  @override
  Future<void> store(Uint8List data) {
    _storedData = data;
    return Future.value();
  }
}

You could then use a WebDatabase.withStorage(InMemoryWebStorage()).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thachnb85
Comment options

Answer selected by thachnb85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants