Hi guys I am building an app which needs minimal, local json persistence on the device. So far I learned about following options:
$http.get() - worked well when reading json files but I am not really sure if it is possible to write using $http.post()
window.localstorage also works well in development so far. I am just not sure if it will also work well when the app is deployed on a real device.
ngStorage - I could not use this yet, I guess because of a angular version conflict or something.
There also seems to be a SQL-Lite solution but I have not tried this one yet. I also think that an entire database would be overkill for my requirements.
So is there any official How-To or recommendation from Ionicās side? What is suited best? What is most reliable and convenient to use.
That sounds great. Could you provide any tutorial or something? Can I access this database via javascript? Also will the database be deployed along with my app-file once I trigger a build?
hereās a basic script for adding and getting a user. iāve limited it because it comes from one of my apps:
.factory('CartService', ['$q', '$http', '$cordovaSQLite', '$ionicPlatform', '$timeout', function($q, $http, $cordovaSQLite, $ionicPlatform, $timeout) {
var db;
$ionicPlatform.ready(function() {
db = $cordovaSQLite.openDB({name: 'my.db', location:'default'});
});
var factory = {
addUser: function(user, shipping, datetime) {
var deferred = $q.defer();
user = JSON.stringify(user);
shipping = JSON.stringify(shipping);
datetime = JSON.stringify(datetime);
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS user (id integer primary key, user text, shipping text, datetime text)").then(function(res) {
});
var query = "INSERT INTO user (user, shipping, datetime) VALUES (?, ?, ?)";
$cordovaSQLite.execute(db, query, [user, shipping, datetime]).then(function(res) {
deferred.resolve('Gegevens opgeslagen.');
}, function (err) {
deferred.reject('Er ging iets mis met het toevoegen van je gegevens.');
});
return deferred.promise;
},
getUser: function() {
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS user (id integer primary key, user text, shipping text, datetime text)").then(function(res) {
});
var query = "SELECT * FROM user";
var items = [];
var deferred = $q.defer();
$cordovaSQLite.execute(db, query).then(function(res) {
var data = res.rows.item(0);
deferred.resolve(data);
}, function (err) {
deferred.reject('Er ging iets mis met het ophalen van je gegevens.');
});