Writing data into the sqlite db file inside asar archive in electron app


#1
var fs = require('fs');
var SQL = require('sql.js');
var filebuffer = fs.readFileSync('./resources/app.asar/app/data/sample.db');
var db = new SQL.Database(filebuffer);


function save_data()
{
  var name=document.getElementById('name').value;
  var ip=document.getElementById('serverip').value;  
   var result=db.each("UPDATE Settings SET Name=$name, IP=$ip WHERE SettingsId=$set",    {$name:name,$ip : ip,$set:1},function(row){console.log(row.name)});
  var data = db.export();
  var buffer = new Buffer(data);
  fs.writeFileSync('./resources/app.asar/app/data/sample.db', buffer);
}

I was able to read the data from the database file inside the asar archive, but while writing the data into db file, it doesn’t gets updated inside asar archive. So please help me crack this issue.


#2

You can’t modify a file that’s inside an ASAR, if you want to modify a file don’t pack it into the ASAR (or copy it out of the ASAR and modify the copy).


#3

Thanks. I’m now keeping the sqlite db outside the asar archive file…


#4

Hi! can i ask you how you did it?!
i’m trying with --asar-unpack, but it seems to not work!

thank you!


#5

@biroplane, did you find the solution. I tried unpacking the files that needs to have fs access. But then the folder is formed outside app.asar and hence my app is not able to access it.


#6

Hi, Initially i was making asar from electron-packager and was facing the issue of not being able to write file dynamically inside asar. After doing little research and following your instruction, i made asar file manually and excluded the folder inside app which needs fs operation. But this creates folder app.asar.unpacked outside, and is not accessible by my app. Can you please help me in this?


#7

No, i just moved all the data to Document folder, and kept outside the asar.