核心数据与数据库的根本区别? [英] Core Data vs. Database fundamental difference?

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

问题描述

有人可以向我解释Core Data(显然是数据存储)和SQLite或MySQL之类的数据库之间的根本区别吗?

Can someone explain to me what the fundamental difference is between Core Data (apparently, a "data store") and a database like SQLite or MySQL?

致力于编写iPhone应用程序,并需要一个静态数据表来显示。我认为核心数据将是一个不错的选择,所以我得到一切设置和运作到数据库(对不起 - 数据存储)去,然后去尝试导入我的数据(它是在一个excel文件,我导出到CSV)。我认为它应该是一个直接的过程,像我在SQLite和其他数据库做了很多次,但事实证明,经过大量的研究,唯一的官方的方式做到这一点是专门为我的数据写一个解析器。

I am working on writing an iPhone app, and needed a table of static data to display. I thought core data would be a good choice for this, so I got everything set up and functioning as far as the database (i'm sorry - data STORE) went, and then went to try to import my data (it was in an excel file which I exported to CSV). I was thinking it should be a straight forward process like I have done in SQLite and other databases many times, but as it turned out after much research, the only "official" way to do this was to write a parser specifically for my data.

当我在苹果开发者论坛上提到这个问题时,我得到的答案基本上是你认为你可以直接导入数据,编写代码来做它?核心数据不是数据库 - 它是一个数据存储!对于我的生活,虽然,我看不到的区别。在我看过的每一种方式中,核心数据的行为都像数据库一样,有一种奇特的访问方式和足够的抽象,它可以使用各种文件格式来实际存储数据。事实上,我最终能够使用一个简单的SQLite .import命令导入我的数据,所以我真的不明白为什么这个概念对于我的原始问题的响应者是如此陌生。

When I asked about this on the Apple Developer forums, the response I got was basically "What kind of idiot are you to think that you could possibly import data directly without having to write code to do it? Core data isn't a database- it's a data STORE!!" For the life of me, though, I can't see the distinction. In every way I have looked at it, core data behaves EXACTLY like a database, with a fancy way of accessing it and enough abstraction that it can use a variety of file formats for actually storing the data. In fact, I was eventually able to import my data using a simple SQLite .import command, so I really don't understand why the concept was so foreign to the responders to my original question.

那么我在这里缺少什么?数据存储与数据库的根本区别是什么,使得简单数据导入的概念与那些知道该技术的人完全不同?

So what am I missing here? What is so fundamentally different about a data store from a database that makes the concept of simple data importing completely alien to those who know the technology?

推荐答案

核心数据不仅仅是一种将数据持久存储到磁盘和从磁盘存储数据的方法,就像SQL一样。 Core Data的真正功能是为Apple API使用的Model-View-Controller应用程序设计提供完整的模型层。这样的核心数据主要是一个对象图管理器,持久性选项粘到一边。

Core Data is not simply a means of persisting/storing data to and from disk as is SQL. Core Data's true function is to provide the complete model layer for the Model-View-Controller app design that the Apple API uses. As such Core Data is primarily an object-graph manager with persistence options tack onto the side.

对象图是内存中活动对象的集合。在Core Data中,这些是受管对象。它们被称为托管对象,因为托管对象上下文不断地监视对象,以确保它们处于数据模型说明他们应该在的状态和关系。

An object-graph is a collection of live objects in memory. In Core Data, these are the managed objects. They are called "managed" objects because the managed object context observes the objects constantly making sure they are in the states and relationships that the data model says they should be in.

Core Data提供持久性选项,但是对于任何特定实现,该选项是很大程度上隐藏的。您甚至可以在同一个应用程序中使用具有不同持久性方法的相同数据模型和托管对象。

Core Data does provide persistence option but exactly what that option is for any particular implementation is largely hidden. You can even use the same data model and managed objects with different persistence methods, sometime in the same app.

与SQL的主要区别在于,SQL将实际数据写入而Core Data将活动对象序列化。当您查看Core Data中的sqlite商店时,您正在查看已拆分并冻干的对象。显然,冻结对象在sqlite存储中需要相当具体的数据格式,因此Core Data存储使用自己的自定义模式,无论存储的详细情况如何,都基本相同。

The key difference with SQL is that SQL writes the actual data to disk whereas Core Data serializes live objects. When you look at a sqlite store in Core Data you are looking at objects that have been taken apart and "freeze dried". Obviously, "freeze drying" objects requires a rather specific data format in the sqlite store so the Core Data store uses its own custom schema that is largely the same regardless of details of the store.

这就是为什么你不能交换任何旧的SQL文件,并希望Core Data导入它。 SQL文件是数据的行,表和列,而不是专用表,列和行用于重构冻结对象。

That is why you can't just swap in any old SQL file and expect Core Data to import it. The SQL file is rows, tables and columns of data and not a specialized tables, columns and rows use to reconstitute freeze dried objects.

由于Core Data首先是一个对象图管理器,导入数据的唯一支持和可靠的方法是创建对象图。在SQL文件的情况下,这意味着使用SQL api读取SQL数据,然后从该数据生成托管对象,然后将它们保存到持久存储。

Since Core Data is first and foremost an object-graph manager, the only supported and reliable means of importing data is to create the object-graph. In the case of an SQL file, that means reading the SQL data using the SQL api and then generating managed objects from that data and then saving them to a persistent store.

这部分更多的工作,但你节省时间将数据集成到应用程序的其余部分,升级数据和增加可靠性和可维护性。

That part is more work but you save time integrating the data into the rest of the app, upgrading the data and gains in reliability and maintainability.

这篇关于核心数据与数据库的根本区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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