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/idbobjectstore/keypath | |
| 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/idbobjectstore/keypath')
| -rw-r--r-- | files/fr/web/api/idbobjectstore/keypath/index.html | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/files/fr/web/api/idbobjectstore/keypath/index.html b/files/fr/web/api/idbobjectstore/keypath/index.html new file mode 100644 index 0000000000..16e46308c8 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/keypath/index.html @@ -0,0 +1,195 @@ +--- +title: IDBObjectStore.keyPath +slug: Web/API/IDBObjectStore/keyPath +tags: + - API + - IDBObjectStore + - IndexedDB + - Propriété + - Reference + - keyPath +translation_of: Web/API/IDBObjectStore/keyPath +--- +<div>{{APIRef("IndexedDB")}}</div> + +<p>La propriété <strong><code>keyPath</code></strong> de l'interface {{domxref("IDBObjectStore")}} renvoie le <a href="/fr/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB#gloss_keypath">chemin de la clé</a> de ce magasin d'objet.</p> + +<p>Si cette propriété vaut <code>null</code> l'application doit fournir une clé pour chaque opération de modification.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox">var mykeyPath = objectStore.keyPath;</pre> + +<h3 id="Valeur">Valeur</h3> + +<p>N'importe quel type de valeur.</p> + +<h2 id="Exemple">Exemple</h2> + +<p>Dans l'exemple suivant, on initialise une transaction de lecture/écriture sur une base de données en ajoutant des données dans un magasin d'objets via la méthode <code>add()</code>. Une fois l'objet créé, on affiche <code>objectStore.keyPath</code> en sortie de la console. Pour un exemple complet et fonctionnel, vous pouvez utiliser notre application <a href="https://github.com/mdn/to-do-notifications/">To-do Notifications</a> (<a href="https://mdn.github.io/to-do-notifications/">tester la démo</a>).</p> + +<pre class="brush: js">// On commence par ouvrir la base de données +var DBOpenRequest = window.indexedDB.open("toDoList", 4); + +DBOpenRequest.onsuccess = function(event) { + note.innerHTML += '<li>Initialisation de la base.</li>'; + + // On enregistre le résultat de l'ouverture + // dans la variable db afin de l'utiliser + // ensuite + var db = DBOpenRequest.result; + + // On utilise la fonction addData() afin d'ajouter + // des données à la base de données + addData(); +}; + +function addData() { + // On crée un nouvel objet prêt à être inséré + // dans la base de données + var newItem = [ { taskTitle: "Promener le chien", hours: 19, minutes: 30, day: 24, month: "Décembre", year: 2013, notified: "no" } ]; + + // On ouvre une transaction en lecture/écriture + // vers la base de données afin d'ajouter des + // données + var transaction = db.transaction(["toDoList"], "readwrite"); + + // On indique le succès de la transaction + transaction.oncomplete = function(event) { + note.innerHTML += '<li>Transaction terminée : modification finie.</li>'; + }; + + transaction.onerror = function(event) { + note.innerHTML += '<li>Transaction non-ouverte à cause d'une erreur. Les doublons ne sont pas autorisés.</li>'; + }; + + // On crée un magasin d'objet pour la transaction + // et on affiche KeyPath dans la console + var objectStore = transaction.objectStore("toDoList"); + console.log(objectStore.keyPath); + + // On ajoute l'objet newItem au magasin d'objets + var objectStoreRequest = objectStore.add(newItem[0]); + + objectStoreRequest.onsuccess = function(event) { + // On indique le succès de l'ajout de l'objet + // dans la base de données + note.innerHTML += '<li>Un nouvel élément a été ajouté dans la base de données.</li>'; + }; +};</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-IDBObjectStore-keyPath', 'keyPath')}}</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<br> + 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, partiel</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<br> + 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> |
