Skip to content

Commit

Permalink
Prefer vanilla indexeddb over the webkit flavor and other Safari-rela…
Browse files Browse the repository at this point in the history
…ted tweaks.
  • Loading branch information
Pamblam committed Dec 15, 2016
1 parent caf26fd commit 00745f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
19 changes: 8 additions & 11 deletions jSQL.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* jSQL.js v1.2
* jSQL.js v1.3
* A Javascript Query Language Database Engine
* @author Robert Parham
* @website https://github.com/Pamblam/jSQL#jsql
Expand Down Expand Up @@ -1589,8 +1589,8 @@

try {
indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
IDBTransaction = window.hasOwnProperty('webkitIndexedDB') ? window.webkitIDBTransaction : window.IDBTransaction;
IDBKeyRange = window.hasOwnProperty('webkitIndexedDB') ? window.webkitIDBKeyRange : window.IDBKeyRange;
IDBTransaction = window.hasOwnProperty('IDBTransaction') ? window.IDBTransaction : window.webkitIDBTransaction ;
IDBKeyRange = window.hasOwnProperty('IDBKeyRange') ? window.IDBKeyRange : window.webkitIndexedDB;
} catch (e) {
throw "indexedDB is not supported in this browser";
}
Expand Down Expand Up @@ -1665,8 +1665,7 @@
// Insert a group of rows
self.insert = function(model, data, successCallback) {
if(typeof successCallback !== "function") successCallback = function(){};
var transParam = undefined === IDBTransaction ? 'readwrite' : IDBTransaction.READ_WRITE;
var transaction = self.db.transaction([model], transParam);
var transaction = self.db.transaction([model], undefined === IDBTransaction.READ_WRITE ? 'readwrite' : IDBTransaction.READ_WRITE);
var store, i, request;
var total = data.length;

Expand All @@ -1688,9 +1687,8 @@

// Delete all items from the database
self.delete = function(model, successCallback) {
var transParam = undefined === IDBTransaction ? 'readwrite' : IDBTransaction.READ_WRITE;
if(typeof successCallback !== "function") successCallback = function(){};
var transaction = self.db.transaction([model], transParam), store, request;
if(typeof successCallback != "function") successCallback = function(){};
var transaction = self.db.transaction([model], undefined === IDBTransaction.READ_WRITE ? 'readwrite' : IDBTransaction.READ_WRITE), store, request;
transaction.onerror = function(){ throw "Could not initiate a transaction"; };;
store = transaction.objectStore(model);
request = store.clear();
Expand All @@ -1701,8 +1699,7 @@
// Get all data from the datastore
self.select = function(model, successCallback) {
if("function" !== typeof successCallback) successCallback = function(){};
var transParam = undefined === IDBTransaction ? 'readonly' : IDBTransaction.READ_ONLY ;
var transaction = self.db.transaction([model], transParam), store, request, results = [];
var transaction = self.db.transaction([model], undefined === IDBTransaction.READ_ONLY ? 'readonly' : IDBTransaction.READ_ONLY), store, request, results = [];
transaction.onerror = function(){ throw "Could not initiate a transaction"; };;
store = transaction.objectStore(model);
request = store.openCursor();
Expand Down Expand Up @@ -1899,7 +1896,7 @@
////////////////////////////////////////////////////////////////////////////

return {
version: 1.2,
version: 1.3,
tables: {},
query: jSQLParseQuery,
createTable: createTable,
Expand Down
Loading

0 comments on commit 00745f5

Please sign in to comment.