Finish WebSQL implementation, all tests passing. Fixes #21.

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2013-11-29 10:29:04 -05:00
parent d5db4c51b9
commit 6ebbdc5915
5 changed files with 15 additions and 19 deletions

View File

@ -23,8 +23,7 @@ module.exports = function(grunt) {
'src/error.js',
'src/fs.js',
'src/shared.js',
'src/providers/**/*.js',
'src/filesystems-manager.js'
'src/providers/**/*.js'
]
},

View File

@ -7,7 +7,6 @@ define(function(require) {
window.webkitIndexedDB ||
window.msIndexedDB;
var IDB_RW = require('src/constants').IDB_RW;
var IDB_RO = require('src/constants').IDB_RO;

View File

@ -9,8 +9,8 @@ define(function(require) {
WebSQL: WebSQL,
Memory: Memory,
Default: IndexedDB,
// The Legacy provider does automatic fallback checks
Legacy: (function() {
// The Fallback provider does automatic fallback checks
Fallback: (function() {
if(IndexedDB.isSupported()) {
return IndexedDB;
}

View File

@ -20,12 +20,12 @@ define(function(require) {
};
}
WebSQLContext.prototype.clear = function(callback) {
function onSuccess(transaction, result) {
callback(null);
}
function onError(transaction, error) {
callback(error);
}
function onSuccess(transaction, result) {
callback(null);
}
this.getTransaction(function(transaction) {
transaction.executeSql("DELETE FROM " + FILE_STORE_NAME,
[], onSuccess, onError);
@ -33,18 +33,15 @@ define(function(require) {
};
WebSQLContext.prototype.get = function(key, callback) {
function onSuccess(transaction, result) {
if(result.rows.length === 0) {
// Key not found, return null
callback(null, null);
return;
}
callback(null, result.rows.item(0).data);
// If the key isn't found, return null
var value = result.rows.length === 0 ? null : result.rows.item(0).data;
callback(null, value);
}
function onError(transaction, error) {
callback(error);
}
this.getTransaction(function(transaction) {
transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ? LIMIT 1",
transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?",
[key], onSuccess, onError);
});
};
@ -96,14 +93,15 @@ define(function(require) {
callback("[WebSQL] Unable to open database.");
return;
}
that.db = db;
function onError(transaction, error) {
callback(error);
}
function onSuccess(transaction, result) {
that.db = db;
function gotCount(transaction, result) {
var firstAccess = result.rows.item(0).count > 0;
var firstAccess = result.rows.item(0).count === 0;
callback(null, firstAccess);
}
function onError(transaction, error) {

View File

@ -20,8 +20,8 @@ define(["IDBFS"], function(IDBFS) {
expect(typeof IDBFS.FileSystem.providers.Default).toEqual('function');
});
it("has Legacy constructor", function() {
expect(typeof IDBFS.FileSystem.providers.Legacy).toEqual('function');
it("has Fallback constructor", function() {
expect(typeof IDBFS.FileSystem.providers.Fallback).toEqual('function');
});
});
});