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/count/index.html | 183 +++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 files/fr/web/api/idbobjectstore/count/index.html (limited to 'files/fr/web/api/idbobjectstore/count') 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

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