Skip to content

Instantly share code, notes, and snippets.

@amrishodiq
Last active May 9, 2016 04:04
Show Gist options
  • Save amrishodiq/1c6e296088ab23d822e843e928eec980 to your computer and use it in GitHub Desktop.
Save amrishodiq/1c6e296088ab23d822e843e928eec980 to your computer and use it in GitHub Desktop.
Write Data to Table with JavaScript
// places should be array of object as a result from internet
function writeDatas(places) {
getDatabase().transaction(function(trx) {
createTableIfNotExists(trx, function() {
var religion = "";
$.each(places, function(index, element) {
// parse the data and do insert to table
if (element.name.indexOf("MASJID")>=0 || element.name.indexOf("MUSALA")>=0) {
religion = "ISLAM";
} else if (element.name.indexOf("GEREJA")>=0 ||
element.name.indexOf("HKBP")>=0 ||
element.name.indexOf("GPIB")>=0 ||
element.name.indexOf("GPKB")>=0 ||
element.name.indexOf("GKI")>=0 ||
element.name.indexOf("GKRI")>=0 ||
element.name.indexOf("GBI")>=0) {
religion = "KRISTEN";
} else if (element.name.indexOf("PURA")>=0) {
religion = "HINDU";
} else if (element.name.indexOf("WIHARA")>=0) {
religion = "BUDDHA";
} else {
religion = "";
}
trx.executeSql('INSERT INTO worshipPlaces (placemark_id, religion, name, address, lat, lng) '
+'VALUES ("'+element.placemark_id+'", "'+religion+'", "'+element.name+'", "'+element.address+'", '+element.lat+', '+element.lng+')');
});
showWorshipPlaces();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment