Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove/drop the table and database from IndexedDB #8

Closed
imprathamesh opened this issue Jan 4, 2022 · 1 comment
Closed

How to remove/drop the table and database from IndexedDB #8

imprathamesh opened this issue Jan 4, 2022 · 1 comment

Comments

@imprathamesh
Copy link

No description provided.

@Jinjinov
Copy link
Owner

Jinjinov commented Jan 4, 2022

Clear table:

using (var db = await this.DbFactory.Create<ExampleDb>())
{
  db.People.Clear();
  await db.SaveChanges();
}

To drop a table or delete the database you will have to access the TG.Blazor.IndexedDB.IndexedDBManager from the third party library https://github.com/wtulloch/Blazor.IndexedDB that this library is using:

When you inherit from IndexedDb, you also inherit protected IndexedDBManager connector;

public class ExampleDb : IndexedDb
{
  public ExampleDb(IJSRuntime jSRuntime, string name, int version) : base(jSRuntime, name, version) { }
  public IndexedSet<Person> People { get; set; }
  
  public async Task DoSomething()
  {
    await this.connector.ClearStore(string storeName); // connector is IndexedDBManager
    await this.connector.DeleteDb(string dbName);
  }
}

To see what you can do with IndexedDBManager take a look at the third party library:
https://github.com/wtulloch/Blazor.IndexedDB/blob/master/TG.Blazor.IndexedDb/IndexedDB/IndexedDBManager.cs

TG.Blazor.IndexedDb is not my library, I am only using it.

@Jinjinov Jinjinov changed the title How to Remove/drop the table and database from INdexeddb How to remove/drop the table and database from IndexedDB Jan 4, 2022
@Jinjinov Jinjinov pinned this issue Jan 4, 2022
@Jinjinov Jinjinov closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants