diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/api/idbcursor | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/pt-br/web/api/idbcursor')
-rw-r--r-- | files/pt-br/web/api/idbcursor/index.html | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/files/pt-br/web/api/idbcursor/index.html b/files/pt-br/web/api/idbcursor/index.html new file mode 100644 index 0000000000..ce9c02414b --- /dev/null +++ b/files/pt-br/web/api/idbcursor/index.html @@ -0,0 +1,181 @@ +--- +title: IDBCursor +slug: Web/API/IDBCursor +translation_of: Web/API/IDBCursor +--- +<p>{{APIRef("IndexedDB")}}</p> + +<p>O <code><strong>IDBCursor </strong></code>é uma interface da <a href="/en-US/docs/IndexedDB">API IndexedDB</a> que representa o <a href="/en-US/docs/IndexedDB/Basic_Concepts_Behind_IndexedDB#gloss_cursor">cursor</a> para atravessar ou interagir <span id="result_box" lang="pt"><span class="hps">sobre</span> <span class="hps">vários registros</span> <span class="hps">em</span> <span class="hps">um banco de dados</span><span>.</span></span></p> + +<p><span id="result_box" lang="pt"><span class="hps">O</span> <span class="hps">cursor</span> <span class="hps">tem uma fonte</span> <span class="hps">que indica qual</span> <span class="hps">índice ou</span> <span class="hps">armazenamento o objeto</span> <span class="hps">está sobre a</span></span><span lang="pt"><span class="hps"> iteração</span><span>.</span> <span class="hps">Ele tem uma posição</span> <span class="hps">dentro do intervalo</span><span>,</span> <span class="hps">e</span> <span class="hps">move-se</span> <span class="hps">numa direcção</span> <span class="hps">que</span> <span class="hps">é</span> <span class="hps">aumentar ou diminuir</span> <span class="hps">na ordem</span> <span class="hps">de</span> <span class="hps">chaves</span> <span class="hps">ficha</span><span>.</span> <span class="hps">O</span> <span class="hps">cursor</span> <span class="hps">permite que um aplicativo</span> <span class="hps">para processar</span> <span class="hps">de forma assíncrona</span> <span class="hps">todos os registros</span> <span class="hps">na faixa</span> <span class="hps">do</span> <span class="hps">cursor.</span></span></p> + +<p><span id="result_box" lang="pt"><span class="hps">Pode</span> <span class="hps">ter um número ilimitado</span> <span class="hps">de</span> <span class="hps">cursores</span> <span class="hps">ao mesmo</span> <span class="hps">tempo</span><span>.</span> <span class="hps">Você sempre consegue</span> <span class="hps">o mesmo objeto</span> <span class="hps">IDBCursor</span> <span class="hps">representando</span> <span class="hps">um determinado</span> <span class="hps">cursor.</span> <span class="hps">As operações são</span> <span class="hps">realizadas</span> <span class="hps">na</span> <span class="hps">loja de</span> <span class="hps">índice ou</span> <span class="hps">objeto subjacente</span><span>.</span></span></p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Methods">Methods</h2> + +<dl> + <dt>{{domxref("IDBCursor.advance()")}}</dt> + <dd><span id="result_box" lang="pt"><span class="hps">Define</span> <span class="hps">o número de vezes</span> <span class="hps">um</span> <span class="hps">cursor</span> <span class="hps">deve mover</span> <span class="hps">a sua posição</span> <span class="hps">para a frente.</span></span></dd> + <dt>{{domxref("IDBCursor.continue()")}}</dt> + <dd><span id="result_box" lang="pt"><span class="hps">Avança o</span> <span class="hps">cursor</span> <span class="hps">para a próxima posição</span> <span class="hps">ao longo de sua</span> <span class="hps">direção,</span> <span class="hps">para o item</span> <span class="hps">cuja chave</span> <span class="hps">corresponde ao</span> <span class="hps">parâmetro <code>chave</code></span><code> </code><span class="hps">opcional.</span></span></dd> + <dt>{{domxref("IDBCursor.delete()")}}</dt> + <dd>Retorna um {{domxref("IDBRequest")}} <span id="result_box" lang="pt"><span class="hps">objeto</span><span>,</span> <span class="hps">e</span><span>,</span> <span class="hps">em um segmento separado</span><span>,</span> <span class="hps">exclui o registro</span> <span class="hps">na posição do</span> <span class="hps">cursor</span><span>,</span> <span class="hps">sem alterar</span> <span class="hps">a posição do</span> <span class="hps">cursor.</span> <span class="hps">Isso pode ser usado</span> <span class="hps">para excluir registros</span> <span class="hps">específicos.</span></span></dd> + <dt>{{domxref("IDBCursor.update()")}}</dt> + <dd>Retorna um {{domxref("IDBRequest")}} objeto, <span id="result_box" lang="pt"><span class="hps">e</span><span>,</span> <span class="hps">em um segmento separado</span><span>,</span> <span class="hps">atualiza o valor</span> <span class="hps">na posição atual</span> <span class="hps">do</span> <span class="hps">cursor</span> <span class="hps">em armazenar o objeto</span><span>.</span> <span class="hps">Isso pode ser usado</span> <span class="hps">para atualizar registros</span> <span class="hps">específicos.</span></span></dd> +</dl> + +<h2 id="Propriedades">Propriedades</h2> + +<dl> + <dt>{{domxref("IDBCursor.source")}} {{readonlyInline}}</dt> + <dd>Retorna um {{domxref("IDBObjectStore")}} ou {{domxref("IDBIndex")}} <span id="result_box" lang="pt"><span class="hps">que</span> <span class="hps">o cursor é</span> <span class="hps">a iteração</span><span>.</span> <span class="hps">Esta função</span> <span class="hps">nunca retorna</span> <span class="hps">nulo ou</span> <span class="hps">gera uma exceção</span><span>, mesmo se o</span> <span class="hps">cursor</span> <span class="hps">está actualmente a ser</span> <span class="hps">iterativo,</span> <span class="hps">tem</span> <span class="hps">iterated</span> <span class="hps">além de seu fim</span><span>,</span> <span class="hps">ou a sua</span> <span class="hps">operação não</span> <span class="hps">está ativa.</span></span></dd> + <dt>{{domxref("IDBCursor.direction")}} {{readonlyInline}}</dt> + <dd><span id="result_box" lang="pt"><span class="hps">Retorna</span> <span class="hps">a direcção do</span> <span class="hps">percurso</span> <span class="hps">do cursor</span><span>.</span> <span class="hps">Veja</span> <span class="hps"><a href="#">constantes </a>para</span> <span class="hps">os possíveis valores.</span></span></dd> + <dt>{{domxref("IDBCursor.key")}} {{readonlyInline}}</dt> + <dd>Returns the key for the record at the cursor's position. If the cursor is outside its range, this is set to <code>undefined</code>. The cursor's key can be any data type.</dd> + <dt>{{domxref("IDBCursor.primaryKey")}} {{readonlyInline}}</dt> + <dd><span id="result_box" lang="pt"><span class="hps">Retorna a chave</span> <span class="hps">para o registro</span> <span class="hps">na posição do</span> <span class="hps">cursor.</span> <span class="hps">Se o cursor estiver</span> <span class="hps">fora do seu</span> <span class="hps">alcance,</span> <span class="hps">isso é definido como</span> <span class="hps">indefinido.</span> <span class="hps">A chave do</span> <span class="hps">cursor</span> <span class="hps">pode ser qualquer</span> <span class="hps">tipo de dados.</span></span></dd> +</dl> + +<h2 id="Constants" name="Constants">Constantes</h2> + +<div>{{ obsolete_header(25) }}</div> + +<div class="warning"> +<p>These constants are no longer available. You should use the string constants directly instead. ({{ bug(891944) }})</p> +</div> + +<ul> + <li><code>NEXT </code>: <code>"next"</code> : The cursor shows all records, including duplicates. It starts at the lower bound of the key range and moves upwards (monotonically increasing in the order of keys).</li> + <li><code>NEXTUNIQUE</code> : <code>"nextunique"</code> : The cursor shows all records, excluding duplicates. If multiple records exist with the same key, only the first one iterated is retrieved. It starts at the lower bound of the key range and moves upwards.</li> + <li><code>PREV </code>: <code>"prev"</code> : The cursor shows all records, including duplicates. It starts at the upper bound of the key range and moves downwards (monotonically decreasing in the order of keys).</li> + <li><code>PREVUNIQUE </code>: <code>"prevunique"</code> : The cursor shows all records, excluding duplicates. If multiple records exist with the same key, only the first one iterated is retrieved. It starts at the upper bound of the key range and moves downwards.</li> +</ul> + +<h2 id="Example">Example</h2> + +<p>In this simple fragment we create a transaction, retrieve an object store, then use a cursor to iterate through all the records in the object store. T<span style="line-height: 1.5;">he cursor does not require us to select the data based on a key; we can just grab all of it. Also note that in each iteration of the loop, you can grab data from the current record under the cursor object using </span><code style="font-style: normal; line-height: 1.5;">cursor.value.foo</code><span style="line-height: 1.5;">. For a complete working example, see our <a href="https://github.com/mdn/IDBcursor-example/">IDBCursor example</a></span><span style="line-height: 1.5;"> (</span><a href="http://mdn.github.io/IDBcursor-example/" style="line-height: 1.5;">view example live</a><span style="line-height: 1.5;">.)</span></p> + +<pre><span style="line-height: 1.5;">function displayData() {</span> + var transaction = db.transaction(['rushAlbumList'], "readonly"); + var objectStore = transaction.objectStore('rushAlbumList'); + + objectStore.openCursor().onsuccess = function(event) { + var cursor = event.target.result; + if(cursor) { + var listItem = document.createElement('li'); + listItem.innerHTML = cursor.value.albumTitle + ', ' + cursor.value.year; + list.appendChild(listItem); + + cursor.continue(); + } else { + console.log('Entries all displayed.'); + } + }; +};</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#idl-def-IDBCursor', 'cursor')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>23{{property_prefix("webkit")}}<br> + 24</td> + <td>10 {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16.0")}}</td> + <td>10, partial</td> + <td>15</td> + <td>7.1</td> + </tr> + <tr> + <td>Available in workers</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("37.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>4.4</td> + <td>{{CompatGeckoMobile("22.0")}}</td> + <td>1.0.1</td> + <td>10</td> + <td>22</td> + <td>8</td> + </tr> + <tr> + <td>Available in workers</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("37.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div class="warning"> +<p>Be careful in Chrome as it still implements the old specification along with the new one. Similarly it still has the prefixed <code>webkitIndexedDB</code> property even if the unprefixed <code>indexedDB</code> is present.</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li> + <li>Starting transactions: {{domxref("IDBDatabase")}}</li> + <li>Using transactions: {{domxref("IDBTransaction")}}</li> + <li>Setting a range of keys: {{domxref("IDBKeyRange")}}</li> + <li>Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}</li> + <li>Using cursors: {{domxref("IDBCursor")}}</li> + <li>Reference example: <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="http://mdn.github.io/to-do-notifications/">view example live</a>.)</li> +</ul> |