I want to have pre populated db with data for my application.
but i am not sure the best way to that.Do i need to create db at launch and populate data from a file or do i need to have db added into the resources file with data loaded. i want to read & write into the db
Pls let me know your opinions
You can add db file as resource. Add your data to the database file , then add the database to resources.
For reading from database, you can read it directly from resource bundle. If you want to write to database , then you must move the database file to Documents or Library Directory of your application.
Related
I'm creating a MERN project and want a file to seed data into my database. Using sql I've done this by creating a seed file with a .db extension which I would then run as a script in my terminal. I am wondering how this is done for MongoDB and what file extension I should use, is this just a json file? I am also wondering what the proper way of doing this is. I was looking online but I see so many different ways that people do things so I'm just trying to figure out what the standard is.
Create each collection in a separate JSON or CSV file, and use mongoimport
Currently I am working with the project in which I need to parse complex XML, which contains multilevel details (Name & Paths for PDFs, PNGs, etc) at each node.
I need to store all the data in local memory of iPhone/iPad.
Should I create classes for each of those details and make appropriate tables in SQLite or store the data as BLOB and retrieve all the data all the time?
Any Suggestions, thoughts are most welcome...
EDIT:
I am storing Files in DocumentsDirectory and path to SQLite database. Question is to create well defined database tables or to store data in BLOB form.
Pros and Cons for both approach would be much appreciated. Thanks.
in my opinion you should simply use BLOB : when you startup your app load you'r xml into an object all changes will be made to that object so you can win the time to rewrite back to disk
on exit application save all to disk..
Using of BLOB is not a good process .Store all pdf and images in Document directory..store that path only in DB...
We have an app in the app store right now that uses a pre-populated Core Data database. We want to update all the tables in the database, except for 1 table which is the Favorites table where users store their Favourite bus routes or stops. Currently, we are accomplishing this update having the app delegate use the SQLite C API, and NSFileManager to do the following:
Create a temporary Favorites database
Copy the favourites from the database on the disk to the temporary database
Delete the database on disk ([fileManager removeItemAtPath:storePath error:NULL] )
Copy the new database from the app bundle to disk ([fileManager copyItemAtPath:databaseBundlePath toPath:storePath error:©Error])
Copy Favourites from the Temp database into the new database.
Delete the temporary Favorites database.
I was wondering if there was another way to do this because there have been a lot of complaints with our app crashing during the splash screen which is the time where the database copying happens.
I heard of Core Data Migration, but my understanding of Core Data Migration is that you can migrate data only when a the model changes, but in our case the model hasn't changed.
Why don't you leave the database as it is and just insert/remove the data into it as needed instead of copying a prefilled database?
Alternatively you can also take the opposite approach: leave the original database, copy the prefilled one with a new name, insert the favorites from the original database into the new one, remove the original one, and now only use the new one. Like this, you are always sure nothing happens to your user's favorites.
Or you could write the favorites first into a text file, and then do the same thing you describe. If anything happens (like a crash), you always still have the favorites in the saved text file.
It also may work with core data migration, but up to now I avoided that ... any structural database change is something I would rather avoid, I think ...
I have an iPhone app that has a sqlLite Core Data model that is pre-loaded with default data. I want to enable the user to restore this default data if they have modified or deleted records from the model, while retaining any new records added to the model by the user.
The sqlLite database is copied to the users documents directory on first run, so the untouched original database is available in the app package. What is the easiest way to copy records between the two databases? I assume that it involves setting up an additional persistentStoreCoordinator, or adding the original dB to the coordinator as an additional persistentStore, but the docs are skimpy on how to do this.
Thanks,
Jk
If you do not want to delete the destination store and just overwrite it then the workflow is:
Stand up a second Core Data stack with the source persistent store.
Fetch each entity from the source.
Look for the object in the destination.
If it exists, update it.
If it doesn't, create it.
Save the destination store.
Depending on how much data you have, this can be a very expensive operation.
I have a CSV file containing data.
I want to load it into a Core Data managed sqlite db.
I just ran one of the sample Core Data Xcode apps and noticed it created the db file.
I noticed table names all started with Z and the primary keys were stored in separate table so from this am I right in presuming that just importing the CSV data directly into the db using sqlite3 command line might mess up primary keys.
Do I need to write a program to read in the CSV line by line and then create objects for each row and persist them to the db.
Anyone got any code for this?
And can I write a desktop client to do this using Core Data. If so will the db be fine to use in IPhone core data app?
Can I then just include the prefilled db in my project and it will be deployed with the app correctly or is there something else I should do.
Use NSScanner to read your CSV file into the NSManagedObject instances in your Core Data store.
I have some categories on NSString for reading and writing CSV files from/to NSArrays. I'll post them online and edit my answer with a link to it.
edit
They're online here: http://github.com/davedelong/CHCSVParser