Closed juarezpaf closed 10 years ago
Hey, sorry for the delayed reply. Let me look into it implementing a sort method.
It will be great for sure! :smile:
I started implementation but quit as it no longer fit my needs. Feel free to pick it up. @ (https://github.com/a904guy/localStorageDB/blob/master/localstoragedb.js)
@line: 166
// sort records by field name (sort) returned from select
function sort(results,sort)
{
var r = [], sortable, s = sort;
for(var record in results)
{
record.sort(function(a,b)
{
if (typeof a[s].localeCompare === 'function') return a[s].localeCompare(b[s]);
return a[s] - b[s];
}
);
r.push(record);
}
return r;
}
@line: 619:
// select rows
query: function(table_name, query, limit, start, sort) {
tableExistsWarn(table_name);
var result_ids = [];
if(!query) {
result_ids = getIDs(table_name, limit, start); // no conditions given, return all records
} else if(typeof query == 'object') { // the query has key-value pairs provided
result_ids = queryByValues(table_name, validFields(table_name, query), limit, start);
} else if(typeof query == 'function') { // the query has a conditional map function provided
result_ids = queryByFunction(table_name, query, limit, start);
}
return sort(select(table_name, result_ids, limit),sort);
},
@a904guy see my PullReq. https://github.com/knadh/localStorageDB/pull/35
@juarezpaf, sorry it's been so long, but the multi-field sorting is now supported (https://github.com/knadh/localStorageDB/commit/63a17494ebe3e22f442f43fc25d432d52098afb1). Thanks to @orangecoding.
Hey @knadh Congratulations for this awesome project, I am wondering if it is possible to implement a sort method. Thanks in advance!