From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/fr/web/api/idbtransaction/db/index.html | 189 ++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 files/fr/web/api/idbtransaction/db/index.html (limited to 'files/fr/web/api/idbtransaction/db') diff --git a/files/fr/web/api/idbtransaction/db/index.html b/files/fr/web/api/idbtransaction/db/index.html new file mode 100644 index 0000000000..460fc2d4c7 --- /dev/null +++ b/files/fr/web/api/idbtransaction/db/index.html @@ -0,0 +1,189 @@ +--- +title: IDBTransaction.db +slug: Web/API/IDBTransaction/db +tags: + - API + - IDBTransaction + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBTransaction/db +--- +
{{APIRef("IndexedDB")}}
+ +

La propriété db de l'interface {{domxref("IDBTransaction")}} renvoie la {{domxref("IDBDatabase","connexion","",1)}} à la base de donnée associée à la {{domxref("IDBTransaction","transaction","",1)}}.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var myDatabase = transaction.db;
+ +

Valeur

+ +

Une {{domxref("IDBDatabase","connexion","",1)}} à la base de données sous la forme d'un objet IDBDatabase.

+ +

Exemples

+ +

Dans le fragment de code suivant, on ouvre une {{domxref("IDBDatabase","connexion","",1)}} à la base de donnée. Sur cette connexion on démarre une {{domxref("IDBTransaction","transaction","",1)}} en lecture/écriture pour {{domxref("IDBObjectStore","accéder au magasin d'objet","",1)}}  "toDoList" et y {{domxref("IDBObjectStore.add","ajouter","",1)}} un enregistrement. Notez également les gestionnaires d'événements {{domxref("IDBTransaction.oncomplete","oncomplete")}} et {{domxref("IDBTransaction.onerror","onerror")}} de la transaction qui affichent sur la page le résultat de la transaction.

+ +

À la fin, la méthode db sert à renvoyer la connexion à la base de données associée à la transaction.

+ +
//Connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += 'Connexion établie.';
+
+  //Affecter la connexion à la variable db.
+  db = DBOpenRequest.result;
+
+  // Exécuter la fonction addData () pour emmagasiner
+  // les données dans la base
+  addData();
+};
+function addData() {
+    //Un nouvel objet prêt à être emmagasiné
+  newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];
+
+  // Ouvrir une transaction de lecture / écriture
+  // pour permettre le traitement des données sur la connexion
+  var transaction = db.transaction(["toDoList"], "readwrite");
+
+  // En cas de succès de l'ouverture de la transaction
+  transaction.oncomplete = function(event) {
+    note.innerHTML += '<li>Transaction complété : modification de la base de données terminée.</li>';
+  };
+  // En  cas d'échec de l'ouverture de la transaction
+  transaction.onerror = function(event) {
+    note.innerHTML += '<li>Erreur transaction non ouverte, doublons interdits.</li>';
+  };
+
+  // Ouvrir l'accès au un magasin "toDoList" de la transaction
+  var objectStore = transaction.objectStore("toDoList");
+
+  // Ajouter un enregistrement
+  var objectStoreRequest = objectStore.add(newItem[0]);
+  objectStoreRequest.onsuccess = function(event) {
+    // Signaler l'ajout de l'enregistrement
+    note.innerHTML += '<li>Enregistrement ajouté.</li>';
+  };
+  // Renvoyer la connexion à la base de donnée
+  //associée à cette transaction.
+  transaction.db;
+};
+ 
+ +

Note : pour un exemple fonctionnel complet, voir notre application To-do (exemple).

+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBTransaction-db', 'db')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support simple23{{property_prefix("webkit")}}
+ 24
{{CompatVersionUnknown}}10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10157.1
Disponible dans les workers{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari MobileChrome pour Android
Support simple4.4{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("22.0")}}1.0.110228{{CompatVersionUnknown}}
Disponible dans les workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf