Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data data schema from existing SQLite database

Is it possible to generate a .xcdatamodel (CoreData data model) from an existing SQLite database file?

I've developed a SQLite database and written a Java API against it. Now, I need to write an equivalent iOS API to the same database (file). I'd prefer not to create the data schema by hand in xCode. I just want to generate the .xcdatamodel, and use xCode to generate the entity classes that I'll code against.

Is it possible?

like image 485
retrodrone Avatar asked Jun 17 '11 16:06

retrodrone


People also ask

How do I connect to an existing SQLite database?

Use the connect() method To establish a connection to SQLite, you need to pass the database name you want to connect. If you specify the database file name that already presents on the disk, it will connect to it. But if your specified SQLite database file doesn't exist, SQLite creates a new database for you.

How do I get SQLite schema?

The schema table looks like this: CREATE TABLE sqlite_schema( type text, name text, tbl_name text, rootpage integer, sql text ); The sqlite_schema table contains one row for each table, index, view, and trigger (collectively "objects") in the schema, except there is no entry for the sqlite_schema table itself.

Is Core Data equal to SQLite?

The most important difference between Core Data and SQLite is that SQLite is a database while Core Data is not. That is the most important difference because there is very little to compare. Core Data and SQLite are solutions to different problems.


3 Answers

See How do I use my existing SQLite database with Core Data? and Efficiently Importing Data. I understand that you're not asking specifically about using the entire database but just creating the model, but you have to understand that there's not a 1-1 relationship between an existing SQLite database and what Core Data wants to store.

like image 98
Caleb Avatar answered Oct 01 '22 02:10

Caleb


Try the following tool which wil generate the Datamodel from existing Sqlite

https://github.com/tapasya/Sqlite2CoreData

like image 45
legend Avatar answered Oct 01 '22 02:10

legend


No. Core Data is not just a thin wrapper around SQLite. It's an object store that can (optionally) be persisted to a SQLite database. This means that Core Data models do not have a direct mapping to the SQLite database.

In your case I'd recommend using one of the SQLite wrappers that are available (I've not used any of them so I couldn't recommend any one in particular).

like image 42
Stephen Darlington Avatar answered Oct 01 '22 01:10

Stephen Darlington