treojs / treo

Consistent API to IndexedDB
http://treojs.com
MIT License
258 stars 18 forks source link

Version callback #36

Closed brettz9 closed 8 years ago

brettz9 commented 8 years ago

Hi,

I was wondering whether you'd be open to a PR for accepting a callback as an optional second argument to version() to be executed during upgradeneeded (I suppose after any store/index actions for the version).

I'm just wary of getting locked in to a wrapper which can't let me fully express what the original API could.

Thanks!

alekseykulikov commented 8 years ago

Hi! This is good idea. In free time I'm currently working on treo@0.6, which uses https://github.com/treojs/idb-schema So API for this feature might be:

var schema = new Schema()
.version(1)
  .addStore('books', { key: 'isbn' })
  .addIndex('byTitle', 'title', { unique: true })
  .callback(fn1)
.version(2)
  .getStore('books')
  .addIndex('byDate', ['year', 'month'])
  .callback(fn2)

So you use .callback() method to set custom method in the end of version execution.

brettz9 commented 8 years ago

Sounds good. And as I've been drawn to the convenient query syntax of db.js, it is nice to see idb-schema as a separate library which I may try to work into db.js.

alekseykulikov commented 8 years ago

Yep, it's designed to work smoothly with other libraries :)