cdjackson
cdjackson

Reputation: 137

Structure of IndexDB database/objectstore

I'm trying to get my head around the use of IndexDB. I have an SQL database which I access via REST and I'm planning on providing some local caching using IndexDB.

My SQL structure uses a large (and variable) number of tables, each table storing an array of data (time sequence and value) for a specific sensor value. Ideally, I would have assumed I'd create a new object store for each of my tables from MySQL. However, it seems that you can only create an object store when the database is opened which is a bit of a pain.

So, I see a number of options -:

I'd welcome any thoughts people have regarding the best structure for this sort of data, that will provide good performance.

Upvotes: 1

Views: 275

Answers (1)

Deni Spasovski
Deni Spasovski

Reputation: 4129

If your data sets are independent, example you don't need to combine results from multiple sensors, I suggest you to split them in different tables and/or different databases. Different database option is more convenient for deleting data.

IndexedDB database limit for performance in a single database is for more than 50K data, depending on browser and hardware. I have a couple tests which can measure the speed, just tweak the object size that is inserted and you can test your use case.

If you have less than 10K data per sensor (object store/database) you won't hit big performance issues. One common mistake when inserting batch of data is separate transaction for each insert - this is completely unnecessary, since you can store 10K data with one transaction. If you are working with even larger data set, you can separate the inserting into couple transaction, so you won't block the reading of that database.

Also for every transaction that you do in IndexeDB you need to open a connection, some people use the approach for keeping the one connection alive and reusing it, I prefer the closing and opening a separate connection for each transaction.

Also for faster access, you can store all database info into Local Storage, that way you can track how many databases you have and descriptions for each of them.

Additionally you can take a look at this similar question

Upvotes: 1

Related Questions