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

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


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.


i would use node js to write a script using javascript.

install nodejs. https://nodejs.org/en/download/ or

brew install node

create a directory to work on your projectmkdir myimportercd myimporter

install the required libraries in the folder

npm install --save request sqlite3 moment npm install -g nodemon

open the folder or app.js with your favorite text editor

save the following code as app.js

var request = require('request');var sqlite3 = require("sqlite3").verbose();var moment = require("moment");var url =  'http://www.google.com';var s, e;var fs = require("fs");var file = "test.db";//var file = process.env.CLOUD_DIR + "/" + "test.db";var exists = fs.existsSync(file);var sqlite3 = require("sqlite3").verbose();var db = new sqlite3.Database(file);// use same exists from checking if db exists, with assumption that table would exists in a new db.if(!exists){    db.run("CREATE TABLE Stuff (thing TEXT)");}function saveResultTosqlite3(message){    var stmt = db.prepare("INSERT INTO Stuff VALUES (?)");    stmt.run(message);    stmt.finalize();}s = moment();request(url, function (error, response, body) {    e = moment();    var elapsed =e.diff(s,'milliseconds');    var responseCode = response.statusCode;         if (!error && response.statusCode == 200) {            console.log("successful request");    }    var message = 'request to ' + url + ' returned status code of ' + responseCode.toString() + ' in ' +elapsed.toString() + ' milliseconds'  ;    console.log(message);    saveResultTosqlite3(message);    });

run the follwing terminal to run the script each time it changes, for development / testing

nodemon app.js