knadh / localStorageDB

A simple database layer for localStorage and sessionStorage for creating structured data in the form of databases and tables
http://nadh.in/code/localstoragedb
814 stars 128 forks source link

Sort isn't working? #46

Closed joshfoskett closed 8 years ago

joshfoskett commented 9 years ago

I'm attempting to sort mapId's in ascending order:

var playingServers = getDatabase().queryAll('playing', {sort: [['mapId', 'ASC']]});

console.log(playingServers);

However, it doesn't appear to be working: screenshot on 11 17 2014 at 1 35 01 pm

As you can see, it is not sorting the mapId in ascending order, but instead by the ID. I also have no errors, so I'm not sure why it isn't working. I've looked at the docs, and it would appear that I'm doing everything correctly?

knadh commented 9 years ago

Sort does indeed work, with any field of your choice. Not sure what's happening in your case. Can you share this bit of code so I can take a look?

joshfoskett commented 9 years ago

Sorry, the issue appears to be with the way I was calling the database:

function getDatabase() {

    return chrome.extension.getBackgroundPage().database;

}

In every other instance, that method worked as it should (for other stuff, like inserting, deleting rows, querying, etc.), and it didn't dawn on me that something as random as sorting would be affected by it, especially when I was getting the results, just not sorted.

As to why using chrome.extension.getBackgroundPage().database doesn't work specifically when sorting, I have no idea. I was using this method so I didn't have to create two different instances of database within my Chrome extension (one in the background, and one when a popup was created), but at the end of the day I doubt it matters all that much. It would appear that having two different instances is an issue, as it doesn't realize that change until it has been reloaded.