Skip to content

Commit

Permalink
Backing out 9c17e6d4739d due to test failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossop committed Aug 8, 2013
1 parent 74e8abb commit c43fdfc
Show file tree
Hide file tree
Showing 36 changed files with 396 additions and 1,771 deletions.
1 change: 0 additions & 1 deletion addon-sdk/source/doc/dev-guide-source/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ We'd like to thank our many Jetpack project contributors! They include:
* Tim Taubert
* Shane Tomlinson
* Dave Townsend
* [Fraser Tweedale](https://github.com/frasertweedale)
* [Matthias Tylkowski](https://github.com/tylkomat)

### V ###
Expand Down
161 changes: 59 additions & 102 deletions addon-sdk/source/doc/module-source/sdk/indexed-db.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,141 +32,98 @@ So you can use the `indexed-db` module to access the same API:
console.log("success");
};

Most of the objects that implement the IndexedDB API, such as
[IDBTransaction](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBTransaction),
[IDBOpenDBRequest](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBOpenDBRequest),
and [IDBObjectStore](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBObjectStore),
are accessible through the indexedDB object itself.
This module also exports all the other objects that implement
the IndexedDB API, listed below under
[API Reference](modules/sdk/indexed-db.html#API Reference).

The API exposed by `indexed-db` is almost identical to the DOM IndexedDB API,
so we haven't repeated its documentation here, but refer you to the
[IndexedDB API documentation](https://developer.mozilla.org/en-US/docs/IndexedDB)
for all the details.

The database created will be unique and private per add-on, and is not linked
to any website database. The module cannot be used to interact with a given
website database. See
[bug 778197](https://bugzilla.mozilla.org/show_bug.cgi?id=779197) and
[bug 786688](https://bugzilla.mozilla.org/show_bug.cgi?id=786688).
The database created will be unique and private per addon, and is not linked to any website database. The module cannot be used to interact with a given website database. See [bug 778197](https://bugzilla.mozilla.org/show_bug.cgi?id=779197) and [bug 786688](https://bugzilla.mozilla.org/show_bug.cgi?id=786688).

## Example
## Example of Usage

Here's a complete add-on that adds two widgets to the browser: the widget labeled
"Add" add the title of the current tab to a database, while the widget labeled
"List" lists all the titles in the database.
[Promise-based example using indexedDB for record storage](https://github.com/gregglind/micropilot/blob/ec65446d611a65b0646be1806359c463193d5a91/lib/micropilot.js#L80-L198).

The add-on implements helper functions `open()`, `addItem()` and `getItems()`
to open the database, add a new item to the database, and get all items in the
database.
<api name="indexedDB">
@property {object}

var { indexedDB, IDBKeyRange } = require('sdk/indexed-db');
var widgets = require("sdk/widget");
Enables you to create, open, and delete databases.
See the [IDBFactory documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBFactory).
</api>

var database = {};
<api name="IDBKeyRange">
@property {object}

database.onerror = function(e) {
console.error(e.value)
}
Defines a range of keys.
See the [IDBKeyRange documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBKeyRange).
</api>

function open(version) {
var request = indexedDB.open("stuff", version);
<api name="IDBCursor">
@property {object}

request.onupgradeneeded = function(e) {
var db = e.target.result;
e.target.transaction.onerror = database.onerror;
For traversing or iterating records in a database.
See the [IDBCursor documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBCursor).

if(db.objectStoreNames.contains("items")) {
db.deleteObjectStore("items");
}
</api>

var store = db.createObjectStore("items",
{keyPath: "time"});
};
<api name="IDBTransaction">
@property {object}

request.onsuccess = function(e) {
database.db = e.target.result;
};
Represents a database transaction.
See the [IDBTransaction documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBTransaction).
</api>

request.onerror = database.onerror;
};
<api name="IDBOpenDBRequest">
@property {object}

function addItem(name) {
var db = database.db;
var trans = db.transaction(["items"], "readwrite");
var store = trans.objectStore("items");
var time = new Date().getTime();
var request = store.put({
"name": name,
"time": time
});

request.onerror = database.onerror;
};
Represents an asynchronous request to open a database.
See the [IDBOpenDBRequest documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBOpenDBRequest).
</api>

function getItems(callback) {
var cb = callback;
var db = database.db;
var trans = db.transaction(["items"], "readwrite");
var store = trans.objectStore("items");
var items = new Array();
<api name="IDBVersionChangeEvent">
@property {object}

trans.oncomplete = function() {
cb(items);
}
Event indicating that the database version has changed.
See the [IDBVersionChangeEvent documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBVersionChangeEvent).
</api>

var keyRange = IDBKeyRange.lowerBound(0);
var cursorRequest = store.openCursor(keyRange);
<api name="IDBDatabase">
@property {object}

cursorRequest.onsuccess = function(e) {
var result = e.target.result;
if(!!result == false)
return;
Represents a connection to a database.
See the [IDBDatabase documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBDatabase).
</api>

items.push(result.value.name);
result.continue();
};
<api name="IDBFactory">
@property {object}

cursorRequest.onerror = database.onerror;
};
Enables you to create, open, and delete databases.
See the [IDBFactory documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBFactory).
</api>

function listItems(itemList) {
console.log(itemList);
}

open("1");

widgets.Widget({
id: "add-it",
width: 50,
label: "Add",
content: "Add",
onClick: function() {
addItem(require("sdk/tabs").activeTab.title);
}
});

widgets.Widget({
id: "list-them",
width: 50,
label: "List",
content: "List",
onClick: function() {
getItems(listItems);
}
});
<api name="IDBIndex">
@property {object}

<api name="indexedDB">
Provides access to a database index.
See the [IDBIndex documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBIndex).
</api>

<api name="IDBObjectStore">
@property {object}

Enables you to create, open, and delete databases.
See the [IDBFactory documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBFactory).
Represents an object store in a database.
See the [IDBObjectStore documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBObjectStore).
</api>

<api name="IDBKeyRange">
<api name="IDBRequest">
@property {object}

Defines a range of keys.
See the [IDBKeyRange documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBKeyRange).
Provides access to the results of asynchronous requests to databases
and database objects.
See the [IDBRequest documentation](https://developer.mozilla.org/en-US/docs/IndexedDB/IDBRequest).
</api>

<api name="DOMException">
Expand Down
Loading

0 comments on commit c43fdfc

Please sign in to comment.