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/idbobjectstore/add/index.html | 239 +++++++++++++++++++++ .../api/idbobjectstore/autoincrement/index.html | 178 +++++++++++++++ files/fr/web/api/idbobjectstore/clear/index.html | 181 ++++++++++++++++ files/fr/web/api/idbobjectstore/count/index.html | 183 ++++++++++++++++ .../web/api/idbobjectstore/createindex/index.html | 231 ++++++++++++++++++++ files/fr/web/api/idbobjectstore/delete/index.html | 221 +++++++++++++++++++ .../web/api/idbobjectstore/deleteindex/index.html | 197 +++++++++++++++++ files/fr/web/api/idbobjectstore/get/index.html | 195 +++++++++++++++++ files/fr/web/api/idbobjectstore/getall/index.html | 128 +++++++++++ .../web/api/idbobjectstore/getallkeys/index.html | 176 +++++++++++++++ files/fr/web/api/idbobjectstore/getkey/index.html | 174 +++++++++++++++ files/fr/web/api/idbobjectstore/index.html | 238 ++++++++++++++++++++ files/fr/web/api/idbobjectstore/index/index.html | 200 +++++++++++++++++ .../web/api/idbobjectstore/indexnames/index.html | 188 ++++++++++++++++ files/fr/web/api/idbobjectstore/keypath/index.html | 195 +++++++++++++++++ files/fr/web/api/idbobjectstore/name/index.html | 216 +++++++++++++++++++ .../web/api/idbobjectstore/opencursor/index.html | 193 +++++++++++++++++ .../api/idbobjectstore/openkeycursor/index.html | 181 ++++++++++++++++ files/fr/web/api/idbobjectstore/put/index.html | 229 ++++++++++++++++++++ .../web/api/idbobjectstore/transaction/index.html | 171 +++++++++++++++ 20 files changed, 3914 insertions(+) create mode 100644 files/fr/web/api/idbobjectstore/add/index.html create mode 100644 files/fr/web/api/idbobjectstore/autoincrement/index.html create mode 100644 files/fr/web/api/idbobjectstore/clear/index.html create mode 100644 files/fr/web/api/idbobjectstore/count/index.html create mode 100644 files/fr/web/api/idbobjectstore/createindex/index.html create mode 100644 files/fr/web/api/idbobjectstore/delete/index.html create mode 100644 files/fr/web/api/idbobjectstore/deleteindex/index.html create mode 100644 files/fr/web/api/idbobjectstore/get/index.html create mode 100644 files/fr/web/api/idbobjectstore/getall/index.html create mode 100644 files/fr/web/api/idbobjectstore/getallkeys/index.html create mode 100644 files/fr/web/api/idbobjectstore/getkey/index.html create mode 100644 files/fr/web/api/idbobjectstore/index.html create mode 100644 files/fr/web/api/idbobjectstore/index/index.html create mode 100644 files/fr/web/api/idbobjectstore/indexnames/index.html create mode 100644 files/fr/web/api/idbobjectstore/keypath/index.html create mode 100644 files/fr/web/api/idbobjectstore/name/index.html create mode 100644 files/fr/web/api/idbobjectstore/opencursor/index.html create mode 100644 files/fr/web/api/idbobjectstore/openkeycursor/index.html create mode 100644 files/fr/web/api/idbobjectstore/put/index.html create mode 100644 files/fr/web/api/idbobjectstore/transaction/index.html (limited to 'files/fr/web/api/idbobjectstore') diff --git a/files/fr/web/api/idbobjectstore/add/index.html b/files/fr/web/api/idbobjectstore/add/index.html new file mode 100644 index 0000000000..0e2a4a7b83 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/add/index.html @@ -0,0 +1,239 @@ +--- +title: IDBObjectStore.add() +slug: Web/API/IDBObjectStore/add +translation_of: Web/API/IDBObjectStore/add +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode add(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet {{domxref("IDBRequest")}} et, dans un thread séparé, crée un clone structurel de la valeur et stocke la valeur clonée dans le magasin d'objet. Cette méthode permet d'ajouter de nouveaux enregistrements dans un magasin d'objet.

+ +

Afin de déterminer si l'opération add s'est effectuée correctement, on pourra écouter l'évènement complete de la transaction et l'évènement success de la requête IDBObjectStore.add car la transaction peut échouer après le déclenchement de l'évènement success. Autremnt dit, l'évènement success est uniquement déclenché au moment où la transaction a été mise dans la file.

+ +

La méthode add ne permet que d'insérer des objets. Si un enregistrement existe déjà dans le magasin d'objet pour la clé fournie en argument, un évènement ConstrainError sera déclenché via l'objet {{domxref("IDBRequest")}}. Si on souhaite mettre à jour des enregistrements existants, on utilisera plutôt la méthode {{domxref("IDBObjectStore.put")}}.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var request = objectStore.add(valeur, clé);
+ +

Paramètres

+ +
+
valeur
+
La valeur à ajouter au magasin.
+
clé
+
La clé qu'on souhaite utiliser pour identifier l'enregistrement. Si elle n'est pas indiquée, la valeur par défaut sera null.
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} qui émettra les différents évènements relatifs à l'opération.

+ +

Exceptions

+ +

Cette méthode peut lever une exception {{domxref("DOMException")}} ayant l'un des types suivants :

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
ReadOnlyErrorLa transaction associée à cette opération est en lecture seule.
TransactionInactiveErrorLa transaction pour cet objet  {{domxref("IDBObjectStore")}} est inactive.
DataError +

Un des conditions suivantes est vérifiée :

+ +
    +
  • Le magasin d'objet utilise des clés en ligne ou possède un générateur de clés et une clé a été fournie dans la fonction.
  • +
  • Le magasin d'objet utilise des clés hors lignes et et n'a pas de générateur de clés et aucune clé n'a été fournie dans la fonction.
  • +
  • Le magasin d'objet utilise des clés en ligne mais ne possède pas de générateur de clés et le chemin de clé utilisé par le magasin ne pointe pas vers une clé valide.
  • +
  • La clé a été fournie à la fonction mais ce paramètre n'est pas une clé valide.
  • +
+
InvalidStateErrorL'objet {{domxref("IDBObjectStore")}} a été supprimé ou déplacé.
DataCloneErrorLa donnée qui devait être enregistrée n'a pas pu être clonée par l'algorithme de clonage interne.
+ +

Exemples

+ +

Dans le fragment de code suivant, on ouvre une transaction en lecture/écriture vers la base de données et on ajoute des données au magasin d'objet grâce à la méthode add(). On notera également les fonctions rattachées à la transaction qui sont utilisées comme gestionnaires d'évènement et qui permettent de savoir si la transaction a réussi ou échoué.

+ +
// On ouvre la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>Database initialisée.</li>';
+
+  // On enregistre le résultat dans la variable db
+  // afin de l'utiliser par la suite
+  var db = DBOpenRequest.result;
+
+  // On utilise la fonction addData() afin d'ajouter
+  // des données dans la base de données
+  addData();
+};
+
+function addData() {
+  // On crée un nouvel objet qu'on insèrera ensuite
+  // dans la base de données
+  var newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];
+
+  // On ouvre une transaction en lecture/écriture
+  // afin d'ajouter les données
+  var transaction = db.transaction(["toDoList"], "readwrite");
+
+  // On indique si la transaction s'est déroulées
+  // sans problème
+  transaction.oncomplete = function(event) {
+    note.innerHTML += '<li>Transaction terminée : modification effectuée.</li>';
+  };
+
+
+  transaction.onerror = function(event) {
+    note.innerHTML += '<li>Ouverture de la transaction impossible : les objets dupliqués ne sont pas autorisés.</li>';
+  };
+
+  // On crée un magasin d'objets pour la transaction
+  var objectStore = transaction.objectStore("toDoList");
+
+  // On ajoute l'objet newItem dans le magasin d'objets
+  var objectStoreRequest = objectStore.add(newItem[0]);
+
+  objectStoreRequest.onsuccess = function(event) {
+    // On indique la réussite de l'insertion
+    note.innerHTML += '<li>Nouvel objet ajouté dans la base de données.</li>';
+  };
+};
+ +
+

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

+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-add-IDBRequest-any-value-any-key', 'add()')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support simple23{{property_prefix("webkit")}}
+ 24 (unprefixed)
{{CompatVersionUnknown}}10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, partial157.1
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome pour Android
Support simple4.4{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("22.0")}}10228{{CompatVersionUnknown}}
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/autoincrement/index.html b/files/fr/web/api/idbobjectstore/autoincrement/index.html new file mode 100644 index 0000000000..d6b516219f --- /dev/null +++ b/files/fr/web/api/idbobjectstore/autoincrement/index.html @@ -0,0 +1,178 @@ +--- +title: IDBObjectStore.autoIncrement +slug: Web/API/IDBObjectStore/autoIncrement +translation_of: Web/API/IDBObjectStore/autoIncrement +--- +

{{ APIRef("IndexedDB") }}

+ +

La propriété autoIncrement de l'interface {{domxref("IDBObjectStore")}} renvoie la position du drapeau d’incrémentation automatique du magasin d'objet {{domxref("IDBObjectStore","relié")}}.

+ +

Note: Chaque magasin d'objets à son conteur d’incrémentation automatique.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var myAutoIncrement = objectStore.autoIncrement;
+ +

Valeur

+ +

Un {{domxref("Boolean","booléen")}} .

+ +
+
true
+
Le magasin d'objet relié s’incrémente automatiquement.
+
false
+
Le magasin d'objet relié ne s’incrémente pas automatiquement.
+
+ +

Exemple

+ +

Dans le code suivant, on ouvre une {{domxref("IDBDatabase","connexion")}} à la base de donnée. Sur cette connexion on démarre une {{domxref("IDBTransaction","transaction")}} en lecture/écriture pour avoir un {{domxref("IDBObjectStore","accès")}} au magasin d'objet "toDoList" dans lequel on {{domxref("IDBObjectStore.add","ajoute")}} un enregistrement.

+ +

La propriété autoIncrement de l'accès au magasin d'objet sert à affiché la position du drapeau d’incrémentation automatique de ce magasin d'objet sur la console.

+ +
//Connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+	note.innerHTML += 'Connexion établie.';
+
+	//Affecte la connexion à la variable db.
+	db = DBOpenRequest.result;
+
+	// Exécutez la fonction addData () pour ajouter l'enregistrement dans le magasin d'objet
+	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" } ];
+
+	// ouvre une transaction de lecture / écriture  prête au 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>L\'erreur: "' + transaction.error +'" c\'est produite échec de la transaction.</li>';
+	};
+
+	// ouvre l'accès au un magasin "toDoList" de la transaction
+	var objectStore = transaction.objectStore("toDoList");
+
+//->Affiche la position du drapeau d’incrémentation automatique
+    console.log(objectStore.autoIncrement);
+
+	// Ajoute un enregistrement
+	var objectStoreRequest = objectStore.add(newItem[0]);
+	objectStoreRequest.onsuccess = function(event) {
+		// signale l'ajout de l'enregistrement
+		note.innerHTML += '<li>Enregistrement ajouté.</li>';
+	};
+ };
+ 
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécification

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#widl-IDBObjectStore-autoIncrement', 'autoIncrement')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support basique4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/clear/index.html b/files/fr/web/api/idbobjectstore/clear/index.html new file mode 100644 index 0000000000..3f6213015f --- /dev/null +++ b/files/fr/web/api/idbobjectstore/clear/index.html @@ -0,0 +1,181 @@ +--- +title: IDBObjectStore.clear() +slug: Web/API/IDBObjectStore/clear +translation_of: Web/API/IDBObjectStore/clear +--- +

{{ APIRef("IndexedDB") }}

+ +

La méthode clear() de l'interface {{domxref("IDBObjectStore")}} fait une {{domxref("IDBRequest","requête")}} pour vider le magasin d'objet {{domxref("IDBObjectStore","relié")}}.

+ +

Vider un magasin d'objet consiste à supprimer tous les enregistrements et les entrées des index de ce magasin d'objet.

+ +
+

Note: La méthode clear() ne remet pas à zero le compteur du génerateur de clé s'il y en à un.

+
+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var request = objectStore.clear();
+ +

Renvoie

+ +

Une {{domxref("IDBRequest","requête")}}.

+ +

Exceptions

+ +
+
ReadOnlyError
+
Cette {{domxref("DOMException","exception")}} est levé si la transaction associé à cette requête est en {{domxref("IDBTransaction.mode","mode")}} lecture seule.
+
TransactionInactiveError
+
Cette {{domxref("DOMException","exception")}} est levé si la {{domxref("IDBTransaction","transaction")}} de l'{{domxref("IDBObjectStore","accès")}} au magasin d’objet est inactive.
+
+ +

Exemple

+ +

Dans le code suivant, on ouvre une {{domxref("IDBDatabase","connexion")}} à la base de donnée. Sur cette connexion on démarre une {{domxref("IDBTransaction","transaction")}} en lecture/écriture pour avoir un {{domxref("IDBObjectStore","accès")}} au magasin d'objet "toDoList" et le {{domxref("IDBObjectStore.clear","vider")}}

+ +

La méthode clear() de l'accès au magasin d'objet fait une {{domxref("IDBRequest","requête")}} pour vider le magasin d'objet toDoList.

+ +
//Connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+	note.innerHTML += '<li>Connexion établie.</li>';
+
+	//Affecte la connexion à la variable db.
+	db = DBOpenRequest.result;
+
+  // Exécutez la fonction clearData () pour vider les données dans le magasin d'objet
+  clearData();
+};
+
+function clearData() {
+  // ouvre une transaction de lecture / écriture  prête pour le nettoyage
+  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>Transaction en échec à cause de l\'erreur : ' + transaction.error + '</li>';
+  };
+
+  // ouvre l'accès au un magasin "toDoList" de la transaction
+  var objectStore = transaction.objectStore("toDoList");
+
+  // Vide le magasin d'objet
+  var objectStoreRequest = objectStore.clear();
+
+  objectStoreRequest.onsuccess = function(event) {
+  // rapporte le succès du nettoyage
+  note.innerHTML += '<li>Enregistrements effacées.</li>';
+  };
+};
+
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécification

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#widl-IDBObjectStore-clear-IDBRequest', 'clear()')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support basique4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/count/index.html b/files/fr/web/api/idbobjectstore/count/index.html new file mode 100644 index 0000000000..3ac1c44d6e --- /dev/null +++ b/files/fr/web/api/idbobjectstore/count/index.html @@ -0,0 +1,183 @@ +--- +title: IDBObjectStore.count() +slug: Web/API/IDBObjectStore/count +tags: + - API + - IDBObjectStore + - IndexedDB + - Méthode + - Reference +translation_of: Web/API/IDBObjectStore/count +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode count(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet {{domxref("IDBRequest")}} et, dans un thread séparé, renvoie le nombre d'enregistrements qui correspondent à la clé ou à l'intervalle de clé ({{domxref("IDBKeyRange")}}) passé en argument. Si aucun argument n'est fourni, la méthode renvoie le nombre total d'enregistrements contenus dans le magasin d'objets.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var requete = ObjectStore.count(optionalKeyRange);
+ +

Paramètres

+ +
+
optionalKeyRange
+
Une clé ou un intervalle de clé ({{domxref("IDBKeyRange")}}) qui indique le critère de comptage des enregistrements.
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} sur lequel seront déclenchés les différents évènements relatifs à l'opération.

+ +

Exceptions

+ +

Cette méthode peut déclencher une exception {{domxref("DOMException")}} ayant un des types suivants :

+ + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
InvalidStateErrorL'objet {{domxref("IDBObjectStore")}} a été supprimé.
TransactionInactiveErrorLa transaction associée à l'objet {{domxref("IDBObjectStore")}} est inactive.
DataErrorLa clé ou l'intervalle de clé passé en argument est invalide.
+ +

Exemples

+ +

Dans ce fragment de code, on crée une transaction, on récupère un magasin d'objets puis on compte le nombre d'enregistrements contenus dans ce magasin grâce à la méthode count(). Lorsque l'évènement associé au succès de l'opération est déclenché, on inscrit le résultat dans la console.

+ +
var transaction = db.transaction(['fThings'], 'readonly');
+var objectStore = transaction.objectStore('fThings');
+
+var countRequest = objectStore.count();
+countRequest.onsuccess = function() {
+  console.log(countRequest.result);
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-count-IDBRequest-any-key', 'count()')}}{{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 web 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 web workers{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/createindex/index.html b/files/fr/web/api/idbobjectstore/createindex/index.html new file mode 100644 index 0000000000..aef72d855a --- /dev/null +++ b/files/fr/web/api/idbobjectstore/createindex/index.html @@ -0,0 +1,231 @@ +--- +title: IDBObjectStore.createIndex() +slug: Web/API/IDBObjectStore/createIndex +translation_of: Web/API/IDBObjectStore/createIndex +--- +

{{ APIRef("IndexedDB") }}

+ +

La méthode createIndex() de l'interface {{domxref("IDBObjectStore")}} met en place sur le magasin d'objet {{domxref("IDBObjectStore","relié")}} un nouvel index et en renvoie l'{{domxref("IDBIndex","accès")}}.

+ +
+

Note: cette méthode ne peut être appelé que si la transaction de l'accès au magasin d'objet est en mode VersionChange.

+
+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
objectStore.createIndex(nomIndex, nomCle, parametresIndexOptionnel);
+ +

Paramètres

+ +
+
nomIndex
+
Le nom de l'index que l'on veut ajouter. Il est possible d'ajouter un index avec un nom vide.
+
nomCle
+
Le nom de clé qu'utilise l'index. Il est possible d'ajouter un index sans nom de clé.
+
parametresIndexOptionnel {{optional_inline}}
+
+

Un objet optionnel pouvant inclure une ou plusieurs des propriétés suivantes:

+ + + + + + + + + + + + + + + + + + + + + + +
PropriétéDescription
uniqueSi true, l'index empêcheras la duplication d'une clé.
multiEntrySi true, l'index ajoutera une entrée pour chaque élément de tableau quand le nom de clé de clé est résolue. Si false, il ajoutera un seule entrée contenant le tableau.
locale +

Actuellement uniquement dans Firefox 43+ , cela vous permet de spécifier des paramètres de localisation pour l'index. Toutes les opérations de tri effectuées sur les données via des intervalle de clé obéirons aux règles locales de tri (voir trie dans localisation courante, en). Vous pouvez spécifier sa valeur de trois façons différentes:

+ +
    +
  • string: une chaîne de caractère contenant le code de la localisation , par exemple 'fr' ou 'en-US'.
  • +
  • auto: La localisation par défaut est utilisé (peut être régler par l'utilisateur).
  • +
  • null or undefined: Les règles de tri par défaut de javaScript seront utilisées.
  • +
+
+
+
+ +

Renvoie

+ +

L'{{domxref("IDBIndex","accès")}} au nouvel index.

+ +

Exceptions

+ +
+
InvalidStateError
+
Cette {{domxref("DOMException","exeption")}} si la {{domxref("IDBTransaction","transaction")}} dont dépend cet {{domxref("IDBObjectStore","accès")}} au magasin d'objet n'est pas en {{domxref("IDBTransaction.mode","mode")}} versionchange.
+
TransactionInactiveError
+
Cette {{domxref("DOMException","exeption")}} si la {{domxref("IDBTransaction","transaction")}} de l'{{domxref("IDBObjectStore","accès")}} au magasin d’objet est inactive. +

Dans les versions de Firefox antérieur à 41, une InvalidStateError est levé dans ce cas aussi, ce qui est trompeur. Cela a été corrigé (voir bug 1176165 ).

+
+
ConstraintError
+
Cette {{domxref("DOMException","exeption")}} si un index avec le même nom (case sensible) existe déjà sur le magasin d'objet.
+
+ +

Exemple

+ +

Dans l'exemple suivant on peut voir le gestionnaire d'événement {{domxref("IDBOpenDBRequest.onupgradeneeded","onupgradeneeded")}} être utilisé pour mètre à jour la structure de la base de donnée quand un numéro de version supérieur est chargé.

+ +

Des méthode createIndex() sont utilisées pour mètre en place différents index sur le magasin d'objet toDoList.

+ +
var db;
+
+// Requête d'ouverture de la base de données "toDoList"
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+// Gère  l'échec de l'ouverture de la base
+DBOpenRequest.onerror = function(event) {
+  note.innerHTML += '<li>La base de donnée n\'as pas peut être ouverte.</li>';
+};
+
+// Gère le succès de l'ouverture de la base
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>La base de données est ouverte.</li>';
+
+  //La connexion est affcté à la variable db.
+  db = request.result;
+
+  // Exécute une fonction d'affichage displayData()
+  displayData();
+};
+
+// Ce gestionnaire d'événement nécessite  un nouveau numéro de version de la basse de données.
+// Si la base n'existe pas un nouveau numéro de version est généré par la méthode d'ouverture de connexion window.indexDB.open .
+
+DBOpenRequest.onupgradeneeded = function(event) {
+  var db = event.target.result;
+
+  db.onerror = function(event) {
+    note.innerHTML += '<li>Erreur de chargement de la base de données.</li>';
+  };
+
+  // L'Accès au magasin d'objet "toDoList" de la base de donnée
+  var objectStore = db.createObjectStore("toDoList", { keyPath: "taskTitle" });
+
+  // Met en place les index du magasin d'objet
+  objectStore.createIndex("heures", "hours", { unique: false });
+  objectStore.createIndex("minutes", "minutes", { unique: false });
+  objectStore.createIndex("jour", "day", { unique: false });
+  objectStore.createIndex("mois", "month", { unique: false });
+  objectStore.createIndex("annee", "year", { unique: false });
+  objectStore.createIndex("notifiee", "notified", { unique: false });
+};
+
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#widl-IDBObjectStore-createIndex-IDBIndex-DOMString-name-DOMString-sequence-DOMString--keyPath-IDBIndexParameters-optionalParameters', 'createIndex()')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support basique4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/delete/index.html b/files/fr/web/api/idbobjectstore/delete/index.html new file mode 100644 index 0000000000..81350ca992 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/delete/index.html @@ -0,0 +1,221 @@ +--- +title: IDBObjectStore.delete() +slug: Web/API/IDBObjectStore/delete +tags: + - API + - IndexedDB + - Méthode + - Reference +translation_of: Web/API/IDBObjectStore/delete +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode delete(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet {{domxref("IDBRequest")}} et, dans un thread séparé, supprime le ou les enregistrements concernés.

+ +

Cette méthode prend une clé ou un objet {{domxref("IDBKeyRange")}} en argument ce qui permet de supprimer un ou plusieurs enregistrements. Si on souhaite supprimer l'ensemble des enregistrements d'un magasin de données, on utilisera plutôt la méthode {{domxref("IDBObjectStore.clear")}}.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var request = objectStore.delete(keyOrKeyRange);
+ +

Paramètres

+ +
+
keyOrKeyRange
+
La clé de l'enregistrement qu'on souhaite supprimer ou un objet {{domxref("IDBKeyRange")}} qui indique l'intervalle de clés à supprimer.
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} qui recevra les évènements relatifs à cette opération. request.result vaut {{jsxref("undefined")}}.

+ +

Exceptions

+ +

Cette méthode peut lever une des exceptions suivantes :

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
TransactionInactiveErrorLa transaction associée au curseur IDBCursor est inactive.
ReadOnlyErrorLa transaction est uniquement en lecture seule.
InvalidStateErrorLe curseur créé avec {{domxref("IDBindex.openKeyCursor")}}, est en train d'être parcouru ou a été parcouru après sa fin.
DataErrorLa clé ou l'intervalle de clés n'est pas valide.
+ +

Exemples

+ +

Dans l'exemple qui suit, on ouvre une transaction en lecture/écriture et on supprime un enregistrement donné grâce à delete(). Pour un exemple complet, voir l'application Notifications To-do (démonstration).

+ +
// On ouvre l'accès à 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.
+  var db = DBOpenRequest.result;
+
+  // On utilise deleteData() pour supprimer
+  // un enregistrement
+  deleteData();
+};
+
+function deleteData() {
+  // On ouvre une transaction en lecture/écriture
+  // afin de supprimer la donnée
+  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 de la base terminée.</li>';
+  };
+
+
+  transaction.onerror = function(event) {
+    note.innerHTML += '<li>Transaction interrompue suite à l\'erreur : ' + transaction.error + '</li>';
+  };
+
+  // On crée un magasin d'objets pour la transaction
+  var objectStore = transaction.objectStore("toDoList");
+
+  // On supprime l'enregistrement du magasin
+  var objectStoreRequest = objectStore.delete("Walk dog");
+
+  objectStoreRequest.onsuccess = function(event) {
+    // On indique le succès de l'opération
+    note.innerHTML += '<li>Enregistremnt supprimé.</li>';
+  };
+};
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-delete-IDBRequest-any-key', 'delete()')}}{{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")}}
10, partial157.1
Disponible dans les web 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 web workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/deleteindex/index.html b/files/fr/web/api/idbobjectstore/deleteindex/index.html new file mode 100644 index 0000000000..b0ff264b07 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/deleteindex/index.html @@ -0,0 +1,197 @@ +--- +title: IDBObjectStore.deleteIndex() +slug: Web/API/IDBObjectStore/deleteIndex +translation_of: Web/API/IDBObjectStore/deleteIndex +--- +

{{ APIRef("IndexedDB") }}

+ +

La méthode deleteIndex() de l'interface {{domxref("IDBObjectStore")}} supprime l'index dont le nom est passé en paramètre, du magasin d'objet relié ({{domxref("IDBObjectStore")}}).

+ +
+

Note: Cette méthode ne peut être appelée que si la transaction ({{domxref("IDBTransaction")}}) de l'accès ({{domxref("IDBObjectStore")}}) au magasin d'objet est en mode ({{domxref("IDBTransaction.mode")}}) versionchange. Les propriétés indexNames ({{domxref("IDBObjectStore.indexNames")}}) des accès au magasin d'object seront aussi mises à jour.

+
+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
objectStore.deleteIndex(nomIndex);
+ +

Paramètre

+ +
+
nomIndex
+
Le nom de l'index à supprimer.
+
+ +

Valeur de retour

+ +

Void.

+ +

Exceptions

+ +
+
InvalidStateError
+
Cette exception ({{domxref("DOMException")}}) est levée si la transaction ({{domxref("IDBTransaction")}}) dont dépend cet accès ({{domxref("IDBObjectStore")}}) au magasin d'objet n'est pas en mode ({{domxref("IDBTransaction.mode")}}) versionchange.
+
TransactionInactiveError
+
Cette exception ({{domxref("DOMException")}}) est levée si la transaction ({{domxref("IDBTransaction")}}) de l'accès ({{domxref("IDBObjectStore")}}) au magasin d’objet est inactive. +

Dans les versions de Firefox antérieur à 41, une InvalidStateError est levée dans ce cas aussi, ce qui est trompeur. Cela a été corrigé (voir bug 1176165).

+
+
NotFoundError
+
Cette exception ({{domxref("DOMException")}}) est levée si l'index avec le nom (case sensible) demandé n'existe pas sur le magasin d'objet.
+
+ +

Exemple

+ +

Dans l'exemple suivant on peut voir le gestionnaire d'événement {{domxref("IDBOpenDBRequest.onupgradeneeded","onupgradeneeded")}} être utilisé pour mettre à jour la structure de la base de données quand un numéro de version supérieure est chargé.

+ +

Des méthode deleteIndex() sont utilisées pour supprimer d'anciens index du magasin d'objet toDoList.

+ +
var db;
+
+// Requête d'ouverture de la base de données "toDoList"
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+// Gère  l'échec de l'ouverture de la base
+DBOpenRequest.onerror = function(event) {
+  note.innerHTML += '<li>La base de donnée n\'as pas peut être ouverte.</li>';
+};
+
+// Gère le succès de l'ouverture de la base
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>La base de données est ouverte.</li>';
+
+  //
+  db = request.result;
+
+  // Exécute une fonction d'affichage displayData()
+  displayData();
+};
+
+// Ce gestionnaire d'événement nécessite  un nouveau numéro de version de la base de données.
+// Si la base n'existe pas un nouveau numéro de version est généré par la méthode d'ouverture de connexion window.indexDB.open .
+
+DBOpenRequest.onupgradeneeded = function(event) {
+
+  db.onerror = function(event) {
+    note.innerHTML += '<li>Erreur de chargement de la base de données.</li>';
+  };
+
+  // L'Accès au magasin d'objet "toDoList" de la base de données
+  var objectStore = db.createObjectStore("toDoList", { keyPath: "taskTitle" });
+
+  // Met en place les index du magasin d'objet
+  objectStore.createIndex("heures", "hours", { unique: false });
+  objectStore.createIndex("minutes", "minutes", { unique: false });
+  objectStore.createIndex("jour", "day", { unique: false });
+  objectStore.createIndex("mois", "month", { unique: false });
+  objectStore.createIndex("annee", "year", { unique: false });
+  objectStore.createIndex("notifiee", "notified", { unique: false });
+
+  //supprime des index du magasin d'objet
+  objectStore.deleteIndex("secondes");
+  objectStore.deleteIndex("contact");
+};
+
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécification

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-deleteIndex-void-DOMString-indexName', 'deleteIndex()')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support simple23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support simple4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/get/index.html b/files/fr/web/api/idbobjectstore/get/index.html new file mode 100644 index 0000000000..8852a504d4 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/get/index.html @@ -0,0 +1,195 @@ +--- +title: IDBObjectStore.get() +slug: Web/API/IDBObjectStore/get +translation_of: Web/API/IDBObjectStore/get +--- +

{{ APIRef("IndexedDB") }}

+ +
+

La méthode get() de l'interface {{domxref("IDBObjectStore")}} fait une {{domxref("IDBRequest","requête")}} pour renvoyer la valeur d'un enregistrement du magasin d'objet {{domxref("IDBObjectStore","relié")}}.

+
+ +

{{Note("Si plusieurs enregistrements peuvent être sélectionnés la valeur du premier enregistrement rencontré (dont la valeur n'est pas undefined) sera renvoyée.")}} {{Note("On ne peut pas savoir s'il y a correspondance mais que l(es) enregistrement(s) a/ont des valeurs non définie (undefined) ou s'ils n'y as pas de correspondance par cette méthode. On peut utulisé la methode getAllKeys pour retrouvé la ou les clés du ou des enregistrements qui n'ont pas de valeur défini (valeur = undefined).")}}

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var request = objectStore.get(cle);
+ +

Paramètre

+ +
+
cle
+
la clé ou l'{{domxref("IDBKeyRange","intervalle de clé")}} de l'enregistrement dont on cherche la valeur.
+
+ +

Renvoie

+ +
+
Une {{domxref("IDBRequest","requête")}}
+
La propriété {{domxref("IDBRequest.result","result")}} de cette requête renvoie en cas de succès,  un clone structuré de la valeur de l'enregistrement correspondant à la clé ou du premier correspondant à l'intervalle de clé.
+
+ +

Exceptions

+ +
+
TransactionInactiveError
+
Cette {{domxref("DOMException","exception")}} est levé si la {{domxref("IDBTransaction","transaction")}} dont dépend cet {{domxref("IDBObjectStore","accès")}} au magasin d'objet est inactive.
+
DataError
+
Cette {{domxref("DOMException","exception")}} est levé si la clé ou l'{{domxref("IDBKeyRange","intervalle de clé")}} est invalide.
+
InvalidStateError
+
Cette {{domxref("DOMException","exception")}} est levé si le magasin d'objet à été supprimé.
+
+ +

Exemple

+ +

Dans le code suivant , on ouvre une {{domxref("IDBTransaction","transaction")}} sur la {{domxref("IDBDatabase","connexion")}} à la base de données, pour avoir l'{{domxref("IDBObjectStore","accès")}} au magasin d'objet dans lequel on veut retrouver la valeur d'un enregistrement.

+ +

La méthode get() sert à retrouver la valeur de l'enregistrement dont la clé est Walk dog dans magasin d'objets toDoList

+ +
// ouvre la connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+// Gère l'ouverture de la connexion
+DBOpenRequest.onsuccess = function() {
+  note.innerHTML += '<li>Database initialised.</li>';
+
+  // enregistre la connexion dans la variable db
+  db = DBOpenRequest.result;
+
+  // exécute la fonction deleteData()
+  deleteData();
+};
+
+function deleteData() {
+  // ouvre un transaction en mode lecture/écriture pour effectuer la suppression
+  var transaction = db.transaction(["toDoList"], "readwrite");
+
+  // affiche le succès de la transaction.
+  transaction.oncomplete = function() {
+    note.innerHTML += '<li>Transaction effectuée: fin de la modification de la base de données.</li>';
+  };
+
+  // affiche la cause de l’échec de la transaction.
+  transaction.onerror = function() {
+    note.innerHTML += '<li>Échec de la transaction: ' + transaction.error + ' la base de données n\'a pas été modifié</li>';
+  };
+
+  // ouvre un accès au magasin d'objet toDoList
+  var objectStore = transaction.objectStore("toDoList");
+
+  // Retrouve l'enregistrement dont la clé est Walk dog
+   var objectStoreRequest = objectStore.get("Walk dog");
+
+  objectStoreRequest.onsuccess = function() {
+    //Affiche le succès de la requête
+    note.innerHTML += '<li>Enregistrement retrouvé.</li>';
+
+    //affecte la valeur de l'enregistrement à la variable
+    var myRecord = objectStoreRequest.result;
+  };
+};
+
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#widl-IDBObjectStore-get-IDBRequest-any-key', 'get()')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support basique4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/getall/index.html b/files/fr/web/api/idbobjectstore/getall/index.html new file mode 100644 index 0000000000..714ca578d7 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/getall/index.html @@ -0,0 +1,128 @@ +--- +title: IDBObjectStore.getAll() +slug: Web/API/IDBObjectStore/getAll +translation_of: Web/API/IDBObjectStore/getAll +--- +

{{ APIRef("IndexedDB") }}

+ +

La méthode getAll() de l'interface {{domxref("IDBObjectStore")}} fait une {{domxref("IDBRequest","requête")}} qui renvoie un tableau ordonné suivant les clés, des valeurs de tous les enregistrements du magasin d'objet {{domxref("IDBObjectStore","relié")}}. On peut limité le nombre d'enregistrements en les filtrants suivant leurs clés ou en paramétrant le compteur.

+ +

{{ Note("Cette méthode renverras un tableau vide si aucun enregistrement ne correspond. Si la valeur est undefined elle prendra une case du tableau.") }}

+ +

Syntaxe

+ +
var request = objectStore.getAll(query, count);
+ +

Paramètres

+ +
+
query {{optional_inline}}
+
Une clé ou l'{{domxref("IDBKeyRange","intervalle de clé")}} pour filtrer, seule les valeurs des enregistrements correspondant sont renvoyées. Par défaut toutes les valeurs des enregistrements du magasin d'objet sont renvoyées.
+
count {{optional_inline}}
+
Le nombre de valeurs d'enregistrement maximum renvoyées. Un nombre décimal sera tronqué. Zéro annule le compteur et toutes les valeurs sont retournées.
+
+ +

Renvoie

+ +
+
Une {{domxref("IDBRequest","requête")}}
+
La propriété {{domxref("IDBRequest.result","result")}} de cette requête renvoie le tableau des valeurs des enregistrements en cas de succès.
+
+ +

Exceptions

+ +
+
TransactionInactiveError
+
Cette {{domxref("DOMException","exception")}} est levée si la {{domxref("IDBTransaction","transaction")}} est inactive.
+
DataError
+
Cette {{domxref("DOMException","exception")}} est levée si la clé où l'{{domxref("IDBKeyRange","intervalle de clé")}} est invalide.
+
InvalidStateError
+
Cette {{domxref("DOMException","exception")}} est levée si le magasin d'objets a été supprimé.
+
TypeError
+
Cette {{domxref("DOMException","exception")}} est levée si le compteur n'est pas un nombre positif.
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB2', '#dom-idbobjectstore-getall', 'getAll()')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique{{CompatChrome(48.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari MobileChrome for Android
Support basique{{CompatNo}}{{CompatChrome(48.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(48.0)}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/getallkeys/index.html b/files/fr/web/api/idbobjectstore/getallkeys/index.html new file mode 100644 index 0000000000..56a70e3e68 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/getallkeys/index.html @@ -0,0 +1,176 @@ +--- +title: IDBObjectStore.getAllKeys() +slug: Web/API/IDBObjectStore/getAllKeys +tags: + - API + - IDBObjectStore + - IndexedDB + - Méthode + - Référence(2) +translation_of: Web/API/IDBObjectStore/getAllKeys +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode getAllKeys(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet  {{domxref("IDBRequest")}} qui permet de récupérer l'ensemble des clés pour les objets qui correspondent au critère passé en argument (ou les clés de tous les objets du magasin si aucun paramètre n'est fourni).

+ +

Si une valeur est trouvée, un clone structurelle sera créé et fourni comme résultat pour la requête.

+ +

Cette méthode produira le même résultat pour :

+ + + +

Pour différencier ces deux situations, on peut appeler la méthode {{domxref("IDBObjectStore.openCursor","openCursor()")}} avec la même clé. Cette méthode fournit un curseur si l'enregistrement existe et ne fournit aucun curseur s'il n'y a pas d'enregistrement.

+ +

Syntaxe

+ +
var request = objectStore.getAllKeys();
+var request = objectStore.getAllKeys(query);
+var request = objectStore.getAllKeys(query, count);
+ +

Parameters

+ +
+
query {{optional_inline}}
+
Une valeur qui est (ou se résoud) en un intervalle de clés ({{domxref("IDBKeyRange")}}).
+
count {{optional_inline}}
+
Une valeur qui définit le nombre de valeurs à renvoyer si plusieurs correspondent. Cette valeur doit être supérieure à  0 ou inférieure à 232-1, sinon une exception {{jsxref("TypeError")}} sera levée.
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} pour lequel seront déclenchés les différents évènements relatifs à l'opération.

+ +

Exceptions

+ +

Cette méthode peut déclencher une exception {{domxref("DOMException")}} ayant le type suivant :

+ + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
TransactionInactiveErrorLe magasin d'objets ({{domxref("IDBObjectStore")}}) associé à la transaction est inactif.
DataError +

La clé ou l'intervalle de clé fourni contient une clé invalide ou est nul.

+
InvalidStateErrorLe magasin d'objets ({{domxref("IDBObjectStore")}}) a été supprimé ou retiré.
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB 2', '#dom-idbobjectstore-getallkeys', 'getAll()')}}{{Spec2('IndexedDB w')}}Définition initiale.
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support simple{{CompatChrome(48.0)}}{{CompatGeckoDesktop(44)}}{{CompatUnknown}}{{CompatOpera(35)}}{{CompatUnknown}}
Disponible dans les web workers{{CompatChrome(48.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(35)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome pour Android
Support simple{{CompatNo}}{{CompatChrome(48.0)}}{{CompatGeckoMobile(44)}}{{CompatUnknown}}{{CompatOperaMobile(35)}}{{CompatUnknown}}{{CompatChrome(48.0)}}
Disponible dans les web workers{{CompatNo}}{{CompatChrome(48.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOperaMobile(35)}}{{CompatUnknown}}{{CompatChrome(48.0)}}
+
+ +

[1] Cette fonctionnalité était disponible depuis Firefox 27 via la préférence dom.indexedDB.experimental, qui était désactivée par défaut.

+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/getkey/index.html b/files/fr/web/api/idbobjectstore/getkey/index.html new file mode 100644 index 0000000000..9e56d3b408 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/getkey/index.html @@ -0,0 +1,174 @@ +--- +title: IDBObjectStore.getKey() +slug: Web/API/IDBObjectStore/getKey +translation_of: Web/API/IDBObjectStore/getKey +--- +

{{ APIRef("IndexedDB") }}

+ +
+

La méthode getKey() de l'interface {{domxref("IDBObjectStore")}} retourne un objet {{domxref("IDBRequest")}}, et, dans un thread séparé, retourne la clé sélectionnée par la requête spécifiée. Cela permet de retrouver un enregistrement spécifique depuis un espace de stockage déterminé.

+
+ +

Si la clé a bien été retrouvée, alors un clone structuré (une copie conforme) sera créée et servira comme résultat à l'objet de requête.

+ +

{{AvailableInWorkers}}

+ +

Syntax

+ +
var request = objectStore.getKey(key);
+ +

Parameters

+ +
+
key
+
La clé ou l'intervale de clé qui identifie l'enregistrement à retrouver.
+
+ +

Return Value

+ +

An {{domxref("IDBRequest")}} object on which subsequent events related to this operation are fired.

+ +

Exceptions

+ +

This method may raise a {{domxref("DOMException")}} of one of the following types:

+ + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
TransactionInactiveErrorThis {{domxref("IDBObjectStore")}}'s transaction is inactive.
DataError +

The key or key range provided contains an invalid key.

+
InvalidStateErrorThe {{domxref("IDBObjectStore")}} has been deleted or removed.
+  
+ +

Example

+ +
let openRequest = indexedDB.open("telemetry");
+openRequest.onsuccess = (event) => {
+  let db = event.target.result;
+  let store = db.transaction("netlogs").objectStore("netlogs");
+
+  let today = new Date();
+  let yesterday = new Date(today);
+  yesterday.setDate(today.getDate() - 1);
+  let request = store.getKey(IDBKeyRange(yesterday, today));
+  request.onsuccess = (event) => {
+    let when = event.target.result;
+    alert("The 1st activity in last 24 hours was occurred at " + when);
+  };
+};
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('IndexedDB 2', '#dom-idbobjectstore-getkey', 'getKey()')}}{{Spec2('IndexedDB 2')}}Initial definition
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(58)}}{{CompatGeckoDesktop("51.0")}}{{CompatUnknown}}{{CompatOpera(45)}}{{CompatUnknown}}
Available in workers{{CompatChrome(58)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(45)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatChrome(58)}}{{CompatChrome(58)}}{{CompatGeckoMobile("51.0")}}{{CompatUnknown}}{{CompatOperaMobile(45)}}{{CompatUnknown}}
Available in workers{{CompatChrome(58)}}{{CompatChrome(58)}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatOperaMobile(45)}}{{CompatUnknown}}
+
+ +

See also

+ + diff --git a/files/fr/web/api/idbobjectstore/index.html b/files/fr/web/api/idbobjectstore/index.html new file mode 100644 index 0000000000..b2c219650e --- /dev/null +++ b/files/fr/web/api/idbobjectstore/index.html @@ -0,0 +1,238 @@ +--- +title: IDBObjectStore +slug: Web/API/IDBObjectStore +translation_of: Web/API/IDBObjectStore +--- +

{{APIRef("IndexedDB")}}

+ +

L'interface IDBObjectStore de l'{{domxref("IndexedDB_API","API IndexedDB")}} est un accès aux magasins d'objet de la base de données.

+ +

Le magasin d'objet emmagasine des enregistrements. Chaque enregistrement est constitué d'un couple clé/valeur. Chaque valeurs est indexée sur sa clé. Les clés sont triées pour former l'index primaire du magasin. Ce qui permet un accès rapide et ordonnée aux valeurs.

+ +

Le magasin d'objet peut en plus de l'index primaire avoir des index qui ordonnent les enregistrements sur d'autres clés. Ces index se mettent automatiquement à jour dans la plupart des cas et permettent de mettre des contraintes d’unicités pour d'autres clés que la clé primaire du magasin d'objet.

+ +

{{AvailableInWorkers}}

+ +

Méthodes

+ +
+
{{domxref("IDBObjectStore.add()")}}
+
Une {{domxref("IDBRequest","requête")}} pour ajouter un enregistrement au magasin d'objet relié, un clone structuré de la valeur passé en paramètre et sa clé .
+
{{domxref("IDBObjectStore.clear()")}}
+
Une {{domxref("IDBRequest","requête")}} pour vider le magasin d'objet relié.
+
{{domxref("IDBObjectStore.delete()")}}
+
Une {{domxref("IDBRequest","requête")}} de suppression d'enregistrement(s) du magasin d'objet relié.
+
{{domxref("IDBObjectStore.get()")}}
+
Une {{domxref("IDBRequest","requête")}} pour renvoyer la valeur d'un enregistrement du magasin d'objet relié.
+
{{domxref("IDBObjectStore.getAll()")}}
+
Une {{domxref("IDBRequest","requête")}} qui renvoie un tableau ordonné suivant les clés, des valeurs de tous les enregistrements du magasin d'objet relié. On peut limité le nombre d'enregistrements en les filtrants suivant leurs clés ou en paramétrant le compteur.
+
{{domxref("IDBObjectStore.getAllKeys()")}}
+
Une {{domxref("IDBRequest","requête")}} qui renvoie la liste de toutes les clés des enregistrements du magasin d'objet. On peut limité le nombre d'enregistrements en les filtrants suivant leurs clés ou en paramétrant le compteur.
+
{{domxref("IDBObjectStore.createIndex()")}}
+
Met en place sur le magasin d'objet relié, un nouvel index et en renvoie l'{{domxref("IDBIndex","accès")}}.
+
{{domxref("IDBObjectStore.deleteIndex()")}}
+
Supprime l'index dont le nom est passé en paramètre, du magasin d'objet relié.
+
{{domxref("IDBObjectStore.index()")}}
+
L'{{domxref("IDBIndex","accès")}} à l'index dont le nom est passé en paramètre du magasin d'objet relié.
+
{{domxref("IDBObjectStore.put()")}}
+
Une {{domxref("IDBRequest","requête")}} pour ajouter ou mettre à jour un enregistrement du magasin d'objet relié, un clone structuré de la valeur passée en paramètre et sa clé.
+
{{domxref("IDBObjectStore.openCursor()")}}
+
Une {{domxref("IDBRequest","requête")}} récursive suivant un {{domxref("IDBCursorWithValue","curseur avec valeur")}} qui itère le magasin d'objet relié.
+
{{domxref("IDBObjectStore.openKeyCursor()")}}
+
Une {{domxref("IDBRequest","requête")}} récursive suivant un {{domxref("IDBCursor","curseur")}} qui itère le magasin d'objet relié.
+
{{domxref("IDBObjectStore.count()")}}
+
Une {{domxref("IDBRequest","requête")}} au magasin d'objet relié. La requête compte le nombre d'enregistrements dans ce magasin d'objet ou sur l'{{domxref("IDBKeyRange","intervalle de clé")}} passé en paramètre.
+
+ +

Propriétés

+ +
+
{{domxref("IDBObjectStore.indexNames")}} {{readonlyInline}}
+
La liste des noms d'index du magasin d'objet relié.
+
{{domxref("IDBObjectStore.keyPath")}} {{readonlyInline}}
+
Le nom de la clé du magasin d'objets relié.
+
{{domxref("IDBObjectStore.name")}} {{readonlyInline}}
+
Le nom du magasin d'objet relié.
+
{{domxref("IDBObjectStore.transaction")}} {{readonlyInline}}
+
La {{domxref("IDBTransaction","transaction")}} à laquelle l'accès du magasin d'objet appartient.
+
{{domxref("IDBObjectStore.autoIncrement")}} {{readonlyInline}}
+
La position du drapeau d’incrémentation automatique du magasin d'objet relié.
+
+ +
+
+ +

Exemple

+ +

Cet exemple montre différents usages de l'accès au magasin d'objet. On met à jour la structure de donnée avec {{domxref("IDBObjectStore.createIndex")}} dans un gestionnaire d'événement onupgradeneeded. On ajoute un nouvel enregistrement avec {{domxref("IDBObjectStore.add")}}.

+ +
// connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+// gère le succès de la connexion
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>Connexion ouverte.</li>';
+
+  //affect la connexion à la variable db.
+  db = DBOpenRequest.result;
+};
+
+// Ce gestionnaire d'événement s'active quand on à besoin d'une nouvelle version de la base de donnée.
+// Si la base n'existais pas avant ou
+// si on ouvre une nouvelle version avec window.indexedDB.open.
+DBOpenRequest.onupgradeneeded = function(event) {
+  var db = event.target.result;
+
+  db.onerror = function(event) {
+    note.innerHTML += '<li>Erreur de chargement de la base.</li>';
+  };
+
+  // Ajoute un magasin d'objets à la base de données
+  var objectStore = db.createObjectStore("toDoList", { keyPath: "taskTitle" });
+
+  // défini des index sur ce magasin
+
+  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 += '<li>Le magasin d\'objet est ajouté.</li>';
+};
+
+// Un nouvel enregistrement à ajouter
+var newItem = [
+ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: 'December', year: 2013, notified: "no" }
+];
+
+// ouvre une transaction en lecture/écriture sur la connexion, prête à ajouter l'enregistrement.
+var transaction = db.transaction(["toDoList"], "readwrite");
+
+// affiche le succès de la transaction
+transaction.oncomplete = function(event) {
+  note.innerHTML += '<li>La transaction à été effectuée.</li>';
+};
+
+transaction.onerror = function(event) {
+  note.innerHTML += '<li>La transaction n\'as pue aboutir.</li>';
+};
+
+// Un accès à toDoList pour la transaction
+var objectStore = transaction.objectStore("toDoList");
+// Ajoute l'enregistrement au magasin d'objet
+var objectStoreRequest = objectStore.add(newItem[0]);
+
+//l'enregistrement c'est bien passé.
+objectStoreRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>L\'enregistrement à été ajouté au magasin d\'objet.</li>';
+}
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#idl-def-IDBObjectStore', 'IDBObjectStore')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponibke dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari MobileChrome for Android
Support basique4.4{{CompatVersionUnknown}}{{CompatGeckoMobile("22.0")}}1.0.110228{{CompatVersionUnknown}}
Disponibke dans workers{{CompatNo}}{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/index/index.html b/files/fr/web/api/idbobjectstore/index/index.html new file mode 100644 index 0000000000..d4f2db4edb --- /dev/null +++ b/files/fr/web/api/idbobjectstore/index/index.html @@ -0,0 +1,200 @@ +--- +title: IDBObjectStore.index() +slug: Web/API/IDBObjectStore/index +tags: + - API + - IDBObjectStore + - IndexedDB + - Méthode + - Reference +translation_of: Web/API/IDBObjectStore/index +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode index(), rattachée à l'interface {{domxref("IDBObjectStore")}}, permet d'ouvrir un index sur le magasin d'objet courant pour, par exemple, renvoyer une liste d'enregistrements triés par cet index grâce à un curseur.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
objectStore.index(nomIndex);
+ +

Paramètres

+ +
+
nomIndex
+
Le nom de l'index qu'on souhaite ouvrir.
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBIndex")}} qui permet d'accéder à l'index.

+ +

Exceptions

+ +

Cette méthode peut déclencher une exception {{domxref("DOMException")}} ayant l'un des types suivants :

+ + + + + + + + + + + + + + + + + + +
ExceptionDescription
InvalidStateErrorL'objet correspondant au magasin d'objet a été supprimé ou la transaction a été clôturée.
NotFoundErrorIl n'existe pas d'index pour ce nom dans la base de données (la recherche est sensible à la casse).
+ +

Exemples

+ +

Dans l'exemple qui suit, on ouvre une transaction sur un magasin d'objet et on accède à l'index lName de la base de données. Ensuite, on ouvre un curseur sur l'index grâce à la méthode {{domxref("IDBIndex.openCursor")}} — cela fonctionne de la même façon que d'ouvrir un curseur à même le magasin d'objet grâce à {{domxref("IDBObjectStore.openCursor")}} sauf que, cette fois, les enregistrements sont renvoyés triés selon l'index et non selon la clé primaire.

+ +

Enfin, on parcourt chaque enregistrement pour l'ajouter dans un tableau HTML.

+ +
function displayDataByIndex() {
+  tableEntry.innerHTML = '';
+  var transaction = db.transaction(['contactsList'], 'readonly');
+  var objectStore = transaction.objectStore('contactsList');
+
+  var myIndex = objectStore.index('lName');
+  myIndex.openCursor().onsuccess = function(event) {
+    var cursor = event.target.result;
+    if(cursor) {
+      var tableRow = document.createElement('tr');
+      tableRow.innerHTML =   '<td>' + cursor.value.id + '</td>'
+                           + '<td>' + cursor.value.lName + '</td>'
+                           + '<td>' + cursor.value.fName + '</td>'
+                           + '<td>' + cursor.value.jTitle + '</td>'
+                           + '<td>' + cursor.value.company + '</td>'
+                           + '<td>' + cursor.value.eMail + '</td>'
+                           + '<td>' + cursor.value.phone + '</td>'
+                           + '<td>' + cursor.value.age + '</td>';
+      tableEntry.appendChild(tableRow);
+
+      cursor.continue();
+    } else {
+      console.log('Éléments affichés.');
+    }
+  };
+};
+ +
+

Note : pour un exemple fonctionnel complet, voir notre exemple sur GitHub (la démonstration associée).

+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-index-IDBIndex-DOMString-name', 'index()')}}{{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")}}
10, partial157.1
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome pour Android
Support simple4.4{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("22.0")}}10228{{CompatVersionUnknown}}
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/indexnames/index.html b/files/fr/web/api/idbobjectstore/indexnames/index.html new file mode 100644 index 0000000000..c3cd0288e6 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/indexnames/index.html @@ -0,0 +1,188 @@ +--- +title: IDBObjectStore.indexNames +slug: Web/API/IDBObjectStore/indexNames +tags: + - API + - IDBObjectStore + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBObjectStore/indexNames +--- +
{{APIRef("IndexedDB")}}
+ +

La propriété indexNames, rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie la liste des noms des index pour les objets du magasin d'objets courant.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var myindexNames = objectStore.indexNames;
+ +

Valeur

+ +

Une liste {{domxref("DOMStringList")}}.

+ +

Exemples

+ +

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 add(). Une fois l'objet créé, on affiche objectStore.indexNames en sortie de la console. Pour un exemple complet et fonctionnel, vous pouvez utiliser notre application To-do Notifications (tester la démo).

+ +
// On commence par ouvrir la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>Base de données initialisée.</li>';
+
+  // On enregistre le résultat de l'ouverture
+  // dans la variable db afin de l'utiliser
+  // ensuite
+  db = this.result;
+
+  // On exécute 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: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", 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 indexNames dans la console
+  var objectStore = transaction.objectStore("toDoList");
+  console.log(objectStore.indexNames);
+
+  // 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>';
+  };
+};
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-indexNames', 'indexNames')}}{{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 web workers{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome pour Android
Support simple4.4{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("22.0")}}10228{{CompatVersionUnknown}}
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + 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 +--- +
{{APIRef("IndexedDB")}}
+ +

La propriété keyPath de l'interface {{domxref("IDBObjectStore")}} renvoie le chemin de la clé de ce magasin d'objet.

+ +

Si cette propriété vaut null l'application doit fournir une clé pour chaque opération de modification.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var mykeyPath = objectStore.keyPath;
+ +

Valeur

+ +

N'importe quel type de valeur.

+ +

Exemple

+ +

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 add(). Une fois l'objet créé, on affiche objectStore.keyPath en sortie de la console. Pour un exemple complet et fonctionnel, vous pouvez utiliser notre application To-do Notifications (tester la démo).

+ +
// 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>';
+  };
+};
+ +

Spécifications

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

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support
+ simple
23{{property_prefix("webkit")}}
+ 24
{{CompatVersionUnknown}}10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, partiel157.1
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari MobileChrome pour Android
Support
+ Simple
4.4{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("22.0")}}1.0.110228{{CompatVersionUnknown}}
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/name/index.html b/files/fr/web/api/idbobjectstore/name/index.html new file mode 100644 index 0000000000..4fb4c3fbb7 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/name/index.html @@ -0,0 +1,216 @@ +--- +title: IDBObjectStore.name +slug: Web/API/IDBObjectStore/name +tags: + - API + - IDBObjectStore + - IndexedDB + - Propriété + - Reference +translation_of: Web/API/IDBObjectStore/name +--- +
{{APIRef("IndexedDB")}}
+ +

La propriété name, rattachée à l'interface {{domxref("IDBObjectStore")}}, indique le nom du magasin d'objets courant.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var nomDuMagasin = IDBObjectStore.name;
+IDBObjectStore.name = nouveauNom;
+ +

Valeur

+ +

Une chaîne de caractères qui contient le nom du magasin d'objet.

+ +

Exceptions

+ +

Plusieurs exceptions peuvent être levées lorsqu'on tente de modifier le nom d'un magasin d'objets.

+ +
+
InvalidStateError
+
Le magasin d'objets a été supprimé ou la transaction courante n'est pas une transaction de mise à jour : il est uniquemnet possible d'opérer un renommage lorsque le mode de la transaction est "versionchange".
+
TransactionInactiveError
+
La transaction actuelle est inactive.
+
ConstraintError
+
Un magasin d'objets utilise déjà le nom qu'on souhaite employer.
+
+ +

Exemples

+ +

Dans le fragment de code qui suit, on ouvre une transaction en lecture/écriture pour la base de données et on ajoute des données au magasin d'objets grâce à la méthode add(). Une fois que le magasin d'objets a été créé, on inscrit la valeur de objectStore.name dans la console. Pour un exemple complet, voir notre application To-do Notifications (cf. également la démonstration live).

+ +
// On ouvre la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>Initialisation de la base de données</li>';
+
+  // On enregistre le résultat de l'ouverture dans la variable
+  // db afin de l'utiliser ensuite.
+  db = DBOpenRequest.result;
+
+  // On exécute la fonction addData() afin d'ajouter des
+  // données à la base de données
+  addData();
+};
+
+function addData() {
+  // On crée un nouvel objet pour l'insérer dans la base
+  var newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];
+
+  // On ouvre une transaction en lecture/écriture
+  // afin d'ajouter les données
+  var transaction = db.transaction(["toDoList"], "readwrite");
+
+  // On gère le cas où la transaction est effectuée correctement
+  transaction.oncomplete = function(event) {
+    note.innerHTML += '<li>Transaction terminée : modification appliquée.</li>';
+  };
+
+  transaction.onerror = function(event) {
+    note.innerHTML += '<li>Transaction non ouverte. Les doublons sont interdits.</li>';
+  };
+
+  // On crée un magasin d'objets pour la transaction
+  var objectStore = transaction.objectStore("toDoList");
+  console.log(objectStore.name);
+
+  // On ajoute l'objet newItem dans le magasin d'objet
+  var objectStoreRequest = objectStore.add(newItem[0]);
+
+  objectStoreRequest.onsuccess = function(event) {
+    // On rapporte la réussite de l'ajout de l'objet en base
+    note.innerHTML += '<li>Nouvel élément ajouté dans la base de données.</li>';
+  };
+};
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-name', 'name')}}{{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)}}
10157.1
Disponible dans les web workers{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoDesktop(37)}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
Renommage possible via le mutateur name{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoDesktop(49)}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome pour Android
Support simple{{CompatNo}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile(22)}}10228{{CompatVersionUnknown}}
Disponible dans les web workers{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile(37)}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
Renommage possible via le mutateur name{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile(49)}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/opencursor/index.html b/files/fr/web/api/idbobjectstore/opencursor/index.html new file mode 100644 index 0000000000..6109ea0611 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/opencursor/index.html @@ -0,0 +1,193 @@ +--- +title: IDBObjectStore.openCursor() +slug: Web/API/IDBObjectStore/openCursor +tags: + - API + - IDBObjectStore + - IndexedDB + - Méthode + - Reference +translation_of: Web/API/IDBObjectStore/openCursor +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode openCursor(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet {{domxref("IDBRequest")}} et, dans un thread séparé, renvoie un nouvel objet {{domxref("IDBCursorWithValue")}} qu'on peut utiliser pour parcourir un magasin d'objets avec un curseur.

+ +

Afin de déterminer si l'opération s'est déroulée correctement, on pourra surveiller l'évènement success.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var requete = ObjectStore.openCursor(optionalKeyRange, optionalDirection);
+ +

Paramètres

+ +
+
range {{optional_inline}}
+
Une clé ou un intervalle de clés ({{domxref("IDBKeyRange")}}) qu'on souhaite parcourir. Si une seule clé est passée en argument, l'intervalle utilisé pour le curseur sera restreint à cette seule clé. Si aucune valeur n'est passée pour cet argument, l'intervalle utilisé pour le curseur englobera tous les enregistrements du magasin d'objets.
+
direction {{optional_inline}}
+
Un objet {{domxref("IDBCursorDirection")}} qui indique la direction de parcours du curseur. La valeur par défaut est "next".
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} sur lequel seront déclenchés les évènements relatifs à l'opération.

+ +

Exceptions

+ +

Cette méthode peut déclencher une exception {{domxref("DOMException")}} ayant l'un des types suivants :

+ + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
InvalidStateErrorL'objet {{domxref("IDBObjectStore")}} ou l'objet {{domxref("IDBIndex")}} a été supprimé.
TransactionInactiveErrorLa transaction rattachée au magasin d'objets ({{domxref("IDBObjectStore")}}) est inactive.
DataErrorLa clé ou l'intervalle de clés indiqué est invalide.
+ +

Exemples

+ +

Dans ce fragment de code, on crée une transaction, on ouvre le magasin d'objets souhaité puis on place un curseur pour parcourir tous les enregistrements du magasin d'objets :

+ +
var transaction = db.transaction("name", "readonly");
+var objectStore = transaction.objectStore("name");
+var request = objectStore.openCursor();
+request.onsuccess = function(event) {
+  var cursor = event.target.result;
+  if(cursor) {
+    // cursor.value contient l'enregistrement courant
+    // pendant le parcours, on peut éventuellement le manipuler ici
+    cursor.continue();
+  } else {
+    // il n'y a plus de résultats
+  }
+};
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBIndex-openCursor-IDBRequest-any-range-IDBCursorDirection-direction', 'openCursor')}}{{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")}}
10, partial157.1
Disponible dans les web 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 web workers{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/openkeycursor/index.html b/files/fr/web/api/idbobjectstore/openkeycursor/index.html new file mode 100644 index 0000000000..d5d23efe42 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/openkeycursor/index.html @@ -0,0 +1,181 @@ +--- +title: IDBObjectStore.openKeyCursor() +slug: Web/API/IDBObjectStore/openKeyCursor +tags: + - API + - IDBObjectStore + - IndexedDB + - Méthode + - Reference +translation_of: Web/API/IDBObjectStore/openKeyCursor +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode openKeyCursor(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet {{domxref("IDBRequest")}} dont le résultat sera un curseur ({{domxref("IDBCursor")}}) qui pourra être utilisé afin de parcourir les enregistrements correspondants. Cette méthode est utilisée afin de parcourir les clés d'un magasin d'objets grâce à un curseur.

+ +

Afin de déterminer si le curseur a bien été ajouté, on pourra écouter l'évènement success sur le résultat de la méthode.

+ +

Syntaxe

+ +
var requete = objectStore.openKeyCursor(optionalKeyRange, optionalDirection);
+ +

Paramètres

+ +
+
optionalKeyRange
+
L'intervalle de clés qu'on souhaite parcourir. Si une seule clé est fournie, l'intervalle constitué ne contiendra que cette clé. Si aucune valeur n'est passée en argument, le curseur produit parcourera tous les enregistrements du magasin d'objets.
+
optionalDirection
+
Un objet {{domxref("IDBCursorDirection")}} qui indique la direction dans laquelle le curseur doit parcourir les évènements. La valeur par défaut est "next".
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} sur lequel seront déclenchés les différents évènements relatifs à cette opération.

+ +

Exceptions

+ +

Cette méthode peut déclencher une exception {{domxref("DOMException")}} ayant l'un des types suivants :

+ + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
InvalidStateErrorLe magasin d'objets ({{domxref("IDBObjectStore")}} ou l'index ({{domxref("IDBIndex")}}) a été supprimé.
TransactionInactiveErrorLa transaction associée au magasin d'objet ({{domxref("IDBObjectStore")}}) est inactive.
DataErrorLa clé ou l'intervalle de clés indiqué est invalide.
+ +

Exemples

+ +

Dans le fragment de code suivant, on crée une transaction, on l'utilise sur un magasin d'objets donné puis on utilise le curseur pour parcourir tous les enregistrements du magasin d'objets :

+ +
var transaction = db.transaction("name", "readonly");
+var objectStore = transaction.objectStore("name");
+var request = objectStore.openKeyCursor();
+request.onsuccess = function(event) {
+  var cursor = event.target.result;
+  if(cursor) {
+    // cursor.key contient la clé de l'enregistrement courant
+    // à la différence de openCursor, il n'y a pas de cursor.value
+    cursor.continue();
+  } else {
+    // Il n'y a plus d'autres résultats
+  }
+};
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB2', '#dom-idbobjectstore-openkeycursor', 'openKeyCursor')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support simple{{CompatChrome(48.0)}}{{CompatGeckoDesktop("44.0")}} [1]10, partial157.1
Disponible dans les web workers{{CompatChrome(48.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(35)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome pour Android
Support simple4.4{{CompatChrome(48.0)}}{{CompatGeckoMobile("44.0")}} [1]1022{{CompatNo}}{{CompatChrome(48.0)}}
Disponible dans les web workers{{CompatNo}}{{CompatChrome(48.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOperaMobile(35)}}{{CompatUnknown}}{{CompatChrome(48.0)}}
+
+ +

[1] Cette fonctionnalité était disponible depuis Firefox 27 via une préférence : dom.indexedDB.experimental qui était désactivée par défaut.

+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/put/index.html b/files/fr/web/api/idbobjectstore/put/index.html new file mode 100644 index 0000000000..4122bd300f --- /dev/null +++ b/files/fr/web/api/idbobjectstore/put/index.html @@ -0,0 +1,229 @@ +--- +title: IDBObjectStore.put() +slug: Web/API/IDBObjectStore/put +tags: + - API + - IDBObjectStore + - IndexedDB + - Méthode + - Reference +translation_of: Web/API/IDBObjectStore/put +--- +
{{APIRef("IndexedDB")}}
+ +

La méthode put(), rattachée à l'interface {{domxref("IDBObjectStore")}}, renvoie un objet {{domxref("IDBRequest")}} et, dans un autre thread, crée un clone structuré de la valeur puis enregistre ce clone dans le magasin d'objet. Cette méthode permet ainsi d'ajouter de nouveaux enregistrements ou de mettre à jour des enregistrements existants dans un magasin d'objet lorsque la transaction est en mode readwrite (lecture-écriture)

+ +

Si l'enregistrement est stocké avec succès, un évènement de succès sera déclenché sur la requête renvoyée par la méthode. La propriété result de cette requête contiendra la clé de l'enregistrement créé ou mis à jour. La propriété transaction de cette requête sera la transaction dans laquelle le magasin d'objet est ouvert.

+ +

La méthode put() permet d'ajouter ou de mettre à jour. Si on souhaite uniquement insérer, on utilisera plutôt {{domxref("IDBObjectStore.add")}}.

+ +

{{AvailableInWorkers}}

+ +

Syntaxe

+ +
var request = objectStore.put(monElement);
+var request = objectStore.put(monElement, cleOptionnelle);
+ +

Paramètres

+ +
+
monElement
+
La valeur qu'on souhaite enregistrer.
+
cleOptionnelle {{optional_inline}}
+
La clé qu'on souhaite utiliser pour identifier l'enregistrement. Si cet argument est absent, la valeur par défaut sera {{jsxref("null")}}.
+
+ +

Valeur de retour

+ +

Un objet {{domxref("IDBRequest")}} qui recevra les évènements qui seront déclenchés suite à cette opération.

+ +

Exceptions

+ +

Cette méthode peut lever une de ces exceptions {{domxref("DOMException")}} :

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ExceptionDescription
ReadOnlyErrorLa transaction associée à l'opération est uniquement dans un mode de lecture seule.
TransactionInactiveErrorLa transaction rattachée à l'objet {{domxref("IDBObjectStore")}} est inactive.
DataError +

L'une de ces conditions est vérifiée :

+ +
    +
  • Le magasin d'objet utilise des clés en ligne (in-line keys) ou dispose d'un générateur de clés et le paramètre pour la clé a été utilisé.
  • +
  • Le magasin d'objet utilise des clés en ligne (in-line keys), ne  dispose pas d'un générateur de clés et le paramètre pour la clé n'a pas été utilisé.
  • +
  • Le magasin d'objet utilise des clés en ligne (in-line keys), ne  dispose pas d'un générateur de clés et le chemin de clé du magasin d'objet ne déclenche pas une clé valide.
  • +
  • Le paramètre pour la clé a été fourni mais la valeur n'est pas une clé valide.
  • +
+
InvalidStateErrorL'objet {{domxref("IDBObjectStore")}} a été supprimé ou déplacé.
DataCloneErrorLes données à enregistrer n'ont pas pu être clonées par l'algorithme interne.
+ +

Exemples

+ +

Dans l'exemple suivant, on effectue une requête pour obtenir l'enregistrement correspondant à un titre donné. Lorsque cette requête est réussie, on récupère l'enregistrement via la fonction onsuccess. Ensuite, on met à jour une des propriétés de l'enregistrement et on enregistre la valeur mise à jour dans le magasin d'objet avec une autre requête et put().

+ +
var title = "Walk dog";
+
+// On ouvre une transaction
+var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList');
+
+// On obtient la liste to-do dont le titre correspond
+var objectStoreTitleRequest = objectStore.get(title);
+
+objectStoreTitleRequest.onsuccess = function() {
+  // On récupère les données de l'objet associé
+  // à l'enregistrement
+  var data = objectStoreTitleRequest.result;
+
+  // On met à jour la valeur de notified avec "yes"
+  data.notified = "yes";
+
+  // On crée une autre requête pour appliquer cette
+  // mise à jour en base de données
+  var updateTitleRequest = objectStore.put(data);
+
+  // On imprime la transaction à l'origine
+  // de la requête
+  console.log("La transaction originelle est " + updateTitleRequest.transaction);
+
+  // Lorsque cette nouvelle requête a réussi. On affiche
+  // les données grâce à la fonction displayData()
+  updateTitleRequest.onsuccess = function() {
+    displayData();
+  };
+};
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('IndexedDB', '#widl-IDBObjectStore-put-IDBRequest-any-value-any-key', 'put()')}}{{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")}}
10, partial157.1
Disponible dans les web 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 web workers{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
+
+ +

Voir aussi

+ + diff --git a/files/fr/web/api/idbobjectstore/transaction/index.html b/files/fr/web/api/idbobjectstore/transaction/index.html new file mode 100644 index 0000000000..013af1c552 --- /dev/null +++ b/files/fr/web/api/idbobjectstore/transaction/index.html @@ -0,0 +1,171 @@ +--- +title: IDBObjectStore.transaction +slug: Web/API/IDBObjectStore/transaction +translation_of: Web/API/IDBObjectStore/transaction +--- +

{{ APIRef("IndexedDB") }}

+ +
+

La propriété transaction de l'interface {{domxref("IDBObjectStore")}} renvoie la {{domxref("IDBTransaction","transaction")}} à laquelle l'{{domxref("IDBObjectStore","accès")}} du magasin d'objet appartient.

+ +

{{AvailableInWorkers}}

+
+ +

Syntaxe

+ +
var myTransaction = objectStore.transaction;
+ +

Valeur

+ +

Une {{domxref("IDBTransaction","transaction")}}.

+ +

Exemple

+ +

Dans le code suivant, on ouvre une {{domxref("IDBDatabase","connexion")}} à la base de donnée. Sur cette connexion on démarre une {{domxref("IDBTransaction","transaction")}} en lecture/écriture pour avoir un {{domxref("IDBObjectStore","accès")}} au magasin d'objet "toDoList" dans lequel on {{domxref("IDBObjectStore.add","ajoute")}} un enregistrement.

+ +

La propriété transaction affiche la transaction à laquelle l'accès du magasin d'objet appartient.

+ +
//Connexion à la base de données
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+DBOpenRequest.onsuccess = function(event) {
+	note.innerHTML += '<li>Connexion établie.</li>';
+
+	//Affecte la connexion à la variable db.
+	db = DBOpenRequest.result;
+
+	// Exécutez la fonction addData () pour ajouter un enregistrement au magasin d'objet
+	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" } ];
+
+	// ouvre une transaction de lecture / écriture  prête au 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>L\'erreur: "' + transaction.error +'" c\'est produite échec de la transaction.</li>';
+	};
+
+	// ouvre l'accès au un magasin "toDoList" de la transaction
+	var objectStore = transaction.objectStore("toDoList");
+
+//->Affiche la transaction de l'accès du magasin d'objet
+    console.log(objectStore.transaction);
+
+	// Ajoute un enregistrement
+	var objectStoreRequest = objectStore.add(newItem[0]);
+	objectStoreRequest.onsuccess = function(event) {
+		// signale l'ajout de l'enregistrement
+		note.innerHTML += '<li>Enregistrement ajouté.</li>';
+	};
+ };
+ 
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécification

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#widl-IDBObjectStore-transaction', 'transaction')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support basique4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

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