核心数据与SQLite for SQL经验丰富的开发人员 [英] Core Data vs. SQLite for SQL experienced developers

查看:94
本文介绍了核心数据与SQLite for SQL经验丰富的开发人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发iPhone Enterprise开发者计划中的内部应用程序。由于它接近OS 3.0,我们重新考虑我们使用SQLite和使用Core Data的原始设计。以下是一些详细信息:




  • 有一个旧桌面应用程序正在替换。我们将重用现有的后端。

  • 我们目前有一个SQLite数据库生成的概念证明。这基本上是现有后端数据库的缩减版本。

  • 我们将从远程站点加载数据,并将其存储在本地,它将持续存在并且需要。我们只更新它,如果它已经改变,这将是每一个月或两个。

  • 这个项目有两个开发人员,我们都有强大的SQL技能,但没有人使用Core Data。



我的问题是:Core Data对SQLite的好处是什么,在这个特定实例中有什么好处,框架而不是使用现有的强大的SQL技能?



编辑:
我只是注意到这个问题: Core Data vs SQLite 3 。我想我的问题是:




  • 如果我必须检查特定的项目是否存在或有更新,这很容易使用SQL ,Core Data仍然有意义吗?

  • 如果我们已经知道SQL,Core Data对这个项目的优势是否能证明我们的学习能力?

    正如您已阅读 .com / questions / 523482 / core-data-vs-sqlite3> Core Data vs SQLite 3 ,你知道Core Data和持久化机制(在这种情况下是SQLite)在很大程度上是正交的。核心数据真的关于管理对象图,它的主要用例是MVC架构的模型组件。 如果您的应用程序非常适合这种架构,可能值得使用Core Data,因为它会在模型​​组件中节省大量代码。如果你已经有一个工作模型组件(例如从现有的桌面应用程序),那么Core Data将不会买你。混合方法是可能的 - 您可以进行自己的持久性/查询,并在内存存储中构建Core数据,您可以使用查询结果填充该数据,并通过Core Data将此内存存储用作应用程序的模型组件。



    要回答您的具体问题:


    $ b这是不常见的,但我已经完成了,没有重大的障碍。 $ b


    1. 您可以为整个持久性存储分配版本号,并通过 + [NSPersistentStore metadataForPersistentStoreWithURL:error:] ,甚至没有打开商店。当然,还存在一个等效的 + setMetadata:forPersistentStoreWithURL:error 。如果要将版本信息存储在实体实例中而不是存储在持久存储元数据中,则只能加载单个对象。使用SQLite持久化存储,Core Data在获取所需内容方面做得非常好。


    2. NSPredicate API,非常容易学习,它似乎做了一个体面的工作,编译到SQL。至少对于你可以适合在iPhone上的大小的数据库,它肯定是足够的(性能明智)在我的经验。我认为SQL与核心数据问题有点误导,但是。一旦你得到一个查询的结果,你打算做什么?如果你自己滚动,你必须实例化对象,处理故障/唯一(如果你不想立即加载一个查询的整个结果到内存)和所有其他对象图管理设施已经提供了Core数据。



    We're beginning development of an in-house app in the iPhone Enterprise developer program. Since it's close to OS 3.0, we're reconsidering our original design of using SQLite and using Core Data instead. Here's some more info:

    • There is a legacy desktop application that this is replacing. We will reuse the existing back end.
    • We currently have a SQLite database generated as a proof of concept. This is basically a cut down version of the existing back end database.
    • We will be loading data from a remote site and storing it locally, where it will persist and need to be . We only update it if it has changed, which will be every month or two. We will most likely use XML or JSON to transfer the data.
    • There are two developers on this project and we both have strong SQL skills but neither one has used Core Data.

    My questions are: what is the benefit of Core Data over SQLite, what would the benefit be in this specific instance and do the benefits justify learning a new framework instead of using existing strong SQL skills?

    EDIT: I just noticed this question: Core Data vs SQLite 3. I guess my questions therefore are:

    • If I have to check if a specific item either exists or has an update, which is easy using SQL, does Core Data still make sense? Can I load the first object in a graph and check the version number without loading the whole graph?
    • If we already know SQL, does the advantages of Core Data for this one project justify us learning it?

    解决方案

    As you've read Core Data vs SQLite 3, you know that Core Data and the persistence mechanism (SQLite in this case) are largely orthogonal. Core Data is really about managing an object graph and it's main use case is for the model component of an MVC architecture. If your application fits nicely into this architecture, it's probably worth using Core Data as it will save you a lot of code in the model component. If you already have a working model component (e.g. from the existing desktop app), then Core Data won't buy you much. A hybrid approach is possible-- you can do your own persistence/querying and build a Core Data in memory store which you populate with the result of a query and use this in-memory store via Core Data as the model component for your app. This isn't common, but I've done it and there are no major roadblocks.

    To answer your specific questions:

    1. You can assign a version number to the entire persistent store and retrieve that information via +[NSPersistentStore metadataForPersistentStoreWithURL:error:], without even opening the store. An equivalent +setMetadata:forPersistentStoreWithURL:error also exists, of course. If you want to store the version info in an entity instance instead of in the persistent store metadata, you can load only a single object. With an SQLite persistent store, Core Data does a very good job of fetching only what you need.

    2. The NSPredicate API, is very easy to learn and it seems to do a decent job of compilation to SQL. At least for databases of the size you could fit on an iPhone it's certainly been adequate (performance wise) in my experience. I think the SQL vs. Core Data question is slightly misguided, however. Once you get the result of a query what are you going to do with it? If you roll your own, you'll have to instantiate objects, handle faulting/uniqueing (if you don't want to load the entire result of a query into memory immediately) and all of the other object graph management facilities already provided by Core Data.

    这篇关于核心数据与SQLite for SQL经验丰富的开发人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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