Skip to content

Commit 093afa4

Browse files
Editorial: Improve example's text around uniqueness. (#318)
Non-normative changes. Resolves #181
1 parent 44f0175 commit 093afa4

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

index.bs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,13 @@ in-order traversal of very large numbers of data records.
128128

129129

130130
<aside class=example id=example-open-connection>
131-
In the following example, the API is used to access a "library"
132-
database that holds books stored by their "isbn" attribute.
133-
Additionally, an index is maintained on the "title" attribute of the
134-
objects stored in the object store. This index can be used to look up
135-
books by title, and enforces a uniqueness constraint. Another index is
136-
maintained on the "author" attribute of the objects, and can be used
137-
to look up books by author.
138-
139-
A connection to the database is opened. If the "library" database did
140-
not already exist, it is created and an event handler creates the
141-
object store and indexes. Finally, the opened connection is saved for
142-
use in subsequent examples.
131+
The following example uses the API to access a `"library"` database. It has a `"books"` object store that holds books records stored by their `"isbn"` property as the primary key.
132+
133+
Book records have a `"title"` property. This example artificially requires that book titles are unique. The code enforces this by creating an index named `"by_title"` with the {{IDBIndexParameters/unique}} option set. This index is used to look up books by title, and will prevent adding books with non-unique titles.
134+
135+
Book records also have an `"author"` property, which is not <span class=allow-2119>required</span> to be unique. The code creates another index named `"by_author"` to allow look-ups by this property.
136+
137+
The code first opens a connection to the database. The <a event>`upgradeneeded`</a> event handler code creates the object store and indexes, if needed. The <a event>`success`</a> event handler code saves the opened connection for use in later examples.
143138

144139
```js
145140
const request = indexedDB.open("library");
@@ -221,8 +216,7 @@ request.onsuccess = function() {
221216
};
222217
```
223218

224-
The following example shows how errors could be handled when a request
225-
fails.
219+
The following example shows one way to handle errors when a request fails.
226220

227221
```js
228222
const tx = db.transaction("books", "readwrite");
@@ -245,9 +239,7 @@ The database connection can be closed when it is no longer needed.
245239
db.close();
246240
```
247241

248-
In the future, the database might have grown to contain other object
249-
stores and indexes. The following example shows one way to handle
250-
migrating from an older version of the database.
242+
In the future, the database might have grown to contain other object stores and indexes. The following example shows one way to handle migrating from an older version.
251243

252244
```js
253245
const request = indexedDB.open("library", 3); // Request version 3.

0 commit comments

Comments
 (0)