Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I import data from a REST call, json feed into a SQLite database on a MAC?

Tags:

I have data that's on my server in a SQL Server database. I can access that with a REST call into a C# ASP.Net Web.API that I have control over and it will return json data. Possibly I can get that to return other formats of data but I am not sure about that. I have full access to the server application and the json it creates.

On my development Mac I am using DB Browser for SQLite and Xamarin to develop a multi-platform app. I have a small SQLite database created.

How can I import/insert the JSON data from some of my tables on the server to tables in the SQLite database that I create on my MAC? I need to do this manually but I would like to automate the process of doing the import into a bash script or something similar that I can run with a command.

I have researched this but don't seem to be able to find any examples of how to do it so I opened up a bounty in the hope that someone could give an answer that would be a big help to me and to others.

like image 841
Alan2 Avatar asked Aug 15 '16 17:08

Alan2


1 Answers

Off the top of my head, you have two options that you can do:

  • Make a simple Xamarin.Mac app that does this. Similar to how windows folks might make a console app. Just have it have one button and call pretty much the same code in your xamarin app to download the data and dump it into a sqlite db.
  • A better option, would be to write a "unit test" (or integration test for those hardcore peeps) that calls the existing code in your xamarin app and writes it to a sqlite db on the file share. Then you can do this as often as you want with a run of a unit test. This could be done in your test runner in Xamarin Studio (Visual Studio or anything that has a test runner). I would use either nUnit or xUnit since they great cross-platform support.

In my previous app, I had XUnit tests that checked to make sure the API calls were working and other tests to ensure that my SQLite.Net-PCL code was working. You could combine that into a single "test" to download the data into a db3.

This assumes you abstracted your code out. If not, you could just copy and paste it. Either way, if you are using x-plat nuget packages the code will work on desktop or mobile app.

like image 174
valdetero Avatar answered Nov 09 '22 18:11

valdetero