Sklad: IndexedDB abstraction layer


IndexedDB is HTML5 standard for a local database of records holding practically any kind of data - from simple numbers to even Blobs. It is not the same as a relational database which has tables with collections rows and columns. IndexedDB has databases, which have objects stores with data stored there. In fact IndexedDB is a NoSQL database similar to MongoDB and CouchDB. It can also search for data with indexes which you create when start working with the database.

The problem of IndexedDB is following: its API is too geeky, unfamiliar and complicated. Sklad library allows you to build apps for modern browsers with IndexedDB in a simple and convenient way. This is not ORM - it's just a thin abstraction layer on top of IndexedDB native API.

How to start


Sklad library supports CommonJS, AMD (require.js) and global namespace module declaration syntax. Also sklad library needs Promise support. If your browser doesn't support promises you should also include promises polyfill. if you don't like promises you can use deprecated 1.x branch releases. bower install sklad --save or download library and include into your project code. Now you can connect to IndexedDB databases using sklad.open(). More details here. Beware that all operations run faster if you use multiple object stores in one call instead of using multiple simple operations. This happens because each operation runs inside its own transaction.

Insert one or multiple records


There are 4 types of storing your data in the object stores. You should choose which of them fits your needs and after this you should pass proper data in the database.insert(). More details here.

Upsert one or multiple records


Delete one or mutiple records


Clear one or multiple object stores


Get records from the object store(s)


You can specify your own ranges with native IDBKeyRange API. There's no opportunity to get limited number of records and total records number in one call. Default iterating direction is increasing in the order of keys including duplicates, but you can also set your own direction. More details here.

Count objects in the object store(s)


Closing connection


Normally database connection is closed when use closes browser tabs. But if you want to do it explicitly skladConnection.close() method is at your service. More details here.


Fork me on GitHub