Skip to content

Commit

Permalink
Version 0.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Diphoorn committed Feb 13, 2015
1 parent dfe8627 commit 0ed8f97
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
57 changes: 39 additions & 18 deletions build/ngDexie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Angularjs wrapper around Dexie.js an IndexedDB handler
* @version v0.0.11 - build 2015-02-02
* @version v0.0.12 - build 2015-02-13
* @link https://github.com/FlussoBV/NgDexie
* @license Apache License, http://www.apache.org/licenses/
*/
Expand Down Expand Up @@ -76,9 +76,9 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
}

configuration.call(this, db);
db.open().then(function(){
db.open().then(function () {
db.close();
db.open().then(function(){
db.open().then(function () {
$log.debug("NgDexie :: database is open");
});
});
Expand All @@ -94,6 +94,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
get: get,
getByIndex: getByIndex,
getDb: getDb,
getTransaction: getTransaction,
list: list,
listByIndex: listByIndex,
put: put,
Expand Down Expand Up @@ -162,6 +163,24 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
return db;
}

/**
* Get an dexie.transaction in RW mode
* @param {type} storeName
* @param {type} handle which receives the transaction
* @returns {$q@call;defer.promise}
*/
function getTransaction(storeName, handle) {
var deferred = $q.defer();
db.transaction("rw", storeName, function () {
handle.call(self, db);
}).then(function () {
deferred.resolve();
}).catch(function (err) {
deferred.reject(err);
});
return deferred.promise;
}

/**
* Get all entries from the storeName
* @param {type} storeName
Expand Down Expand Up @@ -290,8 +309,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
resync: resync,
unsyncedChanges: unsyncedChanges
};



/**
* Resync the database
* @param {type} url
Expand All @@ -307,26 +325,29 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex

// Disconnect the synchronisation database
db.syncable.disconnect(url).then(function () {
var dbTables = [];
var clearTables = 0;
angular.forEach(storeNames, function (storeName) {
dbTables.push(db.table(storeName));
});

db.transaction("rw", dbTables, function () {
// Clear storenames
angular.forEach(dbTables, function (dbTable) {
var dbTable = db.table(storeName);
// Use single table transactions for safari
db.transaction("rw", dbTable, function () {
dbTable.clear();
});
}).then(function () {
return db.syncable.delete(url).then(function () {
setTimeout(function () {
db.syncable.connect("iSyncRestProtocol", url);
}, 1500);
}).then(function () {
clearTables++;
if (clearTables === storeNames.length) {
db.syncable.delete(url).then(function () {
setTimeout(function () {
db.syncable.connect("iSyncRestProtocol", url);
}, 1500);
});
}
});
});

});
}

/**
* Resync the database
/**
* Check if there are synchronisation changes
* @param {type} url
Expand Down
4 changes: 2 additions & 2 deletions build/ngDexie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ed8f97

Please sign in to comment.