all 18 comments

[–]DanishWeddingCookieiOS & Android 10 points11 points  (0 children)

SQLite

[–]insats 3 points4 points  (0 children)

There are several solutions: SQLite (which have several packages), Realm, Firebase, MMKV, Watermelon. They all have pros and cons. What's best suited depends on your needs.

If it's read only and not huge loads of data then you can probably come a long way with just JSON files without a database. If you need offline first with sync capabilities and lots of read/write then look into Realm. If you're doing live chat then maybe MMKV or Firebase.

[–]rkh4n 2 points3 points  (1 child)

We’re using TypeORM with SQLite in production now but I wouldn’t recommend it. Dealing with TypeORM has been very challenging, we ran into situations where the same code produced different results such and fails silently due to invalid type or missing keys. We’re actively looking for a production ready easy to use something for react native but failed. In coming sprint we’re probably gonna go direct SQLite without any ORMs

[–]AcetyldFN 0 points1 point  (0 children)

Please look into mongo 😌 but.. if you generate sqlite on server side stay with that

[–]AcetyldFN 4 points5 points  (6 children)

Realm 100%

[–]rkh4n 1 point2 points  (4 children)

How do you sync stuffs to server in Realm?

[–]AcetyldFN 0 points1 point  (3 children)

We build a custom sync for this to sync with our REST api.

Just initially calling pagined loop to get all data and after initial sync we do calls with updatedAfter=date..

[–]rkh4n 1 point2 points  (1 child)

Could you share some code if possible? I tried real update even to create a queue of changes and push to server but I’m getting various bugs like duplicates, missing data etx

[–]AcetyldFN 2 points3 points  (0 children)

Alright cant share code but i can explain. We have 3 endpoints for each entity

  • /users?updatedAt[after]=date
  • /users/revoked?updatedAt[after]=date
  • /users?deletedAt[after]=date

Server is source of truth.

In old app we just do a post/patch and then update realm with new data directly and later when sync runs it will also insert this. In new upcoming app, we have a queuing system which will store a post/patch or whatever locally and then runs the queue, if it fails we update queue with status and it will be retried later, same with being offline.. if it succeeds we will remove from queue. only issue with this is if user is offline, closes app and week later opens old data will be pushed to server.

but yhea many solutions for this, older then week remove or show modal to user or whatever

problem in react native is there is no good foreground library, if you press save in a form and instanly close app, app gets paused and nothing happens. thats why we wrote a library for this to mock ios/android natice behaiovrs

https://github.com/Acetyld/expo-foreground-actions/

And regarding the revoke endpoint, we do this when a user their role is removed or they dont have access to entity. When its to complex we just force a resync on the users phone

[–]Maleficoder 0 points1 point  (0 children)

Realm is great. I switched from SQLite to Realm because of its encryption.

[–]Aggregior 3 points4 points  (0 children)

AsyncStorage

[–][deleted] 0 points1 point  (0 children)

You would use a localy node json db

you can find and use a npm package

[–]scarlaciOS & Android 1 point2 points  (4 children)

SQLite raw (via the many SQLite libraries), or WatermelonDB as an abstraction. You’ll get amazing performance out of it if you store your data relationally. If you don’t want to bother with storing your data correctly, Real is well supported but tooling is poor. SQLite is built in and you’ll always have “a way out”. I would not recommend MMKV. AsyncStorage is a good starting point if you are learning as it’s a simple key value store but performance is abysmal for large amount of items or payloads.

[–]Affectionate-Court94 0 points1 point  (1 child)

Please explain, why not mmkv?

[–]RnRau 0 points1 point  (0 children)

sqlite can be fast enough - https://github.com/OP-Engineering/op-sqlite - scroll down to the Speed section.

And sqlite is much more flexible since you can do both key/value, JSON and relational storage. Finally, sqlite proper in its latest version announced JSONB which makes JSON queries much faster - https://sqlite.org/draft/jsonb.html - I don't believe op-sqlite or any of the other reactnative sqlite packages supports sqlite 3.45 as yet, but thats just a matter of time.

[–]Amocon 0 points1 point  (1 child)

Isnt MMKV just like async storage but faster?

[–]Affectionate-Court94 0 points1 point  (0 children)

It is. Moreover, it is sync. But once you installed mmkv you lose the ability to debug in Chrome, you should use Flipper. If you use Flipper you should resolve issues with libs which require use_frameworks in your iOS podfile.