Question

I researched a lot on the concepts behind IndexedDB, but I'm having difficulty understanding how it applies to my application.

I have a ton of keywords that I want to store in an IndexedDB. Some of the keywords are for cars and others are for fruits. Now my application uses regex to match the keywords and return whether the string is about cars and/or fruits. I'm guessing I would have to use an expression containing car keywords and another expression containing fruit keywords (which I extract from the IndexedDB).

My question is how exactly should I structure my IndexedDB?

MyApp (db) > Keywords (table) > { keyword: Honda (value), category: Cars }
MyApp (db) > Keywords (table) > { keyword: Apple (value), category: Fruits }

And then:

objectStore.createIndex('category');

And then search by the keyword value whether it matches Cars or Fruits to return a list of keywords pertaining to that subject.

Could someone explain to me if this is the correct way to structure my database or should I build a separate table for Cars and Fruits.

Was it helpful?

Solution

If you already have the keywords in a list and you need to query the database to check what category is that value, then I would suggest you to index your database on the keyword field and that way you'll have the best performance.

objectStore.createIndex('keyword');

If you use the category index you'll need to iterate through all items with a cursor and that's slower since multiple objects belong to same category.

Also if your keywords list can contain both cars and fruits then you need to keep all objects in the same table, otherwise you can split the data into more tables for faster performance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top