Yhilan
Yhilan

Reputation: 269

Exporting sqlite3 db file from inside electron app. Is this possible?

I've got an app I've put together in Electron which saves data using sqlite3. Everything works as expected. I'd like to be able to export/save the actual database file so I can share it with others, treating it sort of like a save file.

I assume that if this is possible then I need to be using fs as well, which is fine.

Even better, can I just create the database file outside the compiled app from the start? And if so what's the best way to accomplish that?

Otherwise I can switch over to kripken/sql.js or something like that, but I'd rather not put the time in to make those changes if there's an easy way to just have the existing sqlite database file get saved to the user's computer outside the app.

Upvotes: 2

Views: 1895

Answers (1)

Yhilan
Yhilan

Reputation: 269

I'm an idiot.

Instead of storing the file internally in the packaged app like this…

const dbPath = path.resolve(__dirname, 'data.db')

…I'm just storing it in the filesystem like this…

const {app} = require('electron').remote;
const dbPath = path.resolve(app.getPath('userData'), 'data.db');

…so that it's accessible from the start.

I'm leaving this question up because I'd be interested if there is a way to have a save file dialogue for an extant file in the packaged app, but in the mean time this is my answer.

Upvotes: 2

Related Questions