aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/api/idbobjectstore
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/web/api/idbobjectstore')
-rw-r--r--files/es/web/api/idbobjectstore/add/index.html193
-rw-r--r--files/es/web/api/idbobjectstore/index.html207
2 files changed, 400 insertions, 0 deletions
diff --git a/files/es/web/api/idbobjectstore/add/index.html b/files/es/web/api/idbobjectstore/add/index.html
new file mode 100644
index 0000000000..1a28ff194c
--- /dev/null
+++ b/files/es/web/api/idbobjectstore/add/index.html
@@ -0,0 +1,193 @@
+---
+title: IDBObjectStore.add
+slug: Web/API/IDBObjectStore/add
+tags:
+ - API
+ - Add
+ - Almacenamiento
+ - Base de datos
+ - IDBObjectStore
+ - IndexedDB
+ - Referencia
+translation_of: Web/API/IDBObjectStore/add
+---
+<p>{{ APIRef("IDBObjectStore") }}</p>
+<div>
+ <p>El metodo <code>add()</code> de la interfaz {{domxref("IDBObjectStore")}} retorna un objeto {{domxref("IDBRequest")}}, y, un hilo separado, crea un <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#structured-clone">clone estructurado</a> del valor, y almacena el valor clonado en el almacén de objetos. Esto es para agregar nevos registros a un almacén de objetos.</p>
+ <p>Para determinar si la operación de agregar fue completada satisfactoriamente, escucha el evento <code>complete</code> de la transaccion en adicion al evento <code>success</code> de la peticion <code>IDBojectStore.add</code>, porque la transaccion y todavía puede fallar después de lanzar el evento success. En otras palabras, el eventos success sólo es lanzado cuando la transacción ha sido puesta en cola satisfactoriamente.</p>
+ <p>El método agregar es un método de <em>sólo inserción</em>. Si un registro ya existe en el almacén de objetos con el argumento <code>key</code> como su clave, entonces un error <code>ConstrainError</code> es lanzado en el objeto petición devuelto. Para actualizar registros existentes, debes usar el método {{domxref("IDBObjectStore.put")}} en su lugar.</p>
+</div>
+<h2 id="Sintaxis">Sintaxis</h2>
+<pre class="brush: js">var request = objectStore.add(myItem, optionalKey);</pre>
+<h3 id="Retorno">Retorno</h3>
+<p>Un objeto <span style="line-height: 1.5;">{{domxref("IDBRequest")}} en el que los eventos subsecuentes relacionados a esta operación son lanzados.</span></p>
+<h3 id="Excepciones">Excepciones</h3>
+<p>Este método puede generar un <span style="line-height: 1.5;">{{domxref("DOMException")}}</span> con un <span style="line-height: 1.5;">{{domxref("DOMError")}}</span> de uno de los siguiente tipos:</p>
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Excepción</th>
+ <th scope="col">Descripción</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>ReadOnlyError</code></td>
+ <td>La transacción asociada con esta operación está en un <a href="/en-US/docs/IndexedDB/IDBTransaction#mode_constants" title="/en-US/docs/IndexedDB/IDBTransaction#mode_constants">modo</a> de sólo lectura.</td>
+ </tr>
+ <tr>
+ <td><code>TransactionInactiveError</code></td>
+ <td>Esta transacción de {{domxref("IDBObjectStore")}}'s está inactiva.</td>
+ </tr>
+ <tr>
+ <td><code><span style="line-height: normal;">DataError</span></code></td>
+ <td>
+ <p>Cualquiera de los siguientes condiciones aplica:</p>
+ <ul>
+ <li>El almacén de objetos usa llaves en línea o tiene un generador de llaves, y una argumento llave fue proporcionado.</li>
+ <li>El almacén de objetos usa llaves fuera de línea y no tiene un generador de llaves, y un argumento llave fue proporcionado.</li>
+ <li>El almacén de objetos usa llaves en línea pero no un generador de llaves, y la ruta de la llave del almacén de objetos no da una llave válida.</li>
+ <li>El argumento llave fue proporcionado pero no contiene una llave válida.</li>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <td><code>InvalidStateError</code></td>
+ <td>El {{domxref("IDBObjectStore")}} ha sido borrado o removido.</td>
+ </tr>
+ <tr>
+ <td><code>DataCloneError</code></td>
+ <td>Los datos siendo almacenados no pueden ser clonados por el algoritmo de clonado estructurado interno.</td>
+ </tr>
+ </tbody>
+</table>
+<h2 id="Ejemplo">Ejemplo</h2>
+<p>En el siguiente código, abrimos una transacción read/write en nuestra base de datos y agregado algunos datos al almacén de datos usando <code>add()</code>. También ten en cuenta que las funciones adjuntas a los manejadores de eventos de la transacción para informar en la salida de la apertura de transacciones en el evento de éxito o falla. Para un ejemplo completo funcionando, mira nuestra aplicación <a href="https://github.com/mdn/to-do-notifications/" style="line-height: 1.5;">To-do Notifications</a><span style="line-height: 1.5;"> (</span><a href="http://mdn.github.io/to-do-notifications/" style="line-height: 1.5;">ver ejemplo</a><span style="line-height: 1.5;">)</span>.</p>
+<pre class="brush: js" style="font-size: 14px;">// Abrimos nuestra base de datos
+<span style="line-height: 1.5;">var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+</span><span style="line-height: 1.5;">DBOpenRequest.onsuccess = function(event) {</span>
+ note.innerHTML += '&lt;li&gt;Database initialised.&lt;/li&gt;';
+
+ // Almacenar el resultado de la apertura de la base de datos en la variable db. Esta es usada mucho después
+ db = DBOpenRequest.result;
+
+ // Ejecuta la función addData() para agregar los datos
+ addData();
+};
+
+function addData() {
+ // Crea un nuevo objeto listo para ser insertado en la IDB
+ var newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];
+
+ // Inicia una transacción de lectura/escritura db transaction, lista para agregar los datos
+ var transaction = db.transaction(["toDoList"], "readwrite");
+
+ // Informa sobre el éxito de la inicio de la transacción
+ transaction.oncomplete = function(event) {
+ note.innerHTML += '&lt;li&gt;Transaction completed: database modification finished.&lt;/li&gt;';
+ };
+
+
+ transaction.onerror = function(event) {
+ note.innerHTML += '&lt;li&gt;Transaction not opened due to error. Duplicate items not allowed.&lt;/li&gt;';
+ };
+
+ // Crea una almacén de objetos en la transacción
+ var objectStore = transaction.objectStore("toDoList");
+
+ // Agrega nuestro objeto newItem al almacén de objetos
+ var objectStoreRequest = objectStore.add(newItem[0]);
+
+ objectStoreRequest.onsuccess = function(event) {
+ //Informa sobre el éxito de nuestro nuevo elemento en la base de datos
+ note.innerHTML += '&lt;li&gt;New item added to database.&lt;/li&gt;';
+ };
+};</pre>
+<h2 id="Parámetros">Parámetros</h2>
+<dl>
+ <dt>
+ value</dt>
+ <dd>
+ El valor para ser almacenado.</dd>
+ <dt>
+ key</dt>
+ <dd>
+ La llave a usar para identificar el registro. Si no es especificada, el resultado es nulo.</dd>
+</dl>
+<h2 id="Especificación"><span style="font-size: 2.14285714285714rem;">Especificación</span></h2>
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificación</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentario</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('IndexedDB', '#widl-IDBObjectStore-add-IDBRequest-any-value-any-key', 'add()')}}</td>
+ <td>{{Spec2('IndexedDB')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilidad de navegadores</h2>
+<div>
+ {{CompatibilityTable}}</div>
+<div id="compat-desktop">
+ <table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Característica</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Soporte básico</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>
+ </tbody>
+ </table>
+</div>
+<div id="compat-mobile">
+ <table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Característica</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>Soporte básico</td>
+ <td>4.4</td>
+ <td>{{CompatGeckoMobile("22.0")}}</td>
+ <td>1.0.1</td>
+ <td>10</td>
+ <td>22</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<h2 id="Ver_también">Ver también</h2>
+<ul>
+ <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Usando IndexedDB</a></li>
+ <li>Iniciando transacciones: {{domxref("IDBDatabase")}}</li>
+ <li>Usando transacciones: {{domxref("IDBTransaction")}}</li>
+ <li>Estableciendo un rango de llaves: {{domxref("IDBKeyRange")}}</li>
+ <li>Obteniendo y haciendo cambios a tus datos: {{domxref("IDBObjectStore")}}</li>
+ <li>Usando cursores: {{domxref("IDBCursor")}}</li>
+ <li>Ejemplo de referencia: <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/">ver ejemplo</a>.)</li>
+</ul>
diff --git a/files/es/web/api/idbobjectstore/index.html b/files/es/web/api/idbobjectstore/index.html
new file mode 100644
index 0000000000..32bb499284
--- /dev/null
+++ b/files/es/web/api/idbobjectstore/index.html
@@ -0,0 +1,207 @@
+---
+title: IDBObjectStore
+slug: Web/API/IDBObjectStore
+tags:
+ - API
+translation_of: Web/API/IDBObjectStore
+---
+<p>{{APIRef("IndexedDB")}}</p>
+
+<div>
+<p>The <code>IDBObjectStore</code> interface of the <a href="/en/IndexedDB" title="en/IndexedDB">IndexedDB API</a> represents an <a href="/en/IndexedDB#gloss_object_store" title="en/IndexedDB#gloss object store">object store</a> in a database. Records within an object store are sorted according to their keys. This sorting enables fast insertion, look-up, and ordered retrieval.</p>
+</div>
+
+<h2 id="Methods">Methods</h2>
+
+<dl>
+ <dt>{{domxref("IDBObjectStore.add")}}</dt>
+ <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, creates a <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#structured-clone">structured clone</a> of the <code>value</code>, and stores the cloned value in the object store. This is for adding new records to an object store.</dd>
+ <dt>{{domxref("IDBObjectStore.clear")}}</dt>
+ <dd>Creates and immediately returns an {{domxref("IDBRequest")}} object, and clears this object store in a separate thread. This is for deleting all current records out of an object store.</dd>
+ <dt>{{domxref("IDBObjectStore.delete")}}</dt>
+ <dd>returns an {{domxref("IDBRequest")}} object, and, in a separate thread, deletes the current object store. This is for deleting individual records out of an object store.</dd>
+ <dt>{{domxref("IDBObjectStore.get")}}</dt>
+ <dd>returns an {{domxref("IDBRequest")}} object, and, in a separate thread, returns the object store selected by the specified key. This is for retrieving specific records from an object store.</dd>
+ <dt>{{domxref("IDBObjectStore.createIndex")}}</dt>
+ <dd>Creates a new index during a version upgrade, returning a new {{domxref("IDBIndex")}} object in the connected database.</dd>
+ <dt>{{domxref("IDBObjectStore.deleteIndex")}}</dt>
+ <dd>Destroys the specified index in the connected database, used during a version upgrade.</dd>
+ <dt>{{domxref("IDBObjectStore.index")}}</dt>
+ <dd>Opens an index from this object store after which it can, for example, be used to return a sequence of records sorted by that index using a cursor.</dd>
+ <dt>{{domxref("IDBObjectStore.put")}}</dt>
+ <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, creates a <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#structured-clone">structured clone</a> of the <code>value</code>, and stores the cloned value in the object store. This is for updating existing records in an object store when the transaction's mode is <code>readwrite</code>.</dd>
+ <dt>{{domxref("IDBObjectStore.openCursor")}}<span style="line-height: 1.5;"> </span></dt>
+ <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, returns a new {{domxref("IDBCursorWithValue")}} object. Used for iterating through an object store by primary key with a cursor.</dd>
+</dl>
+
+<h2 id="Properties">Properties</h2>
+
+<dl>
+ <dt>{{domxref("IDBObjectStore.indexNames")}} {{readonlyInline}}</dt>
+ <dd>A list of the names of <a href="/en/IndexedDB#gloss_index" title="en/IndexedDB#gloss index">indexes</a> on objects in this object store.</dd>
+ <dt>{{domxref("IDBObjectStore.keyPath")}} {{readonlyInline}}</dt>
+ <dd>The <a href="/en/IndexedDB#gloss_key_path" title="en/IndexedDB#gloss key path">key path</a> of this object store. If this attribute is null, the application must provide a key for each modification operation.</dd>
+ <dt>{{domxref("IDBObjectStore.name")}} {{readonlyInline}}</dt>
+ <dd>The name of this object store.</dd>
+ <dt>{{domxref("IDBObjectStore.transaction")}} {{readonlyInline}}</dt>
+ <dd>The name of the transaction to which this object store belongs.</dd>
+ <dt>{{domxref("IDBObjectStore.autoIncrement")}} {{readonlyInline}}</dt>
+ <dd>The value of the auto increment flag for this object store.</dd>
+</dl>
+
+<h2 id="Obsolete_methods">Obsolete methods</h2>
+
+<dl>
+ <dt>{{domxref("IDBObjectStore.openKeyCursor")}}<span style="line-height: 1.5;"> </span></dt>
+ <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, returns a new {{domxref("IDBCursorWithValue")}}. Used for iterating through an object store with a key. However, this is now handled by {{domxref("IDBObjectStore.openCursor")}}, if a value is specified.</dd>
+</dl>
+
+<h2 id="Example">Example</h2>
+
+<p>This example shows a variety of different uses of ObjectStores, from updating the data structure with {{domxref("IDBObjectStore.createIndex")}} inside an <code>onupgradeneeded</code> function, to adding a new item to our object store with {{domxref("IDBObjectStore.add")}}. For a full working example, see our <a href="https://github.com/mdn/to-do-notifications/" style="line-height: 1.5;">To-do Notifications</a><span style="line-height: 1.5;"> app (</span><a href="http://mdn.github.io/to-do-notifications/" style="line-height: 1.5;">view example live</a><span style="line-height: 1.5;">.)</span></p>
+
+<pre class="brush: js">// Let us open our database
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+ note.innerHTML += '&lt;li&gt;Database initialised.&lt;/li&gt;';
+
+ // store the result of opening the database in the db variable.
+ db = DBOpenRequest.result;
+};
+
+// This event handles the event whereby a new version of the database needs to be created
+// Either one has not been created before, or a new version number has been submitted via the
+// window.indexedDB.open line above
+DBOpenRequest.onupgradeneeded = function(event) {
+ var db = event.target.result;
+
+ db.onerror = function(event) {
+ note.innerHTML += '&lt;li&gt;Error loading database.&lt;/li&gt;';
+ };
+
+ // Create an objectStore for this database
+
+ var objectStore = db.createObjectStore("toDoList", { keyPath: "taskTitle" });
+
+ // define what data items the objectStore will contain
+
+ objectStore.createIndex("hours", "hours", { unique: false });
+ objectStore.createIndex("minutes", "minutes", { unique: false });
+ objectStore.createIndex("day", "day", { unique: false });
+ objectStore.createIndex("month", "month", { unique: false });
+ objectStore.createIndex("year", "year", { unique: false });
+
+ objectStore.createIndex("notified", "notified", { unique: false });
+
+ note.innerHTML += '&lt;li&gt;Object store created.&lt;/li&gt;';
+};
+
+// Create a new item to add in to the object store
+var newItem = [
+  { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: 'December', year: 2013, notified: "no" }
+];
+
+// open a read/write db transaction, ready for adding the data
+var transaction = db.transaction(["toDoList"], "readwrite");
+
+// report on the success of opening the transaction
+transaction.oncomplete = function(event) {
+ note.innerHTML += '&lt;li&gt;Transaction opened for task addition.&lt;/li&gt;';
+};
+
+transaction.onerror = function(event) {
+ note.innerHTML += '&lt;li&gt;Transaction not opened due to error. Duplicate items not allowed.&lt;/li&gt;';
+};
+
+// create an object store on the transaction
+var objectStore = transaction.objectStore("toDoList");
+// add our newItem object to the object store
+var objectStoreRequest = objectStore.add(newItem[0]);
+
+objectStoreRequest.onsuccess = function(event) {
+ note.innerHTML += '&lt;li&gt;New item added to database.&lt;/li&gt;';
+}</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-IDBObjectStore', 'IDBObjectStore')}}</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>
+ </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>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</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>