admin管理员组

文章数量:1393109

I want to have a copy of my database locally. But on this local copy, I can create new items.

I want the distant database to create item IDs, to avoid duplicate IDs.

So when I create new items, I use temporary IDs on the local database. When I send newly created items to the database using an API, it returns a mapping object between old and new IDs.

In local databases (for instance IndexedDB on web app or SwiftData on my iOS app), ID are unique and can't be edited. So I just create a new object which is a copy of the new one, but with the definitive ID.

Is that a good practice? How are we supposed to sync a local database and a distant database when the local one creates items with temporary IDs?

Thank you very much!

本文标签: Distant and local database synchronization how to manage temporary IDsStack Overflow