Skip to content

Instantly share code, notes, and snippets.

@talhaakkaya
Created January 14, 2015 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talhaakkaya/3cda02c8dcae7aef0f86 to your computer and use it in GitHub Desktop.
Save talhaakkaya/3cda02c8dcae7aef0f86 to your computer and use it in GitHub Desktop.
cordova-sqlite
// Ionic Starter App
var db = null;
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
// db işlemleri
var db = $cordovaSQLite.openDB({name: "my.db"});
var query = "CREATE TABLE IF NOT EXISTS people (id integer primary key, fistname varchar, lastname varchar, email varchar)";
$cordovaSQLite.execute(db, query);
});
})
.controller('ExampleController', function($scope, $cordovaSQLite){
$scope.insert = function(firstname, lastname, email){
var insertQuery = "INSERT INTO people (firstname, lastname, email) VALUES (?, ?, ?)";
$cordovaSQLite.execute(db, insertQuery, [firstname, lastname, email]).then(function(result){
console.log("id " + result.insertId);
}, function(error){
console.log(error);
})
}
$scope.select = function(email){
var selectQuery = "SELECT * FROM people WHERE email = ?";
$cordovaSQLite.execute(db, selectQuery, [email]).then(function(result){
if(result.rows.length > 0) {
console.log("email" + result.rows.item(0).firstname);
} else {
console.log("not found");
}
}, function(error){
console.log(error);
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment