From 6ebbdc5915237c5b6a8d2960aedfdb612f8b1a38 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Fri, 29 Nov 2013 10:29:04 -0500 Subject: [PATCH] Finish WebSQL implementation, all tests passing. Fixes #21. --- gruntfile.js | 3 +-- src/providers/indexeddb.js | 1 - src/providers/providers.js | 4 ++-- src/providers/websql.js | 22 ++++++++++------------ tests/spec/providers/providers.spec.js | 4 ++-- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index d2fa564..e08ab82 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -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' ] }, diff --git a/src/providers/indexeddb.js b/src/providers/indexeddb.js index 540ec9c..9de9e9a 100644 --- a/src/providers/indexeddb.js +++ b/src/providers/indexeddb.js @@ -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; diff --git a/src/providers/providers.js b/src/providers/providers.js index 960679f..edc6c53 100644 --- a/src/providers/providers.js +++ b/src/providers/providers.js @@ -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; } diff --git a/src/providers/websql.js b/src/providers/websql.js index d81d2b1..721b775 100644 --- a/src/providers/websql.js +++ b/src/providers/websql.js @@ -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) { diff --git a/tests/spec/providers/providers.spec.js b/tests/spec/providers/providers.spec.js index fc007a7..fbdde86 100644 --- a/tests/spec/providers/providers.spec.js +++ b/tests/spec/providers/providers.spec.js @@ -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'); }); }); });