I’m looking at storing data onto a persistent storage (sql based) without affecting the main UI thread. One option is to use a worker thread for this purpose. I came across this feature called OPFS storage which lets you write files to the native file system in a browser environment. And it is supported in a worker setup. So, ideally it should not affect the UI thread.
Sqlite has made available a library for this purpose. This library produces an ESModule which in theory should work for all browser based environments.
I have created a new Ionic project, added Electron platform and tried to integrate this library. But, I’m facing an issue where-in I’m getting run-time exceptions on usage of require statement. The library source code does not have any require statements.
Seems like when I compile the project and run, ionic cordova electron stack seems to be transpiling sqlite-wasm library to CommonJS syntax and it appears to me that when the app code refers to one of these files, it would not be compatible (because Ionic produces code compatible with ESModule syntax) and it simply throws the exception saying require is not defined.
While the electron platform is node js based, the browser front end environment, I understand is ESModule based. Is this mechanism is something which we can make it work? I require persistent storage to be sql based (we are migrating a ionic cordova windows app to ionic cordova electron app). What other options we have a sql based persistent storage and at the same time not affecting the UI thread?
I have hosted my sample project here along with the instructions.
Srinidhi