如何在核心数据中导入数据库模式 [英] how to import databse schema in core data

查看:107
本文介绍了如何在核心数据中导入数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的核心数据中导入数据库模式,我是基于视图的应用程序和核心数据手动添加。



我创建了一个新的数据模型,现在我想要导入我在.sql文件中获得的数据库模式,是否可以导入该模式或我需要手动创建所有表?

解决方案

请注意,Core Data是一个对象图表持久化框架,而不是一个数据库本身



虽然Core Data可以通过sqlite存储来支持,但对于大部分,实现细节是不透明的。在任何情况下,您将无法将 sql 备份到Core Data模型。



我的建议您决定核心数据是否是适合您的框架,在这种情况下,您应该通过在模型构建工具中创建实体和关系,或者如果您热衷于保留数据库模式,然后查看原始sqlite周围的Cocoa包装器,例如Gus Mueller的 FMDB



查看核心数据编程指南。在常见问题中的是这个Q / A:


如何使用我现有的SQLite数据库与Core Data?

$ b $ 虽然Core Data支持SQLite作为其持久
存储类型之一,但数据库格式是私有的。您不能使用本地SQLite API创建
SQLite数据库,并直接使用Core
数据(也不应使用本地SQLite API操作现有Core Data SQLite存储库
)。如果你有一个现有的SQLite数据库,你
需要将它导入一个Core Data存储(参见有效导入
数据)。



I want to import database schema in my core data, i am a view based application and core data added manually.

I created a new data model , now i want to import database schema which i got in .sql file, is it possible to import that schema or I need to create all tables manually?

解决方案

Note that Core Data is an object graph persistence framework rather than a database per se. It may be subtle distinction but an important one when you consider trying to do something like what you are proposing.

While Core Data can be backed by a sqlite store, for the most part, the implementation details are opaque. In any case you won't be able to back-port your sql to a Core Data model.

My recommendation is for you to decide whether Core Data is the right framework for you, in which case you should work with it by creating your entities and relationships in the model builder tool or alternatively, if you are keen on keeping your database schema, then looking at Cocoa wrappers around raw sqlite, such as Gus Mueller's FMDB

Take a look at the Core Data Programming Guide. Among the FAQ's is this Q/A:

How do I use my existing SQLite database with Core Data?

You don’t. Although Core Data supports SQLite as one of its persistent store types, the database format is private. You cannot create a SQLite database using native SQLite API and use it directly with Core Data (nor should you manipulate an existing Core Data SQLite store using native SQLite API). If you have an existing SQLite database, you need to import it into a Core Data store (see "Efficiently Importing Data").

这篇关于如何在核心数据中导入数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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