最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Distant and local database synchronization: how to manage temporary IDs? - Stack Overflow

programmeradmin1浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论