Last active
April 27, 2016 09:07
-
-
Save anteburazer/b5ff29cb321d6684bdbca4e0f50cf06f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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