Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert IndexedDB to SQLite #690

Open
chrisvire opened this issue Sep 16, 2024 · 4 comments
Open

Convert IndexedDB to SQLite #690

chrisvire opened this issue Sep 16, 2024 · 4 comments

Comments

@chrisvire
Copy link
Member

chrisvire commented Sep 16, 2024

There are many features that have already been developed that are being shared between the SAB and DAB PWA. This is to do some work for the SAB app that is not shared with DAB, but needs to be done soon without anyone to work on it.

For storing annotations, the PWA used IndexedDB. It turns out that IndexedDB is not a stable place to store data long-term.

https://gist.github.com/pesterhazy/4de96193af89a6dd5ce682ce2adff49a

We need to convert the mechanism for storing data from IndexedDB to SQLite.

@chrisvire
Copy link
Member Author

chrisvire commented Sep 17, 2024

Here are some lnks:

SQLite Wasm wrapped in TypeScript

These articles have instructions for downloading the SQLite Wasm and integrating it into a SvelteKit application. I think it would be better to import SQLite Wasm from an NPM module.

Source for articles

It looks we need to use Origin Private File System or OPFS for short. This enables writing to the SQLite database.

You should take into account that there will be multiple apps published at the same origin and that we need to segment the data based on the package name in the configuration.

It looks like these writes should happen in a Web Worker so we will need to learn how to use those as well. The Scripture PWA currently uses a Web Worker for search.

@chrisvire
Copy link
Member Author

Here is the code from the Android app (Java) to create the annotations table:

    private static final String ANNOTATIONS_TABLE = "annotations";


    private String getSqlForCreateAnnotationsTable() {
        return "CREATE TABLE " + ANNOTATIONS_TABLE + " (" +
               "    id TEXT PRIMARY KEY, " + // unique ID
               "    date DATETIME, " +       // date modified
               "    page TEXT, " +           // page reference (book collection, book, chapter)
               "    type TEXT, " +           // annotation type
               "    details TEXT, " +        // details as JSON string
               "    deleted INT DEFAULT 0" + // deleted
               ");";
    }

@chrisvire
Copy link
Member Author

I have started the work of including SQLite WASM into the dependencies:

https://github.com/sillsdev/appbuilder-pwa/tree/feature/sqlite-wasm-dependency

@chrisvire
Copy link
Member Author

Create a empty database based on schema from the IndexedDB code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant