[architecture] Which database for an electron app


#1

Hi everyone !

I’m very new at app development and electron is soo helpful for me as I have a web development background.
`
The app I’m working on is a working time recorder.

Here is my question:

  • I need to store users data (projects, time passed per project, etc…)
  • My web background led me to turn towards SQL database (and what I found on the internet tends to confirm)
  • A solution would be to install a database with MAMP and use it with node.js from my electron app

But how to package and export this app once finished? I don’t want to tell my user to install MAMP/WAMP, set a database, etc…

What would you recommend ?

Thanks per advance!
Thibault


[Architecture] How to move “PHP.Laravel + VueJS” app to Hybrid app?
#2

I’d take a look at IndexedDB or, for simple use-cases, Web Storage (localStorage/sessionStorage). Both are built into all modern browsers (and Electron).

Web Storage is very simple to use, but it’s synchronous and not ideal for complex data structures. If you’re looking for a large-scale NoSQL database, IndexedDB is the way to go. Google has a nice guide on how to use it.

If you’re undecided at this point, I can recommend localForage. It’s basically an intermediate layer that supports IndexedDB, Web Storage and the (now deprecated) WebSQL. Switching between those is as simple as changing the config, you usually don’t have to change your code to read or write to the database.


#3

Hey @idelberg !

Thanks for your answer! I will take a look at localForage as I will have session as well as long term data storage needs.

Thanks again !


#4

You definitely want to go with SQLite! It creates a lightweight, simple db (built directly into your app). So for this reason you will need to run a rebuild command when installing it (simply by adding flags to the npm install command).

Take a look at the npm package and documention:
https://www.npmjs.com/package/sqlite3

FYI -
There are also a few Youtube vids that’ll walk you through it.

Here is the code you will end up running (from the docs):
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=brew --prefix --runtime=electron --target=1.7.6 --dist-url=https://atom.io/download/electron


#5

Hey @kaanuki

Thanks for your answer. SQLite seams to fit my needs!

I’ll try it soon