Can we write sqlite related code in different function

Hi,

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

Ramprasad.

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

dao.js
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”);
console.error(err);
});
}

No body is there to answer.