Angular Electron Desktop App Do Not Persist data in SQLite3 Database when App is Closed.

I am using SQLITE3 in my angular8-electron5 desktop app to store user login credentials so that when next they launch the app, they do not have to login, their login details will be retrieve from SQLite Database.

It works as expected during development, but when i build the .exe file and run the app, it does not persist login credentials once the app is closed.
Below is my SQLite database connection credentials and my .sqlite3 file.

  const connection = await createConnection({
    type: 'sqlite',
    synchronize: true,
    logging: true,
    logger: 'simple-console',
    database: './typeormmodels/data/database.sqlite3',
    entities: [User, Usertoken, Usersession],
  });

Please help, i want the app to persist data even after it has been closed, this way users can use it offline without internet.

2 thoughts on “Angular Electron Desktop App Do Not Persist data in SQLite3 Database when App is Closed.

  1. To me, it seems like the database isn’t being embedded correctly. Its probably getting recreated in the production build at each run. May I suggest switching to a NeDB if feasible.

  2. I got this working by referencing my database file like this:

    let fileName = 'database.sqlite3';
    let dbpat = `${process.env.NODE_ENV === 'dev' ? `./typeormmodels/data/${fileName}` : app.getPath('userData')}/data/${fileName}`;
    
      const connection = await createConnection({
        type: 'sqlite',
        synchronize: true,
        logging: true,
        logger: 'simple-console',
        database: `${dbpat}`, 
        entities: [User, Usertoken, Usersession],
      });