-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple operations per transaction, with Treo sugar #32
Comments
Hi, var tr = db.transaction('write', ['avocadoFacts', 'tomatoNotes'])
var facts = tr.store('avocadoFacts')
var notes= tr.store('tomatoNotes')
facts.put(1, { body: 'sometimes avocados have bad taste' })
facts.put(2, { body: 'avocados are expensive in some areas' })
notes.put(1, { body: 'tomato soup is good!' })
tr.then(function() {
console.log('transaction is complete')
}).catch(function(err) {
console.error(err)
}) So, for now I just need to finish 0.6 release. Code is mostly done, need to update docs and test in IE :)
Yes, the reason treo designed this way, because it makes API easier and allows to avoid cross-browser issues. Safari and IndexedDBShim has bad support of transaction reuse. |
Ah this is perfect - I hadn't seen the final API for 0.6. I'd started to write a small plugin which allowed for a lot of the same things that 0.6 does, so I shall grab the release candidate and use that instead. Thanks :) |
You are welcome. 0.6.0-rc1 is pretty stable, I'm just diving to transaction implementation and test it carefully. A few things to keep in mind:
Let me know, how it works :) |
Nice :) |
Currently (as I understand it), Treo opens a transaction for each atomic operation—
get
,put
etc.—allowing for the possibility of data changes between read and write:While it's probably not a huge deal for many applications, I'm running into it fairly frequently (my data is not directly generated by a user interface) and so I'm finding myself falling back to IndexedDB's standard API; opening a big transaction to do my work, and hence losing a lot of the Treo sugar.
I was wondering if there were any plans for a feature like chaining reads and writes together in a single transaction (effectively making an
update
call that's much less verbose than the IndexedDB equivalent), or any thoughts on how difficult it might be to carry over the transaction to arbitrary actions on data.This is a little hairy and ill-defined, but for instance here's some code I'd like to be able to write:
Terrible API aside (very little thought has gone into it; I just want to open the discussion), is it clear what I'm getting at? The example above (updating a record) might be better as a plugin's job, but I'd be interested to hear your thoughts on making better use of transactions in situations like these, and addressing the root cause. Transactions as a concept are extremely useful, but I feel like they're being under utilised.
The text was updated successfully, but these errors were encountered: