将Core Data数据与外部数据库同步
我已经开始开发一个 iPhone 应用程序,我需要将数据与外部 MySQL 数据库同步。当前的数据库方案使用 GUID/UUID 字段作为主键来维护表之间的关系。我已经在数据库应用程序和 MySQL 数据库之间进行了此工作,因此这不是一个关于同步的问题。
我已经开始使用 Core Data,但我意识到它使用 SQLite 数据库中自己的模式来维护实体之间的关系。
我使用 Core Data 是否走上了错误的道路?如果不是,如何在核心数据存储和外部数据库之间同步数据并仍然维护数据关系?
I have started working on an iPhone application that where I need to synchronize data with an external MySQL database. The current database scheme uses GUID/UUID fields as primary keys to maintain relationships between tables. I already have this working between a database app and the MySQL database, so this isn't a question regarding synchronization per say.
I've started going down the path of using Core Data, but I'm realizing that it maintains relationships between entities using it's own schema within the SQLite database.
Am I going down the wrong path using Core Data? If not how does one synchronize data between a Core Data store and an external database and still maintain the data relationships?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所需要做的就是编写逻辑以将实体从一种数据库模式转换为另一种数据库模式。您可以从服务器获取对象并将其转换为核心数据对象,并在保存到服务器时从核心数据获取对象并将其转换为mysql实体。确实没有什么太困难的事情
All you need to do is write the logic to translate entities from one db schema to another. You can fetch objects from the server and convert them to core data objects, and fetch object from core data and convert them to mysql entities when saving to the server. Nothing too difficult involved really
我同意格里福的观点;只需将从 mysql 数据库检索的行或实体转换为托管对象(反之亦然)。
如果我正确理解你想要什么,我肯定会推荐使用核心数据。在 MySQL 和 Core Data 之间转换数据并不难,如果您使用 NSFetchedResultsController 在 UITableView 中显示数据,您实际上不需要编写任何代码。
I agree with Griffo; simply translate the rows or entities you retrieve from the mysql database into managed objects (and visa versa).
If I understand what you are looking to correctly, I would definitely recommend using Core data. Translating the data between MySQL and Core Data isn't that hard, and if you use an NSFetchedResultsController to display your data in a UITableView, you practically don't have to write any code.
并且您始终可以保留原始 GUID 作为导入实体的可选外部 ID。通过这种方式,您将能够更轻松地排除数据导入故障,并将数据存储类型之间的数据关联起来。
and you can always preserve the original GUIDs as, for example, optional externalIDs for the imported entities. This way you will be able troubleshoot your data imports easier and correlated the data between the to types of the data stores.