diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/fr/web/api/idbrequest | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/fr/web/api/idbrequest')
-rw-r--r-- | files/fr/web/api/idbrequest/blocked_event/index.html | 102 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/error/index.html | 213 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/index.html | 129 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/onerror/index.html | 151 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/onsuccess/index.html | 153 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/readystate/index.html | 175 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/result/index.html | 168 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/source/index.html | 178 | ||||
-rw-r--r-- | files/fr/web/api/idbrequest/transaction/index.html | 180 |
9 files changed, 1449 insertions, 0 deletions
diff --git a/files/fr/web/api/idbrequest/blocked_event/index.html b/files/fr/web/api/idbrequest/blocked_event/index.html new file mode 100644 index 0000000000..e3fdfdfb83 --- /dev/null +++ b/files/fr/web/api/idbrequest/blocked_event/index.html @@ -0,0 +1,102 @@ +--- +title: blocked +slug: Web/API/IDBRequest/blocked_event +translation_of: Web/API/IDBOpenDBRequest/blocked_event +--- +<p>Le handler <strong>blocked</strong> est exécuté lorsque l'ouverture d'une connexion à une base de données bloque une transaction <em>versionchange</em> sur celle-ci.</p> + +<h2 id="Informations_générales">Informations générales</h2> + +<dl> + <dt style="float: left; text-align: right; width: 120px;">Spécification</dt> + <dd style="margin: 0 0 0 120px;"><a class="external" href="http://www.w3.org/TR/IndexedDB/#request-api">IndexedDB</a></dd> + <dt style="float: left; text-align: right; width: 120px;">Interface</dt> + <dd style="margin: 0 0 0 120px;">IDBVersionChangeEvent</dd> + <dt style="float: left; text-align: right; width: 120px;">Propagation</dt> + <dd style="margin: 0 0 0 120px;">Non</dd> + <dt style="float: left; text-align: right; width: 120px;">Annulable</dt> + <dd style="margin: 0 0 0 120px;">Non</dd> + <dt style="float: left; text-align: right; width: 120px;">Cible</dt> + <dd style="margin: 0 0 0 120px;">IDBRequest</dd> + <dt style="float: left; text-align: right; width: 120px;">Action par défaut</dt> + <dd style="margin: 0 0 0 120px;">Aucune</dd> +</dl> + +<h2 id="Propriétés">Propriétés</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Property</th> + <th scope="col">Type</th> + <th scope="col">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>target</code> {{readonlyInline}}</td> + <td>{{domxref("EventTarget")}}</td> + <td>The request concerned by this event.</td> + </tr> + <tr> + <td><code>type</code> {{readonlyInline}}</td> + <td>{{domxref("DOMString")}}</td> + <td>The type of event.</td> + </tr> + <tr> + <td><code>bubbles</code> {{readonlyInline}}</td> + <td>{{jsxref("Boolean")}}</td> + <td>Whether the event normally bubbles or not.</td> + </tr> + <tr> + <td><code>cancelable</code> {{readonlyInline}}</td> + <td>{{jsxref("Boolean")}}</td> + <td>Whether the event is cancellable or not.</td> + </tr> + <tr> + <td><code>newVersion</code> {{readonlyInline}}</td> + <td>unsigned long (int)</td> + <td>The new version of the database.</td> + </tr> + <tr> + <td><code>oldVersion</code> {{readonlyInline}}</td> + <td>unsigned long (int)</td> + <td>The old version of the database.</td> + </tr> + </tbody> +</table> + +<h2 id="Exemple">Exemple</h2> + +<pre class="brush:js; line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> req1 <span class="operator token">=</span> indexedDB<span class="punctuation token">.</span><span class="function token">open</span><span class="punctuation token">(</span><span class="string token">"addressbook"</span><span class="punctuation token">,</span> <span class="number token">3</span><span class="punctuation token">)</span><span class="punctuation token">;</span> + +req1<span class="punctuation token">.</span>onsuccess <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span> event <span class="punctuation token">)</span> <span class="punctuation token">{</span> + <span class="keyword token">var</span> addressbookDB <span class="operator token">=</span> event<span class="punctuation token">.</span>target<span class="punctuation token">.</span>result<span class="punctuation token">;</span> + + <span class="comment token">// Essayons d'ouvrir la même base de données avec une version de révision plus élevée</span> + <span class="keyword token">var</span> req2 <span class="operator token">=</span> indexedDB<span class="punctuation token">.</span><span class="function token">open</span><span class="punctuation token">(</span><span class="string token">"addressbook"</span><span class="punctuation token">,</span> <span class="number token">4</span><span class="punctuation token">)</span><span class="punctuation token">;</span> + + <span class="comment token">// Dans ce cas, le handler onblocked</span> sera exécuté + req2<span class="punctuation token">.</span>onblocked <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span> e <span class="punctuation token">)</span> <span class="punctuation token">{</span> + console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>e<span class="punctuation token">)</span> + <span class="punctuation token">}</span><span class="punctuation token">;</span> + +<span class="punctuation token">}</span><span class="punctuation token">;</span></code></pre> + +<h2 id="Evénements_liés">Evénements liés</h2> + +<ul> + <li>{{event("success")}}</li> + <li>{{event("error")}}</li> + <li>{{event("abort")}}</li> + <li>{{event("complete")}}</li> + <li>{{event("upgradeneeded")}}</li> + <li>{{event("blocked")}}</li> + <li>{{event("versionchange")}}</li> +</ul> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/IndexedDB/Using_IndexedDB">Utilisation d'IndexedDB</a></li> +</ul> diff --git a/files/fr/web/api/idbrequest/error/index.html b/files/fr/web/api/idbrequest/error/index.html new file mode 100644 index 0000000000..45e27f7f49 --- /dev/null +++ b/files/fr/web/api/idbrequest/error/index.html @@ -0,0 +1,213 @@ +--- +title: IDBRequest.error +slug: Web/API/IDBRequest/error +tags: + - API + - Error + - IDBRequest + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBRequest/error +--- +<div>{{APIRef("IndexedDB")}}</div> + +<p>La propriété <strong><code>error</code></strong> de l'interface {{domxref("IDBRequest")}} renvoie l'erreur associée lorsque la requête est un échec.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox">var myError = request.error;</pre> + +<h3 id="Valeur">Valeur</h3> + +<p>Une erreur {{domxref("DOMError")}} qui contient l'erreur pertinente. Pour Chrome 48 et les versions ultérieures, cette propriété est une {{domxref("DOMException")}} car <code>DOMError</code> a été retiré du standard pour le DOM. Les codes d'erreurs suivants sont utilisés selon les conditions d'erreur :</p> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Erreur</th> + <th scope="col">Explication</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>AbortError</code></td> + <td>Si on annule la transaction en cours, toutes les requêtes en cours reçoivent cette erreur.</td> + </tr> + <tr> + <td><code>ConstraintError</code></td> + <td>Erreur obtenue lorsqu'on tente d'insérer des données qui ne respectent pas une contrainte. C'est un type d'exception utilisé lorsqu'on crée des magasins d'objet et des index. On aura cette erreur lorsqu'on essaiera par exemple d'ajouter une clé qui existe déjà dans l'enregistrement.</td> + </tr> + <tr> + <td><code>QuotaExceededError</code></td> + <td>Erreur obtenue lorsque atteint le quota d'espace disque et que l'utilisateur refuse de céder plus d'espace mémoire.</td> + </tr> + <tr> + <td><code>UnknownError</code></td> + <td>Erreur obtenue lorsque l'opération a échoué pour des raisons qui ne sont pas propres à la base de données (par exemple une erreur d'écriture sur le disque).</td> + </tr> + <tr> + <td><code>NoError</code></td> + <td>Valeur utilisée lorsque la requête est réussie.</td> + </tr> + <tr> + <td><code>VersionError</code></td> + <td>Erreur obtenue lorsqu'on essaye d'ouvrir une base de données avec une version inférieure à celle dont elle dispose déjà.</td> + </tr> + </tbody> +</table> + +<p>En plus des codes d'erreur envoyés à l'objet {{domxref("IDBRequest")}}, les opérations asynchrones peuvent également déclencher des exceptions. La liste décrit les problèmes qui peuvent se produire lorsque la requête est en cours d'exécution mais d'autres problèmes peuvent apparaître lors de la construction de la requête. Ainsi, si la requête a échoué et que le résultat n'est pas disponible, l'exception <code>InvalidStateError </code>sera levée.</p> + +<h2 id="Exemples">Exemples</h2> + +<p>Dans l'exemple qui suit, on effectue une requête sur le titre de l'enregistrement. Le gestionnaire d'évèvenement <code>onsuccess</code> traite l'enregistrement obtenu depuis le magasin d'objet ({{domxref("IDBObjectStore")}}) et qui est disponible via <code>objectStoreTitleRequest.result</code>. Le gestionnaire met ensuite à jour une propriété de l'enregistrement puis replace l'enregistrement mis à jour dans le magasin d'objet.</p> + +<p>On dispose également d'une fonction <code>onerror</code> qui permet d'indiquer l'erreur qui s'est produite si la requêté échoue. Pour consulter un exemple complet, voir <a href="https://github.com/mdn/to-do-notifications/">l'application de notifications To-do</a> (cf. <a href="https://mdn.github.io/to-do-notifications/">la démonstration <em>live</em></a>).</p> + +<pre class="brush: js">var title = "Walk dog"; + +// On ouvre une transaction +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// On récupère la liste de tâches avec ce titre +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // On récupère l'objet du résultat + var data = objectStoreTitleRequest.result; + + // On met à jour la valeur de la propriété notified avec "yes" + data.notified = "yes"; + + // On crée une autre requête pour replacer l'élément + // into the database + var updateTitleRequest = objectStore.put(data); + + // Lorsque la requête est réussie, on utilise à nouveau + // la fonction the displayData() pour mettre à jour + // l'affichage + updateTitleRequest.onsuccess = function() { + displayData(); + }; +}; + +objectStoreTitleRequest.onerror = function() { + // S'il se produit une erreur pendant la requête + // on l'enregistre + console.log("Il y a eu une erreur pour la récupération des données : " + objectStoreTitleRequest.error); +};</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">État</th> + <th scope="col">Commentaires</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-error', 'error')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support simple</td> + <td>23{{property_prefix("webkit")}}<br> + 24</td> + <td>{{CompatVersionUnknown}}</td> + <td>10 {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16.0")}}</td> + <td>10</td> + <td>15</td> + <td>7.1</td> + </tr> + <tr> + <td>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</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>Fonctionnalité</th> + <th>Android</th> + <th>Webview Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome pour Android</th> + </tr> + <tr> + <td>Support simple</td> + <td>4.4</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("22.0")}}</td> + <td>1.0.1</td> + <td>10</td> + <td>22</td> + <td>8</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("37.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/Web/API/API_IndexedDB/Using_IndexedDB">Utiliser IndexedDB</a></li> + <li>Initier une connexion : {{domxref("IDBDatabase")}}</li> + <li>Utiliser les transactions : {{domxref("IDBTransaction")}}</li> + <li>Définir un intervalle de clés : {{domxref("IDBKeyRange")}}</li> + <li>Récupérer et modifier les données : {{domxref("IDBObjectStore")}}</li> + <li>Utiliser les curseurs {{domxref("IDBCursor")}}</li> + <li>Exemple de référence : <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="https://mdn.github.io/to-do-notifications/">exemple <em>live</em></a>).</li> +</ul> diff --git a/files/fr/web/api/idbrequest/index.html b/files/fr/web/api/idbrequest/index.html new file mode 100644 index 0000000000..87759d881f --- /dev/null +++ b/files/fr/web/api/idbrequest/index.html @@ -0,0 +1,129 @@ +--- +title: IDBRequest +slug: Web/API/IDBRequest +tags: + - API + - Database + - IDBRequest + - IndexedDB + - Interface + - Reference + - Storage + - TopicStub +translation_of: Web/API/IDBRequest +--- +<p>{{APIRef("IndexedDB")}}</p> + +<p>L'interface <strong><code>IDBRequest</code></strong> de l'API IndexedDB donne accès par ses gestionnaires d'événements aux résultats des requêtes asynchrones sur la base de données, les magasins d'objets ou les index. Chaque opération d'écriture ou lecture sur la base de données utilise une requête.</p> + +<p>Cet objet <strong><code>IDBRequest</code></strong> ne contient aucune information sur le résultat de l'opération, mais dès qu'une information est disponible un événement est déclenché. L'objet <strong><code>IDBRequest</code></strong> utilise ses gestionnaires d'événements pour le capter et mettre l'information à disposition.</p> + +<p>Toute les opération asynchrone retourne immédiatement une instance <strong><code>IDBRequest</code></strong> avec une propriété <code>readyState</code> défini à <code>'pending'</code> qui passe à <code>'done'</code> lorsque la requête réussie ou échoue. Quand l'état passe à <code>done</code>, chaque requête retourne <code>result</code> et <code>error</code>, et un évènement est envoyé sur la requête. Quand l'état est sur <code>pending</code>, chaque accès à <code>result</code> ou <code>error</code> lève une exception <code>InvalidStateError</code>.</p> + +<p>Pour faire simple, chaque méthode asynchrome retourne un objet de requête. Si l'opération réussi, le résultat est disponible dans la propriété <code>result</code> et un évènement <code>success</code> est lancé ({{domxref("IDBRequest.onsuccess")}}). Si une erreur est rencontrée, une exeption est disponible dans la propriété <code>error</code> et un évènement <code>error</code> est lancé ({{domxref("IDBRequest.onerror")}}).</p> + +<p>L'interface {{domxref("IDBOpenDBRequest")}} est dérivé de <code>IDBRequest</code>.</p> + +<p>{{AvailableInWorkers}}</p> + +<p>{{InheritanceDiagram}}</p> + +<h2 id="Propriétés">Propriétés</h2> + +<p><em>Hérite des propriétés de {{domxref("EventTarget")}}.</em></p> + +<dl> + <dt>{{domxref("IDBRequest.result","result")}} {{readonlyInline}}</dt> + <dd>La propriété <strong><code>result</code></strong> de l'interface <strong><code>IDBRequest</code></strong> renvoie le résultat de la requête. Si la requête est en cours, échoue ou que le résultat n'est pas disponible, l'exception <code>InvalidStateError</code> est levée.</dd> + <dt>{{domxref("IDBRequest.error","error")}} {{readonlyInline}}</dt> + <dd>La propriété <strong><code>error</code></strong> de l'interface <strong><code>IDBRequest</code></strong> indique le code de l'erreur survenue durant le traitement de la requête. Si la requête est en cours l'exception <code>InvalidStateError</code> est levée.</dd> + <dt>{{domxref("IDBRequest.source","source")}} {{readonlyInline}}</dt> + <dd>La propriété <strong><code>source</code></strong> de l'interface <strong><code>IDBRequest</code></strong> renvoie la source de la requête, tel qu'un {{domxref("IDBIndex","index")}}, un {{domxref("IDBObjectStore","magasin d'ojets")}} ou <code>null</code> s'il n'y a pas de source (lors de l'appel {{domxref("indexedDB.open")}} par exemple).</dd> + <dt>{{domxref("IDBRequest.transaction","transaction")}} {{readonlyInline}}</dt> + <dd>La propriété <strong><code>transaction</code></strong> de l'interface <strong><code>IDBRequest</code></strong> renvoie la {{domxref("IDBTransaction","transaction")}} dans laquelle on fait la requête. La propriété peut renvoyer <code>null</code> si requête se fait sans transaction, comme un objet IDBRequest renvoyé par {{domxref("IDBFactory.open")}} dans ce cas on est juste connecté à la base de données.</dd> + <dt>{{domxref("IDBRequest.readyState","readyState")}} {{readonlyInline}}</dt> + <dd>La propriété <strong><code>readyState</code></strong> de l'interface <strong><code>IDBRequest</code></strong> renvoie l'état de la requête. Chaque requête débute avec un statut <code>pending</code> et passe au statut <code>done</code> quand la requête réussie ou échoue.</dd> +</dl> + +<h2 id="Méthodes">Méthodes</h2> + +<p><em>Pas de méthodes spécifiques, mais hérite des méthodes de {{domxref("EventTarget")}}.</em></p> + +<h2 id="Gestionnaire_dévénement">Gestionnaire d'événement</h2> + +<p>On peut écouter les évènement avec <code>addEventListener()</code> ou bien en assignant un gestionnaire d'évènement à la propriété <code>on<em>eventname</em></code> de cette interface.</p> + +<dl> + <dt>{{domxref("IDBRequest.onerror","onerror")}}</dt> + <dd>Le gestionnaire d'événement <strong><code>onerror</code></strong> de l'interface <strong><code>IDBRequest</code></strong> capte l'événement <code><a href="/en-US/docs/Web/Events/error">error</a></code>, déclenché quand une requête renvoie une erreur.</dd> + <dt>{{domxref("IDBRequest.onsuccess","onsuccess")}}</dt> + <dd>Le gestionnaire d'événement <strong><code>onsuccess</code></strong> de l'interface <strong><code>IDBRequest</code></strong> capte l'événement <code><a href="/en-US/docs/Web/Events/success">success</a></code>, déclenché quand la requête réussie.</dd> +</dl> + +<h2 id="Exemple">Exemple</h2> + +<p>Dans l'exemple suivant, on ouvre une base de données et on fait une requête. Les gestionnaires d'événement <code>{{domxref("IDBRequest.onsuccess","onsuccess")}}</code> et <code>{{domxref("IDBRequest","onerror")}}</code> sont inclus. Pour un exemple de travail complet, voir notre application <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> (<a href="http://mdn.github.io/to-do-notifications/">voir l'exemple en direct</a>).</p> + +<pre class="brush: js notranslate">var db; + +// Ouvre une base de données. +var DBOpenRequest = window.indexedDB.open("toDoList", 4); + +// Ces deux gestionnaires d'événement interviennent quand la dase de +// de données s'ouvre ou non. +DBOpenRequest.onerror = function(event) { + note.innerHTML += '<li>Error loading database.</li>'; +}; + +DBOpenRequest.onsuccess = function(event) { + note.innerHTML += '<li>Database initialised.</li>'; + + // Affecte le resutat de l'ouverture à la variable. + db = DBOpenRequest.result; +};</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">Statut</th> + <th scope="col">Commentaire</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#idbrequest', 'IDBRequest')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td>Définition initiale.</td> + </tr> + <tr> + <td>{{SpecName("IndexedDB 2", "#request-api", "IDBRequest")}}</td> + <td>{{Spec2("IndexedDB 2")}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilité avec les navigateurs</h2> + +<div> +<div> +<div> + + +<p>{{Compat("api.IDBRequest")}}</p> +</div> +</div> +</div> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/Web/API/IndexedDB_API/Using_IndexedDB">Utiliser IndexedDB</a></li> + <li>Démarrer une transaction: {{domxref("IDBDatabase")}}</li> + <li>Utiliser les transactions: {{domxref("IDBTransaction")}}</li> + <li>Définir un intervalle de clés: {{domxref("IDBKeyRange")}}</li> + <li>Récupérer et modifier vos données: {{domxref("IDBObjectStore")}}</li> + <li>utiliser les curseurs: {{domxref("IDBCursor")}}</li> + <li>Exemple de référence: <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> diff --git a/files/fr/web/api/idbrequest/onerror/index.html b/files/fr/web/api/idbrequest/onerror/index.html new file mode 100644 index 0000000000..a63b087f8c --- /dev/null +++ b/files/fr/web/api/idbrequest/onerror/index.html @@ -0,0 +1,151 @@ +--- +title: IDBRequest.onerror +slug: Web/API/IDBRequest/onerror +translation_of: Web/API/IDBRequest/onerror +--- +<p>{{ APIRef("IndexedDB") }}</p> + +<p>le gestionnaire d'événement <strong><code>onerror</code></strong> de l'interface {{domxref("IDBRequest")}} capte l'événement <code><a href="/en-US/docs/Web/Events/error">error</a></code>, déclenché quand une requête renvoie une erreur.</p> + +<p>Le gestionnaire d'événement reçoit l'événement <a href="/en-US/docs/Web/Events/error">error</a> avec le type="error" en paramètre.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="brush: js">request.onerror = function( event ) { ... };</pre> + +<h2 id="Exemple">Exemple</h2> + +<p>L'exemple suivant demande un titre d'enregistrement donné, <code>onsuccess</code> obtient l'enregistrement associé au {{domxref("IDBObjectStore","magasin d'objets")}} (mis à disposition en tant que <code style="font-style: normal;">objectStoreTitleRequest.result</code>), on met à jour une propriété de l'enregistrement, puis le sauve dans le magasin d'objets. En bas le gestionnaire d'événement <code>onerror</code> affiche le code d'erreur si la {{domxref("IDBRequest","requête")}} échoue. Pour un exemple de travail complet, voir notre <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> app (<a href="http://mdn.github.io/to-do-notifications/">view example live</a>).</p> + +<pre>var title = "Walk dog"; + +// Ouvrez une transaction comme d'habitude +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// Obtenez l'objet toDoList qui a ce titre +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // Prenez l'objet de données renvoyé comme résultat + var data = objectStoreTitleRequest.result; + + // Mettre à jour la valeur notified de l'objet à "yes" + data.notified = "yes"; + + // Créer une autre requête qui insère le nouvelle élément dans la base de données + var updateTitleRequest = objectStore.put(data); + + // Lorsque cette requête réussit, appelle de la fonction displayData() pour mettre à jour l'affichage + updateTitleRequest.onsuccess = function() { + displayData(); + }; +}; + +objectStoreTitleRequest.onerror = function() { + // Si une erreur se produit à la demande, on l'affiche + console.log("Il y a eu une erreur dans la récupération des données: " + objectStoreTitleRequest.error); +}; +</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">Statut</th> + <th scope="col">Commentaire</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-onerror', 'onerror')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilité avec les navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support basique</td> + <td>23{{property_prefix("webkit")}}<br> + 24</td> + <td>10 {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16.0")}}</td> + <td>10, en partie</td> + <td>15</td> + <td>7.1</td> + </tr> + <tr> + <td>Disponible dans 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>Fonctionnalité</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>Support basique</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>Disponible dans 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> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li> + <li><a href="/en-US/docs/Web/Events/error">Error Event</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> diff --git a/files/fr/web/api/idbrequest/onsuccess/index.html b/files/fr/web/api/idbrequest/onsuccess/index.html new file mode 100644 index 0000000000..e1f2f6fa90 --- /dev/null +++ b/files/fr/web/api/idbrequest/onsuccess/index.html @@ -0,0 +1,153 @@ +--- +title: IDBRequest.onsuccess +slug: Web/API/IDBRequest/onsuccess +translation_of: Web/API/IDBRequest/onsuccess +--- +<p>{{ APIRef("IndexedDB") }}</p> + + +<p>Le gestionnaire d'événement <strong><code>onsuccess</code></strong> de l'interface {{domxref("IDBRequest")}} capte l'événement <code><a href="/en-US/docs/Web/Events/success">success</a></code>, déclenché quand la requête réussie.</p> + +<p>Le gestionnaire d'événement un événement <a href="/en-US/docs/Web/Events/success">success</a> avec le type="success" en paramètre.</p> + +<p>{{AvailableInWorkers}}</p> + + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="brush: js">request.onsuccess = function( event ) { ... };</pre> + +<h2 id="Exemple">Exemple</h2> + +<p>L'exemple suivant demande un titre d'enregistrement donné, <code>onsuccess</code> obtient l'enregistrement associé de {{domxref("IDBObjectStore")}} (mis à disposition en tant que <code>objectStoreTitleRequest.result</code>), on met à jour une propriété de l'enregistrement, puis le sauve dans le magasin d'objets. En bas le gestionnaire d'événement <code>onerror</code> affiche le code d'erreur si la requête échoue. Pour un exemple de travail complet, voir notre <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> app (<a href="http://mdn.github.io/to-do-notifications/">view example live</a>).</p> + +<pre>var title = "Walk dog"; + +// Ouvrez une transaction comme d'habitude +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// Obtenez l'objet toDoList qui a ce titre +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // Prenez l'objet de données renvoyé comme résultat + var data = objectStoreTitleRequest.result; + + // Mettre à jour la valeur notified de l'objet à "yes" + data.notified = "yes"; + + // Créer une autre requête qui insère le nouvelle élément dans la base de données + var updateTitleRequest = objectStore.put(data); + + // Lorsque cette requête réussit, appelle de la fonction displayData() pour mettre à jour l'affichage + updateTitleRequest.onsuccess = function() { + displayData(); + }; +}; + +objectStoreTitleRequest.onerror = function() { + // Si une erreur se produit à la demande, on l'affiche + console.log("Il y a eu une erreur dans la récupération des données: " + objectStoreTitleRequest.error); +}; +</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">Statut</th> + <th scope="col">Commentaire</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-onsuccess', 'onsuccess')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilité avec les navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support basique</td> + <td>23{{property_prefix("webkit")}}<br> + 24</td> + <td>10 {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16.0")}}</td> + <td>10, en partie</td> + <td>15</td> + <td>7.1</td> + </tr> + <tr> + <td>Disponible dans 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>Fonctionnalité</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>Support basique</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>Disponible dans 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> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li> + <li><a href="/en-US/docs/Web/Events/success">Success Event</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> diff --git a/files/fr/web/api/idbrequest/readystate/index.html b/files/fr/web/api/idbrequest/readystate/index.html new file mode 100644 index 0000000000..2093d5e30a --- /dev/null +++ b/files/fr/web/api/idbrequest/readystate/index.html @@ -0,0 +1,175 @@ +--- +title: IDBRequest.readyState +slug: Web/API/IDBRequest/readyState +tags: + - API + - IDBRequest + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBRequest/readyState +--- +<div>{{APIRef("IndexedDB")}}</div> + +<p>La propriété <strong><code>readyState</code></strong>, rattachée à l'interface {{domxref("IDBRequest")}}, est une propriété en lecture seule qui indique l'état de la requête.</p> + +<p>Chaque requête démarre avec l'état <code>pending</code> (c'est-à-dire en attente). Cet état vaut ensuite <code>done</code> (fini) lorsque la requête est terminée (en cas de réussite de l'opération comme en cas d'échec).</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox">var <em>currentReadyState</em> = <em>request</em>.readyState;</pre> + +<h3 id="Valeur">Valeur</h3> + +<p>La valeur {{domxref("IDBRequestReadyState")}} de la requête, qui peut être l'un de deux valeurs. <code>pending</code> lorsque la requête est en attente, <code>done</code> lorsque celle-ci est finie.</p> + +<h2 id="Exemples">Exemples</h2> + +<p>Dans l'exemple qui suit, on effectue une requête sur un enregistrement avec un titre donné et on recupère l'enregistrement associé grâce au gestionnaire d'évènement <code>onsuccess</code> à partir du magasin d'objets {{domxref("IDBObjectStore")}}. Ensuite, on met à jour une des propriétés de cet enregistrement et on replace cet objet mis à jour dans le magasin d'objets via une autre requête. La valeur de la propriété <code>readyState</code> pour la deuxième requête est affichée dans la console. Pour consulter un exemple fonctionnel complet, vous pouvez vous référer à notre appliction <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> (<a href="https://mdn.github.io/to-do-notifications/">cf. également l'exemple <em>live</em></a>).</p> + +<pre class="brush: js">var title = "Walk dog"; + +// On ouvre une transaction +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// On récupère l'enregistrement avec le titre souhaité +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // On récupère les données du résultat de la requête + var data = objectStoreTitleRequest.result; + + // On met à jour la propriété notified de l'objet + // avec la valeur "yes" + data.notified = "yes"; + + // Ensuite, on crée une autre requête pour insérer + // l'enregistrement dans la base de données + var updateTitleRequest = objectStore.put(data); + + // On affiche l'état de la requête dans la console + console.log("La valeur de readyState est " + updateTitlerequest.readyState); + + // Lorsque cette deuxième requête est appliquée, + // on exécute la fonction displayData() afin d'afficher + // les données à jour + updateTitleRequest.onsuccess = function() { + displayData(); + }; +};</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">État</th> + <th scope="col">Commentaires</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-readyState', 'readyState')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName("IndexedDB 2", "#dom-idbrequest-readystate", "readyState")}}</td> + <td>{{Spec2("IndexedDB 2")}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support simple</td> + <td>23{{property_prefix("webkit")}}<br> + 24 (sans préfixe)</td> + <td>{{CompatVersionUnknown}}</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>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</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>Fonctionnalité</th> + <th>Android</th> + <th>Webview Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome pour Android</th> + </tr> + <tr> + <td>Support simple</td> + <td>4.4</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("22.0")}}</td> + <td>10</td> + <td>22</td> + <td>8</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("37.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/Web/API/API_IndexedDB/Using_IndexedDB">Manipuler IndexedDB</a></li> + <li>Démarrer des transactions : {{domxref("IDBDatabase")}}</li> + <li>Manipuler des transactions : {{domxref("IDBTransaction")}}</li> + <li>Définir un intervalle de clés : {{domxref("IDBKeyRange")}}</li> + <li>Récupérer des données et les modifier : {{domxref("IDBObjectStore")}}</li> + <li>Manipuler des curseurs : {{domxref("IDBCursor")}}</li> + <li>Exemple de référence pour IndexedDB : <a href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a></li> +</ul> diff --git a/files/fr/web/api/idbrequest/result/index.html b/files/fr/web/api/idbrequest/result/index.html new file mode 100644 index 0000000000..654ffb20d1 --- /dev/null +++ b/files/fr/web/api/idbrequest/result/index.html @@ -0,0 +1,168 @@ +--- +title: IDBRequest.result +slug: Web/API/IDBRequest/result +tags: + - API + - IDBRequest + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBRequest/result +--- +<div>{{APIRef("IndexedDB")}}</div> + +<p>La propriété <strong><code>result</code></strong>, rattachée à l'interface {{domxref("IDBRequest")}}, renvoie le résultat de la requête. Si la requête échoue et que le résultat n'est pas disponible, une exception <code>InvalidStateError</code> sera levée.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox">var resultat = request.result;</pre> + +<h3 id="Valeur">Valeur</h3> + +<p>La valeur du résultat de la requête (le type dépend des objets du magasin d'objets).</p> + +<h2 id="Exemples">Exemples</h2> + +<p>Dans l'exemple qui suit, on souhaite récupérer l'enregistrement qui correspond à un titre donné. Le gestionnaire d'évènements <code>onsuccess</code> permet de récupérer l'enregistrement contenu dans le magasin d'objet ({{domxref("IDBObjectStore")}}) (via <code>objectStoreTitleRequest.result</code>). Ensuite, on met à jour une propriété de cet enregistrement et on replace cet enregistrement dans le magasin d'objet.</p> + +<pre class="brush: js;highlight:[11]">var title = "Walk dog"; + +// On ouvre une transaction en lecture/écriture +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// On récupère l'objet qui possède le titre souhaité +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // On agit sur les données de l'objet de la requête + var data = objectStoreTitleRequest.result; + + // On met à jour la propriété notified avec "yes" + data.notified = "yes"; + + // On crée une autre requête pour réinsérer l'objet dans la base + var updateTitleRequest = objectStore.put(data); + + // Lorsque cette seconde requête est terminée, on lance displayData() pour rafraîchir l'écran + updateTitleRequest.onsuccess = function() { + displayData(); + }; +};</pre> + +<div class="note"> +<p><strong>Note :</strong> pour un exemple fonctionnel complet, voir notre <a href="https://github.com/mdn/to-do-notifications/">application To-do</a> (<a href="https://mdn.github.io/to-do-notifications/">exemple</a>).</p> +</div> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">État</th> + <th scope="col">Commentaires</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-result', 'result')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support simple</td> + <td>23{{property_prefix("webkit")}}<br> + 24</td> + <td>{{CompatVersionUnknown}}</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>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</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>Fonctionnalité</th> + <th>Android</th> + <th>Webview Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome pour Android</th> + </tr> + <tr> + <td>Support simple</td> + <td>4.4</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("22.0")}}</td> + <td>1.0.1</td> + <td>10</td> + <td>22</td> + <td>8</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("37.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/Web/API/API_IndexedDB/Using_IndexedDB">Utiliser IndexedDB</a></li> + <li>Initier une connexion : {{domxref("IDBDatabase")}}</li> + <li>Utiliser les transactions : {{domxref("IDBTransaction")}}</li> + <li>Définir un intervalle de clés : {{domxref("IDBKeyRange")}}</li> + <li>Récupérer et modifier les données : {{domxref("IDBObjectStore")}}</li> + <li>Utiliser les curseurs {{domxref("IDBCursor")}}</li> + <li>Exemple de référence : <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="https://mdn.github.io/to-do-notifications/">exemple <em>live</em></a>).</li> +</ul> diff --git a/files/fr/web/api/idbrequest/source/index.html b/files/fr/web/api/idbrequest/source/index.html new file mode 100644 index 0000000000..dcf0bb4029 --- /dev/null +++ b/files/fr/web/api/idbrequest/source/index.html @@ -0,0 +1,178 @@ +--- +title: IDBRequest.source +slug: Web/API/IDBRequest/source +tags: + - API + - IDBRequest + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBRequest/source +--- +<div>{{APIRef("IndexedDB")}}</div> + +<p>La propriété <strong><code>source</code></strong> est une propriété en lecture seule, rattachée à l'interface {{domxref("IDBRequest")}}, et qui indique la source de la requête (c'est-à-dire l'index ou le magasin d'objets utilisé). Si aucune source n'existe (par exemple car on a appelé {{domxref("indexedDB.open")}}), la propriété vaut <code>null</code>.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox">var <em>IDBIndex</em> = <em>request</em>.source; +var <em>IDBCursor</em> = <em>request</em>.source; +var <em>IDBObjectStore</em> = <em>request</em>.source; +</pre> + +<h3 id="Valeur">Valeur</h3> + +<p>Un objet qui représente la source de la requête. Ce peut être un objet {{domxref("IDBIndex")}}, {{domxref("IDBObjectStore")}} ou un objet {{domxref("IDBCursor")}}.</p> + +<h2 id="Exemples">Exemples</h2> + +<p>Dans l'exemple qui suit, on récupère un enregistrement avec un titre donné depuis un magasin d'objets. Ensuite, on met à jour une des propriétés de cet enregistrement et on met à jour le magasin d'objets en insérant cet objet modifié. Lors de cette deuxième requête, on affiche la source dans la console. Pour consulter un exemple fonctionnel complet, vous pouvez vous référer à notre application <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> (<a href="https://mdn.github.io/to-do-notifications/">cf. l'exemple <em>live</em></a>).</p> + +<pre class="brush: js;highlight:[11]">var title = "Walk dog"; + +// On ouvre une transaction +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// On fait une requête pour récupérer +// l'enregistrement qui possède le titre +// souhaité +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // On récupère l'objet afin de le modifier + var data = objectStoreTitleRequest.result; + + // On met à jour la propriété notified + // avec la valeur "yes" + data.notified = "yes"; + + // On crée une autre requête pour replacer + // l'enregistrement modifié dans la base de d + // données + var updateTitleRequest = objectStore.put(data); + + // Ici, on affiche la source de la requête dans + // la console + console.log("La source de cette requête est " + updateTitlerequest.source); + // Quand cette deuxième requête sera appliquée, + // on lancera displayData() pour mettre à jour + // l'affichage + updateTitleRequest.onsuccess = function() { displayData(); }; +}; +</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">État</th> + <th scope="col">Commentaires</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-source', 'source')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName("IndexedDB 2", "#dom-idbrequest-source", "source")}}</td> + <td>{{Spec2("IndexedDB 2")}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support simple</td> + <td>23{{property_prefix("webkit")}}<br> + 24 (sans préfixe)</td> + <td>{{CompatVersionUnknown}}</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>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</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>Fonctionnalité</th> + <th>Android</th> + <th>Webview Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome pour Android</th> + </tr> + <tr> + <td>Support simple</td> + <td>4.4</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("22.0")}}</td> + <td>10</td> + <td>22</td> + <td>8</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td>Disponible dans les <em>web workers</em></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("37.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Voir_aussi">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/Web/API/API_IndexedDB/Using_IndexedDB">Manipuler IndexedDB</a></li> + <li>Démarrer des transactions : {{domxref("IDBDatabase")}}</li> + <li>Manipuler des transactions : {{domxref("IDBTransaction")}}</li> + <li>Définir un intervalle de clés : {{domxref("IDBKeyRange")}}</li> + <li>Récupérer des données et les modifier : {{domxref("IDBObjectStore")}}</li> + <li>Manipuler des curseurs : {{domxref("IDBCursor")}}</li> + <li>Exemple de référence pour IndexedDB : <a href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a></li> +</ul> diff --git a/files/fr/web/api/idbrequest/transaction/index.html b/files/fr/web/api/idbrequest/transaction/index.html new file mode 100644 index 0000000000..d8d1e99ef8 --- /dev/null +++ b/files/fr/web/api/idbrequest/transaction/index.html @@ -0,0 +1,180 @@ +--- +title: IDBRequest.transaction +slug: Web/API/IDBRequest/transaction +translation_of: Web/API/IDBRequest/transaction +--- +<p>{{ APIRef("IndexedDB") }}</p> + +<p>La propriété <strong><code>transaction</code></strong> de l'interface IDBRequest renvoie la {{domxref("IDBTransaction","transaction")}} dans laquelle on fait la requête.La propriètè peut renvoiyer <code>null</code> si requête se fait sans transaction, comme un objet IDBRequest renvoyé par {{domxref("IDBFactory.open")}} dans ce cas on est juste connecté à la base de données.</p> + +<p class="note"> Durant la gestion d'un événement {{domxref("IDBOpenDBRequest.onupgradeneeded", "upgradeneeded")}} qui met à jour la version de la base de données, la propriété <strong><code>transaction</code></strong> doit être une {{domxref("IDBTransaction","transaction")}} ouverte en {{domxref("IDBTransaction.mode", "mode")}} <code>"versionchange"</code>, on peut alors accéder aux {{domxref("IDBObjectStore","magasins d'objets")}} et {{domxref("IDBIndex","index")}} ou annulé la mise à niveau. Après quoi, la propriété <strong><code>transaction</code></strong> renverra encore <code>null</code>.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="brush: js">var myTransaction = request.transaction;</pre> + +<h3 id="Valeur">Valeur</h3> + +<p>Une {{domxref("IDBTransaction","transaction")}}.</p> + +<h2 id="Exemple">Exemple</h2> + +<p>L'exemple suivant demande un titre d'enregistrement donné, <code>onsuccess</code> obtient l'enregistrement associé du {{domxref("IDBObjectStore","magasin d'objects")}} (mis à disposition en tant que <code>objectStoreTitleRequest.result</code>), on met à jour une propriété de l'enregistrement, puis le sauve dans le magasin d'objects. La {{domxref("IDBTransaction","transaction")}} à l'origine de la deuxième {{domxref("IBBRequest","requête")}} est affichée sur la console du développeur (Ps, les deux requêtes proviennent de la même transaction). En bas est une fonction onerror qui affiche le code d'erreur si la requête échoue. Pour un exemple de travail complet, voir notre <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> app (<a href="http://mdn.github.io/to-do-notifications/">view example live</a>).</p> + +<pre class="brush: js">var title = "Walk dog"; + +// Ouvrez une transaction comme d'habitude +var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList'); + +// Obtenez l'objet toDoList qui a ce titre +var objectStoreTitleRequest = objectStore.get(title); + +objectStoreTitleRequest.onsuccess = function() { + // Prenez l'objet de données renvoyé comme résultat + var data = objectStoreTitleRequest.result; + + // Mettre à jour la valeur notified de l'objet à "yes" + data.notified = "yes"; + + // Créer une autre requête qui insère le nouvelle élément dans la base de données + var updateTitleRequest = objectStore.put(data); + + // Affiche la transaction à l'origine de la deuxième requête + console.log(" la transaction à l'origine de ces requêtes est " + updateTitleRequest.transaction); + + // Lorsque cette requête réussit, appelle de la fonction displayData() pour mettre à jour l'affichage + updateTitleRequest.onsuccess = function() { + displayData(); + }; + +objectStoreTitleRequest.onerror = function() { + // Si une erreur pendant la requête, on l'affiche + console.log("Il y a eu une erreur dans la récupération des données: " + objectStoreTitleRequest.error); +}; +</pre> + +<p>Cet exemple montre comment la propriété <strong><code>transaction</code></strong> peut être utilisé pendant une mise à niveau de version pour accéder à des {{domxref("IDBObjectStore","magasins d'objects")}} existants: </p> + +<pre class="brush: js">var openRequest = indexedDB.open('db', 2); +console.log(openRequest.transaction); // Affiche "null". + +openRequest.onupgradeneeded = function(event) { + console.log(openRequest.transaction.mode); // Affiche "versionchange". + var db = openRequest.result; + if (event.oldVersion < 1) { + // Nouvelle base de données, créer un magasin d'objets "livres". + db.createObjectStore('books'); + } + if (event.oldVersion < 2) { + // Mise à niveau de la base de données v1: ajoute un index sur "title" pour stocker les livres. + var bookStore = openRequest.transaction.objectStore('books'); + bookStore.createIndex('by_title', 'title'); + } +}; + +openRequest.onsuccess = function() { + console.log(openRequest.transaction); // Affiche "null". +}; +</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">Statut</th> + <th scope="col">Commentaire</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBRequest-transaction', 'transaction')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilité avec les navigateurs</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Fonctionnalité</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Support basique</td> + <td>23{{property_prefix("webkit")}}<br> + 24</td> + <td>10 {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16.0")}}</td> + <td>10, en partie</td> + <td>15</td> + <td>7.1</td> + </tr> + <tr> + <td>Disponible dans 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>Fonctionnalité</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>Support basique</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>Disponible dans 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> + +<h2 id="Voir_aussi">Voir aussi</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> |