Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 746065 of IDBCursorSync

  • Revision slug: Web/API/IDBCursorSync
  • Revision title: IDBCursorSync
  • Revision id: 746065
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment apiref

Revision Content

{{APIRef("IndexedDB")}} {{ draft() }}

The IDBCursorSync interface of the IndexedDB API represents a cursor for iterating over multiple records in a database. You can have only one instance of IDBCursorSync representing a cursor, but you can have an unlimited number of cursors at the same time. Operations are performed on the underlying index or object store. It enables an application to synchronously process all the records in the cursor's range.

Method overview

bool continue (in optional any key);
void remove () raises (IDBDatabaseException);

Attributes

Attribute Type Description
count readonly unsigned long long The total number of objects that share the current key.
direction readonly unsigned short The direction of traversal of the cursor. See Constants for possible values.
key readonly any The key for the record at the cursor's position.
value any

The value for the record at the cursor's position. Setting this attribute can raise an IDBDatabaseException with the following codes:

DATA_ERR
If the underlying object store uses in-line keys and the property at the key path does not match the key in this cursor's position.
NOT_ALLOWED_ERR
If the underlying index or object store does not support updating the record because it is open in the READ_ONLY or SNAPSHOT_READ mode, or if an index record cannot be changed because the underlying index is auto-populated.
SERIAL_ERR
If the data being stored could not be serialized by the internal structured cloning algorithm.

Constants

Constant Value Description
NEXT 0 This cursor includes duplicates, and its direction is monotonically increasing in the order of keys.
NEXT_NO_DUPLICATE 1 This cursor does not include duplicates, and its direction is monotonically increasing in the order of keys.
PREV 2 This cursor includes duplicates, and its direction is monotonically decreasing in the order of keys.
PREV_NO_DUPLICATE 3 This cursor does not include duplicates, and its direction is monotonically decreasing in the order of keys.

Methods

continue()

Advances the cursor to the next position along its direction, to the item whose key matches the optional key parameter. If no key is specified, advance to the immediate next position. Returns false if the cursor has reached the end of its range; otherwise returns true.

bool continue (
  in optional any key
);
Parameters
key
The key to which to move the cursor's position.

remove()

Deletes the record at the cursor's position, without changing the cursor's position

void delete (
) raises (DatabaseException);
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If the underlying index or object store does not support updating the record because it is open in the READ_ONLY or SNAPSHOT_READ mode.

Revision Source

<p>{{APIRef("IndexedDB")}} {{ draft() }}</p>

<p>The <code>IDBCursorSync</code> interface of the <a href="/en/IndexedDB" title="en/IndexedDB">IndexedDB API</a> represents a <a href="/en/IndexedDB#gloss_cursor" title="en/IndexedDB#gloss cursor">cursor</a> for iterating over multiple records in a database. You can have only one instance of <code>IDBCursorSync</code> representing a cursor, but you can have an unlimited number of cursors at the same time. Operations are performed on the underlying index or object store. It enables an application to synchronously process all the records in the cursor's range.</p>

<h2 id="Method_overview">Method overview</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <td><code>bool <a href="#continue" title="#continue">continue</a> (in optional any key);</code></td>
  </tr>
  <tr>
   <td><code>void <a href="#remove" title="#remove">remove</a> () raises (<a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a>);</code></td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Attribute</th>
   <th scope="col">Type</th>
   <th scope="col">Description</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><a name="attr_count"><code>count</code></a></td>
   <td><code>readonly unsigned long long</code></td>
   <td>The total number of objects that share the current key.</td>
  </tr>
  <tr>
   <td><a name="attr_direction"><code>direction</code></a></td>
   <td><code>readonly unsigned short</code></td>
   <td>The <a href="/en/IndexedDB#gloss_direction" title="en/IndexedDB#gloss direction">direction</a> of traversal of the cursor. See Constants for possible values.</td>
  </tr>
  <tr>
   <td><a name="attr_key"><code>key</code></a></td>
   <td><code>readonly any</code></td>
   <td>The key for the record at the cursor's <a href="/en/IndexedDB#gloss_position" title="en/IndexedDB#gloss position">position</a>.</td>
  </tr>
  <tr>
   <td><a name="attr_value"><code>value</code></a></td>
   <td><code>any</code></td>
   <td>
    <p>The value for the record at the cursor's position. Setting this attribute can raise an IDBDatabaseException with the following codes:</p>

    <dl>
     <dt><code><a href="/en/IndexedDB/IDBDatabaseException#DATA_ERR" title="en/IndexedDB/DatabaseException#DATA ERR">DATA_ERR</a></code></dt>
     <dd>If the underlying object store uses <a href="/en/IndexedDB#gloss_in-line_key" title="en/IndexedDB#gloss in-line key">in-line keys</a> and the property at the <a href="/en/IndexedDB#gloss_key_path" title="en/IndexedDB#gloss key path">key path</a> does not match the key in this cursor's position.</dd>
     <dt><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_ALLOWED_ERR" title="en/IndexedDB/DatabaseException#NOT ALLOWED ERR">NOT_ALLOWED_ERR</a></code></dt>
     <dd>If the underlying index or object store does not support updating the record because it is open in the <code><a href="/en/IndexedDB/IDBObjectStoreSync#const_read_only" title="en/IndexedDB/IDBObjectStoreSync#const read only">READ_ONLY</a></code> or <code><a href="/en/IndexedDB/IDBCursorSync#const_snapshot_read" title="en/IndexedDB/IDBCursorSync#const snapshot read">SNAPSHOT_READ</a></code> mode, or if an index record cannot be changed because the underlying index is <a href="/en/IndexedDB#gloss_auto-populated" title="en/IndexedDB#gloss auto-populated">auto-populated</a>.</dd>
     <dt><code><a href="/en/IndexedDB/IDBDatabaseException#SERIAL_ERR" title="en/IndexedDB/DatabaseException#SERIAL ERR">SERIAL_ERR</a></code></dt>
     <dd>If the data being stored could not be serialized by the internal structured cloning algorithm.</dd>
    </dl>
   </td>
  </tr>
 </tbody>
</table>

<h2 id="Constants">Constants</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Constant</th>
   <th scope="col">Value</th>
   <th scope="col">Description</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><a name="const_next"><code>NEXT</code></a></td>
   <td>0</td>
   <td>This cursor includes duplicates, and its direction is monotonically increasing in the order of keys.</td>
  </tr>
  <tr>
   <td><a name="const_next_no_duplicate"><code>NEXT_NO_DUPLICATE</code></a></td>
   <td>1</td>
   <td>This cursor does not include duplicates, and its direction is monotonically increasing in the order of keys.</td>
  </tr>
  <tr>
   <td><a name="const_prev"><code>PREV</code></a></td>
   <td>2</td>
   <td>This cursor includes duplicates, and its direction is monotonically decreasing in the order of keys.</td>
  </tr>
  <tr>
   <td><a name="const_prev_no_duplicate"><code>PREV_NO_DUPLICATE</code></a></td>
   <td>3</td>
   <td>This cursor does not include duplicates, and its direction is monotonically decreasing in the order of keys.</td>
  </tr>
 </tbody>
</table>

<h2 id="Methods">Methods</h2>

<h3 id="continue" name="continue">continue()</h3>

<p>Advances the cursor to the next position along its direction, to the item whose key matches the optional <code>key</code> parameter. If no key is specified, advance to the immediate next position. Returns false if the cursor has reached the end of its range; otherwise returns true.</p>

<pre>
bool continue (
  in optional any key
);
</pre>

<h5 id="Parameters">Parameters</h5>

<dl>
 <dt>key</dt>
 <dd>The key to which to move the cursor's position.</dd>
</dl>

<h3 id="remove" name="remove">remove()</h3>

<p>Deletes the record at the cursor's position, without changing the cursor's position</p>

<pre>
void delete (
) raises (DatabaseException);
</pre>

<h5 id="Exceptions">Exceptions</h5>

<p>This method can raise an IDBDatabaseException with the following code:</p>

<dl>
 <dt><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_ALLOWED_ERR" title="en/IndexedDB/DatabaseException#NOT ALLOWED ERR">NOT_ALLOWED_ERR</a></code></dt>
 <dd>If the underlying index or object store does not support updating the record because it is open in the <code><a href="/en/IndexedDB/IDBObjectStoreSync#const_read_only" title="en/IndexedDB/IDBObjectStoreSync#const read only">READ_ONLY</a></code> or <code><a href="/en/IndexedDB/IDBCursorSync#const_snapshot_read" title="en/IndexedDB/IDBCursorSync#const snapshot read">SNAPSHOT_READ</a></code> mode.</dd>
</dl>
Revert to this revision