question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
astroamecommented, Oct 30, 2019

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],
  });

2reactions
nikhilnxvverma1commented, Jul 22, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to persist data in an Electron app? [closed] - Stack Overflow
After building a custom solution that communicates over IPC to node to save a JSON file, I have realized that it may be...
Read more >
How to create an Electron app using Angular and SQLite3.
Now let's open our src/index.ts file and add some code to connect to the database. The two things we need to do are,...
Read more >
Electron Tutorial: Data Persistence - Techiediaries
Throughout this tutorial, we are going to explore different approaches for persisting and retrieving data in cross-platform desktop applications ...
Read more >
Connecting to Sqlite Database in Electron JS - YouTube
Nearly every application needs a database of some sort. Sqlite is a great choice for an Electron db. It's lightweight, it's portable and...
Read more >
How to store user data in Electron - Cameron Nokes
Where should I store the data? · Mac OS: ~/Library/Application Support/<Your App Name (taken from the name property in package.json)> · Windows: C ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found