yathit / ydn-db

Javascript database module for Indexeddb, Web SQL and localStorage storage mechanisms supporting version migration, advanced query, SQL and transaction.
Apache License 2.0
503 stars 41 forks source link

Retrieving datatype(INTEGER) sorted list. #37

Closed amitgodse1 closed 9 years ago

amitgodse1 commented 9 years ago

My Code:

var schema = {
                    version: 2,
                    stores: [{
                        name: 'Employee',
                        keyPath: "name",
                        indexes: [{
                            keyPath: 'phone',
                            type: 'INTEGER'
                        }]
                    }]
                };

I want to retrieve my data sorted my phone which is INTEGER. I have tried all Sorting method like ,

db.values("Employee", "phone", null, 100)).done(function(r) {
  console.log("list of objects sorted by Phone", r);
});

or

db.values("Employee", "phone")).done(function(r) {
  console.log("list of objects sorted by phone", r);
 });

Result :

1 11 2 3 33 4

Where my expected result should be:

1 2 3 4 11 33

Sorting its considering INTEGER as string. Is there way to sort data by datatype while retrieving from object store.?

yathit commented 9 years ago

For number value, it is sorted as numeric. So you will get as expected result.

But, if your phone is string, it will be, from your result, it is sorted by string. ydn-db will not modify the field value. Setting INTEGER is only meaningful only for WebSQL.