简体   繁体   English

如何删除 indexedDB 中的对象存储?

[英]How to delete an object store in indexedDB?

I can't find in documentation information about deleting object store, not object on store and not a database, namely deleting the object store.我在文档中找不到有关删除对象存储的文档信息,而不是存储对象而不是数据库,即删除对象存储。 Is there such a possibility?有这种可能吗?

Documentation: https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/clear文档: https ://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/clear

First, you need to create a transaction to IndexedDB instance specifying the access options to the table.首先,您需要为 IndexedDB 实例创建一个事务,指定对表的访问选项。 Since you want to manipulate, set: "readwrite" option for mode: IDBTransactionMode , then the name of the table you want to drop, in my case its called "photos_os" .由于您要操作,请设置:模式的“readwrite”选项mode: IDBTransactionMode ,然后是您要删除的表的名称,在我的情况下它称为“photos_os”

function dropTable() {
    const objectStore = db.transaction('photos_os', "readwrite").objectStore('photos_os');
    const objectStoreRequest = objectStore.clear();

    objectStoreRequest.onsuccess = function(event) {
        console.log('Erase of database completed.');
    };
}

Here is documentation on how to delete an object store:以下是有关如何删除对象存储的文档:

https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM