services.factory('Products', ['$q', 'sqliteService', function ($q, sqliteService) {
return {
getProducts: function () {
var query = 'SELECT * FROM Products';
return $q.when(sqliteService.getItems(query));
},
addProduct: function (product) {
var query = "INSERT INTO Products (IdProduct, Name, Icon, Color) VALUES (?,?,?,?)";
return $q.when(sqliteService.executeSql(query, [product.IdProduct, product.Name, product.Icon, product.Color]));
},
dropTable: function () {
var query = 'DROP TABLE IF EXISTS Products';
return $q.when(sqliteService.executeSql(query));
},
createTable: function () {
var query = 'CREATE TABLE IF NOT EXISTS Products (IdProduct integer primary key, Name text, Icon text, Color text)';
return $q.when(sqliteService.executeSql(query));
}
};
});
SQLite plugin with ngCordova in Ionic Framework => Using service pattern (Works for litehelpers/Cordova-sqlite-storage and MSOpenTech/cordova-plugin-websql) Code => http://1drv.ms/1Ono0Ys
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.