Watermelondb: Can you surport Electron?

Created on 9 Sep 2018  ·  10Comments  ·  Source: Nozbe/WatermelonDB

Oh! this is a powerful way to edit database!

Can you surport Electron?

enhancement

Most helpful comment

expect

All 10 comments

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 ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radex picture radex  ·  6Comments

bsr203 picture bsr203  ·  6Comments

MikeWoots picture MikeWoots  ·  5Comments

binbinla picture binbinla  ·  3Comments

impactcolor picture impactcolor  ·  4Comments