Update and remove operation on Jaydata
I'm trying to write a simple CRUD functionality in Jaydata, I had written this simple code for update operation:
SampleClass.prototype.Load = function(input1,callback) { var param='it.Name=="'+input1+'"'; this.data.items.filter(param).forEach(function(ii) { callback(ii); }); this.data.items.saveChanges(); };
so when I call:
t.Load('Entry4',function(res){console.log(res.Name)})
It works like a charm! But If I call an update operation for callback like:
t.Load('Entry4',function(res){res.Name="Entry5"})
It doesn't change anything in the DB. I have seen something like beginTransaction function as in http://jaydata.org/examples/JayDataPro/ToDoList_complex, but I couldn't understand the essence of it.
Answers
Special thanks to Gabor Dolla
In order to update a value in JayData:
- DB has to have a primary-key inside it.
- Change non-key attributes
- Call the asynchronous save() function after it.
solution to the question is: after changing the object field's definition like this:
Name{ type:'string', **key:true**}
You can query on anything but only change non-key attributes of them
t.Load('Entry4',function(res){res.LastName="Entry5";res.save()});