#Should we use an ORM for client side SQLite?

10 messages · Page 1 of 1 (latest)

loud stirrup
#

Hi we have a native RN app that are considering using Tanstack DB since we need full offline support while being able to sync through an API and we have no direct database access on the BFF, we are just integrating with a 3rd party API that has MongoDB.

Is it recommended to have an ORM like Prisma or such for your client side SQLite db for persistence, querying etc or not to get prisma studio and such?

We need to have optimistic updates on a lot of mutations but not all, reactive queries and such so that they update when we mutate things and sometimes our mutations will have side effects on other entities without triggering a new API mutation request for the side effect changes.

bold forge
#

DB is the ORM 😆 so you don't need another one

loud stirrup
#

Ah that's a good explanation 😂
Thanks!

loud stirrup
# bold forge DB is the ORM 😆 so you don't need another one

One more question, is there some way to ensure mutation requests are processed serially so that there is no concern for race conditions or being offline for a long time causing issues when you go back online and suddenly a new online request is received before an older one etc?

bold forge
#

you have to install the offline transactions package to actually store transactions offline

#

that does serial persistence but you can also use the paced mutations hook for serial online persistence

loud stirrup
#

Ah I guess we need to use the paced mutations hook then.

I am using the offline-transactions package as well I just want to ensure that if we have something sending multiple mutations in a row they are processed in order and next one isn’t sent until the previous one is done for the same mutation scope

bold forge
#

yeah you'd want both then I think (though check if offline-transaction always serializes writes? I don't think it does but it might)

loud stirrup
# bold forge yeah you'd want both then I think (though check if offline-transaction always se...

Hmm does Tanstack DB somewhat expect you to be able to set the ID of created entities from the client?

Feels like I am running into quite a few edge cases not that well supported since it's more of a bad 3rd party API foundation that limits us from doing it properly.

Support server-owned IDs without client-issued canonical IDs and then map temp IDs to real IDs

Like when I do a submit of one thing I need to optimistically update two other entities that should not trigger any requests.

I need to clear the optimistic state after a refetch.

For the web aspects I figured we can't really use wasm and have to use the session storage instead because the data is quite sensitive.