核心数据vs SQLite 3 [英] Core Data vs SQLite 3

查看:101
本文介绍了核心数据vs SQLite 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经非常熟悉关系数据库,并使用 SQLite (和其他数据库)以往。但是,核心数据有一定的诱惑,因此我正在考虑花一些时间学习它

I am already quite familiar with relational databases and have used SQLite (and other databases) in the past. However, Core Data has a certain allure, so I am considering spending some time to learn it for use in my next application.

使用Core Data over SQLite有很多好处,反之亦然吗?

Is there much benefit to using Core Data over SQLite, or vice versa? What are the pros/cons of each?

我发现很难证明学习核心数据的成本,因为苹果不会将它用于许多旗舰应用程序,例如Mail.app或iPhoto.app - 而不是选择SQLite数据库。 SQLite也在iPhone上广泛使用。

I find it hard to justify the cost of learning Core Data when Apple doesn't use it for many of its flagship applications like Mail.app or iPhoto.app - instead opting for SQLite databases. SQLite is also used extensively on the iPhone.

那些熟悉使用这两个评论的用户体验?

Can those familiar with using both comment on their experience? Perhaps, as with most things, the question is deeper than just using one over the other?

推荐答案

虽然核心数据是一个子孙的Apple的企业对象框架,一个对象关系映射器(ORM)到关系后端,Core Data不是一个ORM。事实上,它是一个对象图管理框架。它管理对象实例的潜在非常大的图形,允许应用程序使用图形工作,该图形根据需要通过在内存中断开对象而不完全适合内存。核心数据还管理关于属性和关系的约束以及维护引用完整性(例如,当对象被添加到关系或从关系中删除对象时,保持向前和向后链接一致)。核心数据因此是构建MVC架构的模型组件的理想框架。

Although Core Data is a descendant of Apple's Enterprise Object Framework, an object-relational mapper (ORM) that was/is tightly tied to a relational backend, Core Data is not an ORM. It is, in fact, an object graph management framework. It manages a potentially very large graph of object instances, allowing an app to work with a graph that would not entirely fit into memory by faulting objects in and out of memory as necessary. Core Data also manages constraints on properties and relationships and maintins reference integrity (e.g. keeping forward and backwards links consistent when objects are added/removed to/from a relationship). Core Data is thus an ideal framework for building the "model" component of an MVC architecture.

为了实现其图形管理,核心数据使用sqlite作为磁盘存储。可以使用不同的关系数据库或甚至非关系数据库(如 CouchDB)实现 。正如其他人指出的,Core Data还可以使用XML或二进制格式或用户编写的原子格式作为后端(尽管这些选项要求整个对象图适合内存)。如果您对如何在sqlite后端实施Core Data感兴趣,您可能需要查看OmniGroup的 OmniDataObjects 框架,Core Data API子集的开源实现。 BaseTen 框架也是使用PostgreSQL作为后端的Core Data API的实现。

To implement its graph management, Core Data happens to use sqlite as a disk store. It could have been implemented using a different relational database or even a non-relational database such as CouchDB. As others have pointed out, Core Data can also use XML or a binary format or a user-written atomic format as a backend (though these options require that the entire object graph fit into memory). If you're interested in how Core Data is implemented on an sqlite backend, you might want to check out OmniGroup's OmniDataObjects framework, an open source implementation of a subset of the Core Data API. The BaseTen framework is also an implementation of the Core Data API using PostgreSQL as a backend.

因为Core Data不是为sqlite的ORM,它不能读任意的sqlite模式。相反,你不应该依赖于使用其他sqlite工具读取Core Data的sqlite数据存储;该模式是一个可能改变的实现细节。

Because Core Data is not intended to be an ORM for sqlite, it cannot read arbitrary sqlite schema. Conversely, you should not rely on being able to read Core Data's sqlite data stores with other sqlite tools; the schema is an implementation detail that may change.

因此,直接使用Core Data或sqlite之间没有任何冲突。如果您想要关系数据库,请使用sqlite(直接或通过一个Objective-C包装器,如 FMDB )或关系数据库服务器。但是,您可能仍需要了解Core Data以用作对象图管理框架。结合Apple的控制器类和键值绑定兼容的视图小部件,您可以使用很少的代码实现一个完整的MVC架构。

Thus, there is not really any conflict between using Core Data or sqlite directly. If you want a relational database, use sqlite (directly or via one of the Objective-C wrappers such as FMDB), or a relational database server. However, you may still want to learn Core Data for use as an object graph management framework. In combination with Apple's controller classes and key-value binding compatible view widgets, you can implement an complete MVC architecture with very little code.

这篇关于核心数据vs SQLite 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆