Reputation: 58662
Two questions about indexeddb operations.
var cursor = request.result;
W3C
var cursor = event.target.result;
MDN
would they give same results always for all requests.
2.
is there a value
property on cursor retuned by index.openCursor
. I see it is used in W3C spec at one place, in a example.
[report(cursor.value.isbn, cursor.value.title, cursor.value.author);][3]
is there a place it say I can use it.
Upvotes: 1
Views: 1248
Reputation: 29208
1) In general it's all requests that have results. There are different types of requests (such as IDBOpenDBRequest
and cursor requests) and various ways to get to objects such as IDBDatabase
and IDBObjectStore
depending on the request. event.target.result
is just one example.
For example:
* An IDBIndex
will have an IDBObjectStore
at objectStore
.
* With an IDBObjectStore
you'll find a reference to an IDBTransaction
at transaction
* On an IDBTransaction
, there will be a db
attribute with an IDBDatabase
.
* An IDBOpenDBRequest
will have its IDBDatabase
on the result
property
In addition to event.target
you'll also find an event.source
that carries such objects and references.
Various types of IDB objects can appear as a target
, and so the event.target.result
will change depending on the method used. It even depends on the callback used: a success
callback from a cursor request yields an IDBCursorWithValue
as event.target.result
(with a request being the target) and nothing on a complete
event.
2) In general it's just IDBCursorWithValue
requests that have a value
. There are various requests that don't yield value, which even include certain types of valueless cursor requests.
Update: A IDBRequest
will have a IDBCursorWithValue
at request.result
and its cursor value is usually (but not always) going to be at request.result.value
(with the exception being value-free cursors, which I doubt you'll be using). request
is returned by the method synchronously (my preferred method to grab a reference) or obtained via event.target
(a little confusing). Check out this method called standardCursor
in my library. It's reused by entries.delete
, entries.get
and entries.update
and should point you in the right direction. My lib is literate and implemented to spec w/exception of its webkitGetDatabaseNames
support.
Upvotes: 2