aaronpowell / db.js

db.js is a wrapper for IndexedDB to make it easier to work against
http://aaronpowell.github.com/db.js/
MIT License
818 stars 142 forks source link

differences between Firefox and Chrome behaviour on first database create #14

Closed brailateo closed 12 years ago

brailateo commented 12 years ago

At the first database create, right after that, Google Chrome for Windows does not allow the call

server.people.add( {
    firstName: 'Aaron',
    lastName: 'Powell',
    answer: 42
} ).done( function ( item ) {
    console.log("Item 1 stored");
} );

The error message is : Cannot call method 'add' of undefined After creating the database, after a page Reload (opening an already created database) the above constructions works just fine ! Firefox works fine allowing that type of call even for the first time!

The sollution I've found is:

server.add( 'people', {
    firstName: 'Aaron',
    lastName: 'Powell',
    answer: 42
} ).done( function ( item ) {
    console.log("Item 1 stored");
} );

Should I do something special on first database creation on Chrome?

aaronpowell commented 12 years ago

Which version of Chrome are you using? Do you have a test page I can hit?

brailateo commented 12 years ago

I'm using Chrome version 22.0.1229.94 m on Windows 7 , the same version on Linux! You can test the behaviour at http://sniia.iqm.ro/dbjs/readme.html In order to get an error:

In order to test the second method after a page reload:

Firefox 16.0 works just fine in both scenarios and operating systems (Windows 7 and Linux)

aaronpowell commented 12 years ago

I don't have Chrome 22 on my machine, got 23 and it works fine, wonder if it was a bug in just that release.

I'll see if I can get it onto another machine and test.

brailateo commented 12 years ago

I tried to upgrade now on my Windows 7 machine and Chrome says:

Version 22.0.1229.94 m Google Chrome is up to date

I'll wait for 23 version to came out as stable and I'll test it again! Also I will open today another issue that is more a "wish" than an issue! :-)

aaronpowell commented 12 years ago

So I think I know what the problem is related to, Chrome still passes my 'old API' test, where I do a check for the setVersion API. This is how IDB use to handle schema changes, but as of May 2012 it was changed to use onupgraderequested. Chrome was the last browser to move to this, I tried to ensure db.js handled both APIs but ultimately it's a bit of pain.

I plan to remove it since all top-level browsers support onupgraderequested but I didn't think it was causing any problems so I hadn't done it yet. I'll put it into the backlog.

aaronpowell commented 12 years ago

Can you test again PR 20 (f861c80)?

brailateo commented 12 years ago

Now it is not working anymore! With Google Chrome 22 for Linux & Windows 7 when trying to insert with both methods I got: Catch error inserting item 1 TypeError with server.people.add( Catch error inserting item 1 IDBDatabaseException server.add.('people',

Also, query-ing the empty, new created database without any inserts gives the error: Uncaught Error: NotFoundError: DOM IDBDatabase Exception 8

With Firefox 16.0.1 both on Linux & Windows , at insert (both methods) got the error: TypeError: server.add("people", {firstName: "Gelu", lastName: "Pitpalac", answer: 25}).done(function (item) {console.log("Item 2 stored");}).reject is not a function [Break On This Error]
} ).reject( function (item) {

I don't have any jquery.js file in my html test file ! I hope I got right the patched file from git ( I don't know how to work with it )! The md5sum on patched file is teo@teo:~/teste/dbjs$ md5sum db.js 4c091457e5997dcdaf6893a85c087e27 db.js teo@teo:~/teste/dbjs$ cat db.js | wc 510 1793 16873

That is!

aaronpowell commented 12 years ago

I've just downgraded my machine from Chrome beta to Chrome stable so I now have rev-22 installed but I think it's quite broken cuz I can't open any database, regardless of the name or anything (and it's not a documented error).

Out of curiosity are you able to run the unit tests?

aaronpowell commented 12 years ago

Oh and regards to the reject is not a function error, that's expected, reject is the method used by the owner of the deferred object to notify the consumer when an action wasn't successful. You're looking for fail as the method to register with.

aaronpowell commented 12 years ago

Ok, it seems that onupgradeneeded isn't implemented in Chrome 22 so removing setVersion test will break it.

brailateo commented 12 years ago

I don't know how to run the unit tests! What should I do ? Yes, Firefox now works when I have replaced "reject" with fail !

aaronpowell commented 12 years ago

There's folder in the source called /tests which has a small node.js site that you hit the root of. I'm trying to work out how to add it to the docs though.

Ultimately Chrome 22 seems to have some real issues with IDB that I'm struggling to work around :weary:

brailateo commented 12 years ago

It would be better to add in the docs 4 or 5 lines of how to work with it. With Chrome 22, your hard work now to make it compatible somehow will be useless in 6 months, if Chrome 23 is coming with the right IndexedDB implementation. I'm checking daily for updates but my browser continue to pretend that there is no new 23 version yet! :-(

aaronpowell commented 12 years ago

I'm closing this as it is just related to Chrome 22 which is the last version of Chrome not to support onupgradeneeded. I'm not sure when 23 is meant to drop but I do know it works fine in it. In the meantime you might want to try the indexedDB polyfil

brailateo commented 12 years ago

As Google Chrome is moving fast with new releases, it would be no problem to upgrade to new versions so I agree, it's no use to try keeping a backward compatibility!