How to remove store from ydn.db?

198 Views Asked by At

I am using ydn.db from local storage.

Which function can be used to remove the store using YDB.DB library ?
The stores i have added is as follows

var schema = {
  stores: [{
      name:'consignments',
    keyPath:"timeStamp"
    }];

var db = new ydn.db.Storage('localhost', schema);

I wish to check whether the store exist in localstorage and if it exists delete the store and if not exist add the store.

2

There are 2 best solutions below

0
mca On

I use the deleteDatabase function like this:

indexedDB.deleteDatabase(storage_name);

see the doc here: https://dev.yathit.com/api/ydn/db/index.html

0
Kyaw Tun On

If store exist or not can be known only after opening the database. If a schema does not a store name, but exit in the connected database, the existing store will be removed.

To delete the database

var db = new ydn.db.Storage('localhost', schema);

To delete above the database,

ydn.db.deleteDatabase(db.getName(), db.getType());

If type of database is not known

ydn.db.deleteDatabase('localhost');