0

I am using Lawnchair JavaScript library. Reference here http://westcoastlogic.com/lawnchair/

In below code, because i passed different id, TABLE1 and TABLE2.. I expect dao1 and dao2 are completely be stored as 2 different objects / storage. But the fact is they're referring to the same thing.. and any "save" action from dao1 or dao2, will be stored at the same "Lawnchair".

i.e. (dao1.all and dao2.all will return same array).

Appreciate for your big/small idea / suggestion.. Thanks!!

        <script src="javascripts/lib/Lawnchair.js" type="text/javascript"></script>
        <script src="javascripts/lib/adaptors/WebkitSQLiteAdaptor.js" type="text/javascript"></script>
        <script src="javascripts/lib/adaptors/DOMStorageAdaptor.js" type="text/javascript"></script>
        <script src="javascripts/lib/adaptors/LawnchairAdaptorHelpers.js" type="text/javascript"></script>

var dao1 = new Lawnchair('TABLE1');
dao1.nuke(); // Clear persistent storage.
dao1.save({111: '222'});

var dao2 = new Lawnchair('TABLE2');
dao2.nuke(); // Clear persistent storage.
dao2.save({333: '444'});

dao1.all(function(a) {
    console.log("dao1")
    console.log(a)
});
dao2.all(function(a) {
    console.log("dao2")
    console.log(a)
});

will produce something like below in Java Console

dao1
m-account.js:112[
Object
333: "444"
key: "ACF3A299-E986-4993-915F-A62FF009E846"
__proto__: Object
]
m-account.js:116
dao2
m-account.js:117[
Object
333: "444"
key: "ACF3A299-E986-4993-915F-A62FF009E846"

proto: Object

mu is too short
  • 426,620
  • 70
  • 833
  • 800
iwan
  • 7,269
  • 18
  • 48
  • 66
  • hi.. thank you for your comment -- dao1.all and dao2.all will return same array – iwan May 10 '11 at 04:48
  • hello, actually this dao1 and dao2 are testing JS objects. But i verified that dao1.save and dao2.save is adding records to actualDao within the same script, i checked by counting the length of array (r) using actualDao.all – iwan May 10 '11 at 05:54
  • hi mu.. any clue how to execute JS in jsfiddle.net? i modify slightly your code to just dump into console. I put into more detail in the question. Thanks a lot for your help. This may be similar question http://stackoverflow.com/questions/5508634/how-do-i-use-lawnchair-with-more-than-one-table – iwan May 11 '11 at 07:33
  • hi mu.. looking at jsfiddle link you gave me, i agree with you that it seems fine for you. Would you mind to give me how do you include Lawnchair js -- is it the same as mine (4 js above)? Thanks a lot – iwan May 13 '11 at 09:41
  • hi mu, thank you for your patience..i took all your Lawnchair references, and it works! It seems the problem happening at latest Lawnchair release, thanks again. Could you put, some short answer -- not part of question comment -- i will flag that as "anser" – iwan May 14 '11 at 00:01
  • Sure, done. And thanks for not giving up, teaching is a great way to learn new things. – mu is too short May 14 '11 at 03:39

2 Answers2

1

Lawnchair works fine:

http://jsfiddle.net/ambiguous/D4u57

I think you might be checking the wrong things (i.e. array length rather than contents), or putting one object in two Lawnchair databases, or perhaps you're not including all of the Lawnchair JavaScript files (there are several in my jsfiddle and I had to pull that list out of one of the Lawnchair examples).

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • thank you for the link sample. it works fine at earlier Lawnchair release (shown) in sample. – iwan May 15 '11 at 10:49
0

Lawnchair is a cross mobile device key-value data store that insulates you from worrying about what platform your code is on.

You are trying to bend LawnChair in to doing something that it isn't designed to do.

You need to do full HTML5 database SQL.

Nick McCloud
  • 101
  • 1