I'm just starting and taking some hard hits with SQLite Capacitor

I’m currently developing an Ionic 7 React application using Capacitor and attempting to integrate SQLite. However, I’m encountering difficulties getting SQLite to function properly. I’ve been working on this for several days now, and it’s proving to be quite challenging.

Could someone please provide an example app demonstrating CRUD operations with Ionic 7 React and SQLite? Alternatively, if there’s a comprehensive guide available, I’d greatly appreciate it. Initially, I considered using Ionic Storage, but I’m unsure if a Key-Value approach is suitable for my requirements (though I’m open to suggestions if anyone has nice ideas on its usage).

To provide some context for my application, I’m developing an Ionic app for mobile platforms (Android and iOS) that interacts with an API containing a substantial database. I need to store JSON data for students, classes, teachers, observations, reports, etc. The intention is to store only the data from the last month locally, with regular deletion of older data (requiring an internet connection for accessing older data). Additionally, the app needs to support various filters allowing users to filter by class date, school, discipline, students, etc.

Furthermore, if a user logs in with a different account, the local database should be cleared and replaced with data corresponding to the new user.

1 Like

Are you using the Community SQLite plugin? - GitHub - capacitor-community/sqlite: Community plugin for native & electron SQLite databases

How much data are we talking that you need to store? My app is currently using 1.85 MB of storage using Ionic Storage. Each key is a “table” and value is an encoded JSON string of all the records. On app load, all the data gets loaded into memory in my Pinia store in Vue. I know that isn’t much storage use, but at that, the app still loads really fast.

Thanks for the answering. So, i’m doing some estimates here and it actually might be around 3 MBs, lower than i expected.
I’m actually managing to make SQLite to work, but now you gave me a quite good idea indeed.

1 Like

The only thing that i’ll have to figure out is how do i make it synchronizing with the server. The idea is that only data that was edited would be sent from the app to the server and from the server to the app checking a key in the json named "Sync: " that can be “true” or “false”.

I know there are some DBs out there that help with that. They have been discussed in this forum previously by others but I don’t recall what they are.

I’ll keep searching, i saw Rxdb, but as i didn’t find a significant community around it, i prefered to stay away from it.

Maybe pouchDB could be an option?

Again, thx for answering.

1 Like

Yeah, PouchDB is the one I’ve seen mentioned here. I have no experience with it though.

For anyone who find themselves here with the same problem, i suggest looking at this post: Ionic React Sqlite

My problem is now solved. This aaronksaunders guy is a saver.

2 Likes

I want to print this comment, frame it, and send it to Aaron.

1 Like