I'm using YDN-DB as my indexeddb wrapper; I've read the user guide and api, and have absolutely no idea how you'd update a record by id (primary key [auto incremented]).
Is anyone familiar with this/have any idea?
I'm using YDN-DB as my indexeddb wrapper; I've read the user guide and api, and have absolutely no idea how you'd update a record by id (primary key [auto incremented]).
Is anyone familiar with this/have any idea?
Figured it out (finally) - thanks for the great library Kyaw!
The following code works:
record = {id: 1, "setting": "test", "value": "value"};
req = db.put({name: 'tblSettings', keyPath: 'id'}, record);
req.done(function(key) {
console.log(key);
});
req.fail(function(e) {
throw e;
});
You can update value of a record using put
method by identifying the record by its primary key.
For store using auto generated key (autoIncrement), the primary key is known in the callback when you insert the record via add
or put
method. Primary key can be queried or canonically constructed. For example, a contact object may use its email address as primary key. You can get all primary keys in a store by keys
method.