3

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?

http://dev.yathit.com/ydn-db/getting-started.html

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
Richard
  • 1,148
  • 3
  • 18
  • 33

2 Answers2

1

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;
});
Richard
  • 1,148
  • 3
  • 18
  • 33
0

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.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
  • I did try this: db.put('tblSettings', { "setting": "test", "value": "50" }, 1); This is the error message I got: ydn.error.ArgumentException: key cannot provide while in-line key is in used. – Richard Apr 23 '13 at 13:45