Objective-c - How to store objects in database SQLite - sql

I'm curious to learn more about storing objects.
If I have an app that manage an office database where I have model object like Department, Employee, Task. How can I store them in the database?
Should I create a table for each model and store the primitive instance values like name, id, surname ? Or should I store the object itself?
Which is the right approach??
To better understand:
How an app like whatsapp or kik (both chat/messaging application) store their data in their server? Do they use coredata or databases? Do they save primitive values or objects?

A popular pratice is to use Core Data to store locally and use Web API to sync with server.
For example, we're developing an app using Core Data to map objects to SQLite, handled by API apple provided, and using RestKit, an third-party library to map objects to requests understandable to server API, thus, you can see your data published on server
Not quite sure it's what your're asking for, this pratice is straightforward for manipulating complicated objects, compared to using SQL directly.

Related

Convert an online JSON set of files to a relational DB (SQL Server, MySQL, SQLITE)

I'm using a tool called Teamwork to manage my team's projects.
The have an online API that consists of JSON files that are accessible with authorisation
https://developer.teamwork.com/projects/introduction/welcome-to-the-teamwork-projects-api
I would like to be able to convert this online data to an sql db so i can create custom reports for my management.
I can't seem to find anything ready to do that.
I need a strategy to do this..
If you know how to program, this should be pretty straightforward.
In Python, for example, you could:
Come up with a SQL schema that maps to the JSON data objects you want to store. Create it in a database of your choice.
Use the Requests library to download the JSON resources, if you don't already have them on your system.
Convert each JSON resource to a python data structure using json.loads.
Connect to your database server using the appropriate Python library for your database. e.g., PyMySQL.
Iterate over the python data, inserting rows into the database as appropriate. This is essentially the JSON-to-Tables mapping from step 1 made procedural.
If you are not looking to do this in code, you should be able to use an open-source ETL tool to do this transformation. At LinkedIn a coworker of mine used to use Talend Data Integration for solid ETL work of a very similar nature (JSON to SQL). He was very fond of it and I respected his opinion, so I figured I should mention it, although I have zero experience of it myself.

Can I retrieve data from the server and store it in core data?

I'm a newbie and working on a pull to refresh app.
I have watched the tutorial of using Sqlite3 in ios6 to build data driven app. When the user pull to refresh the app will load the data from the server and then store it locally and display it on the tableView and the user can also edit and save back to the server.
Can this be done using core data not Sqlite3? because I find it really difficult to make Objective-C interface that will interact with C language (the Sqlite3).
Or are there any better solution?
You can use Core Data for this task. You can use Mogenerator with Core data to create a core data model for you. Then use Magical Records to easy saving and fetching of core data. These two libraries make Core Data super simple and nice. As for pulling info from the server, you'll have to model the data recieved to the models created by Mogenerator and then save them into core data. Again with taking data from core data and pushing it to a server, depending on what you're using to communicate with the server, you'll need to create a dictionary to mimic the JSON you'll need to send to the server and then push it off. As far as I know theres nothing to directly communicate the info from Core Data directly to the server. Anyway you'll probably have to play around with this concept, but my recommendation is definitely use Mogenerator to get the core data NSManagedObjects and then MagicalRecord for super easy saving and fetching.

Sencha Mysql Queries

I'm about to port an Android-Travellog App to other Plattforms using Sencha Touch.
The Problem is, that Sencha only has a Store System to store Data, but doesnt appear to have a possibilty to acctually make MySql queries.
And since most of the Mysql code in my previous app is already there, id would be quite a pain to redo everything with Senchas new System.
Is there a possibilty to use mysql (or any other sql) queries with Sencha to Store Data on the Phone?
Sencha stores and proxies abstract away the need to write raw query code. A store can use one of a number of different proxies for interfacing with different back-end data stores, one of which is the SQL proxy, which as you can see in the source code provides an API for basic data querying WebSQL databases.
If you want to gain the full benefit of the framework and do things the "Sencha way" you'll probably want to start from scratch and architect your app to use the stores API.

Xcode iOS phone directory app. core data, sql lite, or

as part of an application I am trying to create, I am looking to data storage solutions. However, I have found many solutions that I can not quite directly apply to the position I am in.
Basically, I want to display in my app, a directory of the staff of my organization. About 100 or so individuals. I want to have generic attributes such as name, email, office#, etc.
However, my goal is to not end up with a static representation of the staff here! (people come and go, switch offices,etc.)
I am looking for the best way (if possible) to maintain a small database that I can administer, and if perhaps, something were to change to someone here, I can make the change and the change will be reflected accordingly.
Please help! I tried submitting my first app but got rejected because I relied on a webview to accomplish this task. This is an internship opportunity and my first real chance at development. Any help will be GREATLY appreciated.
Thanks!!!!!
The iPhone directory app can be used to store data in any format you want (xml, json or a proprietary format), because all you do is save a file. But if you choose to use the iPhone app directory to store data you have to write code to read the file (very simple to do) and parse the information (not so simple because the dificulty scales based on the information complexity).
SQLite is a tool to store structured data, providing you a set of tools to access and use the information. You don't need to parse the information, because SQLite does it for you by using transact sql queries.
By now, because you have a list of individuals, and these people are relationed to offices, I think you should use SQLite.
The Code Data is a object graph management, it's a tool to give you more options over data manipulation, and can make your life very easy if you have a lot of data and very complex data models. I don't think you need that for your particular problem, but I think you should learn it at some point.
UPDATE 1
You application will have something like:
A core database (sql server, oracle, my sql, etc) will hold your individuals information (your cloud database).
A web page (php, asp.net, etc) will display the core database information in json or xml format (your api).
A iphone app will download the information from the web page and store it in the local SQLite. (you have to decide when you will update the local sql lite, like when is opened, once a week, once a moth, twice a day, etc) (your local storage method).
Display the local SQLite individuals information in the app.

Using Core Data in remote SQL

I want to use Core Data for managing remote sql server. Is that possible? I checked through the apple documentation and it only shows about SQLite, but on CS193P stanford lectures they say that it is possible to do, but don't say how?
I currently use a bridge with php queries, but that is not OOP way
Thank you.
According to Apple, the answer is no:
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”).