Can we write sqlite related code in different function


I want to reuse my sqlite related code. So that i put that block of code in different javascript function. I am able to pass $cordovaSQLite and my model bean. But the insertion is not happening. Is its the right way to do ?. Please find the below javascript.

Any solution helps us a lot.
Thanks in advance


.controller(‘StudyRetrieveListCtrl’, function($scope, Response, $cordovaSQLite) { {
$scope.studies = study;
angular.forEach($scope.studies, function(study, index) {
createStudy($cordovaSQLite, study);

function createStudy($cordovaSQLite, study) {
var createStudy = “INSERT INTO study (study_id, study_num, sponsor_name, prot_name) VALUES (?, ?, ?, ?)”;
$cordovaSQLite.execute(db, createStudy, [study.studyId, study.studyNum, study.sponsorName, study.protName]).then(function(res) {
console.log(‘HURREY ! INSERTED’);
function (err) {
// alert(“error”);

No body is there to answer.