Skip to content

Instantly share code, notes, and snippets.

@anteburazer
Last active April 27, 2016 09:07
Show Gist options
  • Save anteburazer/b5ff29cb321d6684bdbca4e0f50cf06f to your computer and use it in GitHub Desktop.
Save anteburazer/b5ff29cb321d6684bdbca4e0f50cf06f to your computer and use it in GitHub Desktop.
(function() {
'use strict';
var workersModule = angular.module('App.Workers');
workersModule.service('InsertDataWorker', [
'$rootScope',
'$cordovaSQLite',
'WorkerBridge',
'LocalDB',
'DataStoreService',
insertDataWorker
]);
function insertDataWorker($rootScope, $cordovaSQLite, WorkerBridge, LocalDB, DataStoreService) {
var scope = {
start: start
};
/* ********************************************************************************
* Public functions
* ********************************************************************************/
function start() {
worker.startWorkerJob();
}
/* ********************************************************************************
* Private functions
* ********************************************************************************/
var workerCode = function () {
//this will become the first line of the worker
"use strict;"
function startWorkerJob() {
main.insertData();
}
}
/*
* Insert data into local database
*
* @return {Promise}
*/
function insertData() {
var startQuery = "INSERT INTO 'MyTable' ",
data = DataStoreService.getData(),
query = '';
if (!data.length) return;
query = startQuery + '_MY TEST DATABASE QUERY_';
$cordovaSQLite.execute(LocalDB.database, query)
.then(function () {
$rootScope.$broadcast('data-inserted');
});
}
var worker = WorkerBridge.buildBridgedWorker(workerCode, ["startWorkerJob"], ["insertData"], [insertData]);
return scope;
}
module.exports = workersModule;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment