parliament
parliament

Reputation: 22914

Embed RethinkDB into Electron (or NodeJS) app

I'm building an Electron app, specifically a crypto-currency wallet, so I need all the information stored locally on the user's machine and should not be synced to any server.

I like RethinkDB and would like to use it, but I can't find a way to embed it into the app.

I want the database to launch when the app starts, and shutdown when the app closes... in other words have it embedded into the app.

Is this possible with Rethinkdb? There's no relevant info on the page detailing how to start-up the db but perhaps this can be done anyways?

Upvotes: 2

Views: 324

Answers (1)

tpikachu
tpikachu

Reputation: 4854

As long as you are storing the user data on their local machine. I believe you should use the embedded database but not the client-server database engine. Of course, we can use any database in our Electron application but in most cases, we don't need any client-server db engine as long as we need a simple library or script to store and manage the local db file.

RethinkgDB is a great database library and it's a client-server pattern. Please use SQLite instead. SQLite is not a client-server database engine. Instead, it is embedded into the end program. As the below code snippets show, we just need to set the DB file path where all data will be stored.

Query syntax is the same as PostgreSQL.

const sqlite3 = require('sqlite3');

const database = new sqlite3.Database('./public/db.sqlite3', (err) => {
    if (err) console.error('Database opening error: ', err);
});

ipcMain.on('asynchronous-message', (event, arg) => {
    const sql = arg;
    database.all(sql, (err, rows) => {
        event.reply('asynchronous-reply', (err && err.message) || rows);
    });
});

In addition, I used to use keytar to keep sensitive data like private keys and credentials of my wallet.

Upvotes: 3

Related Questions