Open yee94 opened 6 years ago
We’ll be happy to accept a contribution that adds an Electron adapter :)
expect
Closing this issue as it seems no one is working on this currently. Please let me know if someone wants to implement this - I can give guidance
We would be interested in implementing this. We are building an offline-first electron app with React, and we'd like to bind the state to a local SQLite database and sync to the cloud.
We've had a look through the source code and this is our rough understanding of what needs to be done:
In adapters/sqlite/index.js
, you have the bridge to the native code with the line const Native: NativeBridgeType = NativeModules.DatabaseBridge
. For electron, we'd need to implement this "DatabaseBridge" interface via nodejs, using something like node-sqlite3 to talk to the database. (We'll also need to modify this file to abstract out the calls to react-native, maybe as a separate adaptor or just an argument to the SQLiteAdapterOptions
.)
We also need to think about how to do the multi-threading, as we do not want the database calls running inside the renderer process. Possibly we can re-use the concepts from the LokiJS implementation via web workers, although workers are still experimental for node. Another would be to run the queries as part of a separate node server over node-ipc. Maybe we just provide the interface and it's up to the user to decide.
Are we roughly along the right lines?
@davidkell Yep, that all sounds correct!
@davidkell Is there any progress ? We have a react-native app and a electron app, so we are also interesting in making WatermelonDB support electron
@endpress I would very much welcome Electron support, so if @davidkell hasn't released any code, I highly encourage you @endpress to contribute :) The vast, vast, majority of work is done - we only need to hook up electron sqlite to watermelon's sqliteadpter
@endpress Yes, please go ahead and contribute!
From our end, we've been using the LokiJS/IndexedDB adaptor in the Electron app, and this is working well.
We'll probably hold off writing the SQLite version until there's a compelling advantage to doing it for us. To be honest, I'm not actually sure what this will be as the LokiJS adaptor is doing a great job, but probably performance or access to raw SQL.
Note that for LokisJS adaptor in electron, you need to enable the nodeIntegrationInWorker: true
for your renderer process.
@radex Out of interest, do you have any insight into the relative performance of the LokiJS vs SQLite adaptors?
Out of interest, do you have any insight into the relative performance of the LokiJS vs SQLite adaptors?
Not formally / in numbers. LokiJS is very fast for computing queries, but it doesn't have true lazy loading. So if you have a 50MB database, it needs to be loaded into memory at app launch which may be slow on some devices. SQLite doesn't have that problem
Someone has a Proof Of Concept ?
Any news?
@radex In my case I'll have to use SQLite adapter because I need to a SQLite plugins (word spliting) to do full text search, plus the db size could be huge, with SQLite a 2-4G db still works fine
So, I gave it a shot in a demo electron app that uses electron-vite. Besides an issue with the export of SQLiteAdapter
it works fine. I used better-sqlite3
as the database and simply added a rebuild script to rebuild it for the architecture that the electron app compiles for.
The only issue that I'm struggeling with is that the models are not serializable. As I have the DB running in the main process I need to be able to serialize the data to send it over the IPC bridge. For now I've added a toJSON()
method to my model. I call that method before I send the data over the bridge. Does that sound legit? Is there a better way to achieve that?
@dastein1 curious where you got to on this? Mongodb just abruptly deprecated their atlas device sync services and divesting RealmDB back to community so we are considering our next move. We are thinking about SQLite via node in the electron main process (as you mentioned above) and are wondering if you got this working or where things left off?
@radex if you have any further insights or help with some of the recent questions above, if no one picks this up, I will likely give it a shot.
Oh! this is a powerful way to edit database!
Can you surport Electron?