sapphiredb-js icon indicating copy to clipboard operation
sapphiredb-js copied to clipboard

Compatibility with SQLite/watermelon database as custom storage provider

Open msamirma opened this issue 3 years ago • 2 comments

@morrisjdev can you elaborate more about implementing a custom storage provider? I m willing to do the implementation of that but need more clarification if possible

msamirma avatar Jun 08 '21 14:06 msamirma

Hi.

Thank you for your interest and offered help.

The storage provider on client side is used to store the state of the current collection. It is used when no connection to server is possible and the client should use data that were previously loaded.

Currently the only implementation is the LocalStorage provider, that just stores the json value as string:

export class SapphireLocalStorage extends SapphireStorage {
  get(key: string): Observable<string> {
    return of(localStorage.getItem(key));
  }

  set(key: string, value: string) {
    localStorage.setItem(key, value);
  }
}

The idea of making this extendable was to allow using the sapphiredb-js client in NodeJs for example, where LocalStorage has to be replaced with another persistent storage solution like files.

I don't know if it's neccessary to use a complete database for this purpose, but let me know your thougts.

Thank you again and best regards

Morris

morrisjdev avatar Jun 13 '21 10:06 morrisjdev

Hi Thank you for your response! I was thinking was to create a custom provider that allows the client to work with a persistence database like sqlite (a Mobile app for example). But after giving it another thought I think it will be better to decouple from sapphire client.

if you got what I mean, it will be great you share your thoughts with me regarding what am thinking about.

Best regards

msamirma avatar Jun 25 '21 18:06 msamirma