After a bit more sweat and tears, I've now got a "full" (if ugly) example of an IndexedDB application. It allows you to create and delete simple notes. You can view this demo here:
http://www.raymondcamden.com/demos/2012/apr/30/test5.html
Right now this demo is Firefox only. It doesn't work in Chrome because of the bug I mentioned in my earlier blog post. Here's the code - and again - I want to mention (and credit) the excellent MDN tutorial for making this easier to build.
Nothing too scary, right? Using method chaining makes the code a bit more palatable and simpler to work with.
After getting this working, I began to look at how you can retrieve data. I guess I shouldn't be surprised (and @thefalken pointed it out to me), but you are limited to primary key lookups only.
So let me make sure that is clear. This is not a replacement for WebSQL. You cannot search. I guess - technically - you could search if you load everything up and iterate over it, but that's not really efficient. You can do range based filters, so for example, given a set of names I could go from Bob to Mary, but if I wanted to quickly find all the objects with property X set to Y and property Z set to A, then I'm out of luck. I was really thinking this was a Mongo-ish type solution, but I was wrong.
I don't know about you - but this is kind of disappointing. Maybe my opinion will change, but right now I'm sad that WebSQL is being dumped for this.
Archived Comments
I am using PhoneGap and WebSQL at the moment. Just got your synchronisation working by the way. Will I have to dump WebSQL and use IndexedDB? Search is essential in my applications.
WebSQL works in mobile just fine (not just Mobile/PhoneGap, but the browsers themselves). So I'd continue to use it for now. Just be aware of it being deprecated in general.
As it stands - even if it goes away 100%, you can use SQLite via a PhoneGap plugin to continue using it.
Hello,
Google Chrome:
var transaction = db.transaction(["note"], IDBTransaction.READ);
Change:
var transaction = db.transaction(["note"], 'readwrite');
var request = db.transaction(["note"], IDBTransaction.READ_WRITE)
Change:
var request = db.transaction(["note"], 'readwrite')
var request = db.transaction(["note"], IDBTransaction.READ_WRITE)
Change:
var request = db.transaction(["note"], 'readwrite')
Thank you. :)
No, thank you. :) I haven't gotten around to updating my Chrome IndexedDB articles. They were written at a time when Chrome wasn't fully to spec.
Excellent sample application. However, how to get count of the data store?
You can get a count pretty easy - see my "Counting Data" section in this article:
http://code.tutsplus.com/tu...