0
votes

I am implementing the use of IndexedDB storage in my webapp (Chrome only) which stores a sequence of records along the lines of

{raw:"string",id:"string",dayUsed:number}

where

  1. id - is the unique string identifying the object (used as the indexedDB objectstore key
  2. dayUsed - records the last day (since Date(2013,11,10)) that the object was used.

As the app is used the number of records in this store will grow. I want to keep tabs on what is happening in this object store with a view to pruning it when

  1. The number of records in the store exceeeds a preset threshold
  2. There are records in the store with a dayUsed value exceeding a preset threshold

I have followed the MDN tutorial (which b.t.w has a few small bits of misinformation) and implemented most of what I need but the record pruning bit still seems unclear.

The core methods offered by IndexedDB are quite limited. For instance, even getting the total number of records is not just a matter of issuing a one-liner. Whilst the app is running I could from time-to-time run a cleanup routine that goes through the whole object store and deletes entries with dayUsed breahces. However, given that my objectstore could well have several hundred entries this could be a lengthy operation that slows down the app. Where then? Spawn a webworker to do the job?

This is starting to look more complicated than I had envisaged. To my question - are there high level wrappers that provide a SQL like interface to IndexedDB stores that can handle all such tasks well?

3

3 Answers

1
votes
0
votes

Check out my library https://bitbucket.org/ytkyaw/ydn-db/wiki/Home

The trick is you just use key to count daily use withiut storing anything.

0
votes

Have a look at this jQuery plugin - jQuery Plugin for indexedDB It gives you the basic functions like objectStore.count() and objectStore.clear(). Here is the link to Documentation - Docs