# Multiple storage solution in one app

**URL:** <https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874>\
**Category:** Ionic React\
**Created:** [April 11, 2024, 2:46pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874 "2024-04-11T14:46:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stclaude](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@stclaude](https://forum.ionicframework.com/u/stclaude)\
**Post date:** [April 11, 2024, 2:46pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/1 "2024-04-11T14:46:40Z")

</div>

Hello everyone,

I’m relatively new to the Ionic Community and I’m looking to implement storage solution for my workout app. After doing my research I think the strength and weaknesses of Ionic Storage, Capacitor Storage, Preferences API and SQLite are clear, however it’s not clear to me if it would be a good practice to combine these solutions or if it’s the right fit for my use case, so I would like the input from the community.

The app should store:

1. User preferences
2. Plates inventory (what plates the user has available in the gym)
3. Records of each workout

Additionally, I will be providing workout performance statistics to the user.

It sounds to me that Preferences API would be the easiest way to story user preferences persistently.

The plates inventory could be stored with Ionic Storage as JSON since each plate only has about 7 properties, although the user will be able to store 100s of plates so I’m not sure how scalable that is. So maybe I should use a SQLite?

Last but not least, for the workout records, since I will be providing statics and need querying, sounds to me that SQLite is the way to go.

On any case, would you recommend to use multiple solutions in one app; Ionic for preferences, Ionic Storage(with SQLite plugin) for inventory, and SQLite for records. Or should I just use SQLite to store everything there? I’m a bit torn right now.

What would be a good way to go about this? Curious of what your thoughts are.

Thank you!

Claudio

---

<div class="post-metadata">

**Author:** ![Hills90210](https://avatars.discourse-cdn.com/v4/letter/h/57b2e6/32.png) [@Hills90210](https://forum.ionicframework.com/u/Hills90210)\
**Post date:** [April 11, 2024, 3:40pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/2 "2024-04-11T15:40:35Z")

</div>

> [@stclaude](#):
>
> It sounds to me that Preferences API would be the easiest way to story user preferences persistently.

I wouldn’t use this to store user preferences, as it states in the [docs](https://capacitorjs.com/docs/apis/preferences): This API is _not_ meant to be used as a local database since mobile OSs may periodically clear data.

Sounds like you already know what you need to do. Go the SQLite way. Also if your build an app like this, which stores lots of workout data from the user, you should look into [Secure Storage](https://ionic.io/docs/secure-storage).

---

<div class="post-metadata">

**Author:** ![twestrick](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/twestrick/32/136131_2.png) [@twestrick](https://forum.ionicframework.com/u/twestrick)\
**Post date:** [April 11, 2024, 4:31pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/3 "2024-04-11T16:31:46Z")

</div>

I think you misread the plugin docs 🙂 It says to use the Preferences plugin for **persistent** storage of lightweight data. It should be used over `localStorage` which might be cleared periodically.

For the OP’s use case, SQLite definitely sounds like the way to go. Might as well use it for everything to keep it simple, preferences, workout data, etc.

Agree on the encryption too. The [SQLite community plugin](https://github.com/capacitor-community/sqlite) says it supports encryption.

---

<div class="post-metadata">

**Author:** ![Hills90210](https://avatars.discourse-cdn.com/v4/letter/h/57b2e6/32.png) [@Hills90210](https://forum.ionicframework.com/u/Hills90210)\
**Post date:** [April 11, 2024, 5:44pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/4 "2024-04-11T17:44:30Z")

</div>

> [@twestrick](#):
>
> I think you misread the plugin docs 🙂 It says to use the Preferences plugin for **persistent** storage of lightweight data. It should be used over `localStorage` which might be cleared periodically.

> **Note** : This API is _not_ meant to be used as a local database. If your app stores a lot of data, has high read/write load, or requires complex querying, we recommend taking a look at a SQLite-based solution. One such solution is [Ionic Secure Storage](https://ionic.io/docs/secure-storage), a SQLite-based engine with full encryption support. The [Capacitor Community](https://github.com/capacitor-community/) has also built a number of other storage engines.

I see where it could it be misread, thanks 🙂, but depending on the case, user data is not lightweight and most definitely shouldn’t be used to store sensitive info like user data.

[ios user defaults](https://developer.apple.com/documentation/foundation/userdefaults):  
The parameters are referred to as _defaults_ because they’re commonly used to determine an app’s default state at startup or the way it acts by default. The defaults system allows an app to customize its behavior to match a user’s preferences.

[android shared preferences](https://developer.android.com/reference/android/content/SharedPreferences):  
SharedPreferences is not recommended for storing data that is sensitive to this kind of rollback to a prior state such as user security or privacy settings. SharedPreferences is best suited to storing data about how the user prefers to experience the app

If it’s minor data without sensitive information sure or passing data over to get in another component, sure why not. But OP hasn’t gave us enough info on what the user data is 🙂.

Also good to note, that its best to have 1 type of storage library to handle all these uses cases.

---

<div class="post-metadata">

**Author:** ![twestrick](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/twestrick/32/136131_2.png) [@twestrick](https://forum.ionicframework.com/u/twestrick)\
**Post date:** [April 11, 2024, 6:02pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/5 "2024-04-11T18:02:41Z")

</div>

Fair enough, makes sense 😁 For user preferences, I was thinking just general app preferences, light/dark mode preference, a preferred audio voice, auto advance or not, etc. As you said, we don’t know what the OP is looking to store here. Anything other than simple general preferences, 100% agree with you. Go with something more secure and robust.

---

<div class="post-metadata">

**Author:** ![stclaude](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@stclaude](https://forum.ionicframework.com/u/stclaude)\
**Post date:** [April 11, 2024, 8:01pm UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/6 "2024-04-11T20:01:34Z")

</div>

@Hills90210 @twestrick thank you so much for your answers. I will go with your suggestion of using SQLite and keep it simple. And also will do encryption to protect user’s information.

To share more insight I will be storing stuff like user’s height and weight, preferred metric(kg vs lb) and some other simple configurations for the app.

Appreciate the help y’all.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://forum.ionicframework.com/u/bluepuma77)\
**Post date:** [May 25, 2024, 8:17am UTC](https://forum.ionicframework.com/t/multiple-storage-solution-in-one-app/240874/7 "2024-05-25T08:17:07Z")

</div>

Just started with CapacitorJS, looked into SQLite, but the plugin wasn’t that easy to use. And currently you need a special version for v6 ([issue](https://github.com/capacitor-community/sqlite/issues/541)).

So I ran some tests with `Preferences` and it turns out it can save and load 1000 keys with JSON string in 0.2 sec. Persistence is probably delayed, doc states data is cached for faster access.

So for now our iOS MVP is using the easies solution, let’s see if we run into any trouble, then we will check other options.
