Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any chance to implement sort method? #18

Closed
juarezpaf opened this issue Sep 21, 2013 · 5 comments
Closed

Any chance to implement sort method? #18

juarezpaf opened this issue Sep 21, 2013 · 5 comments

Comments

@juarezpaf
Copy link

Hey @knadh Congratulations for this awesome project, I am wondering if it is possible to implement a sort method. Thanks in advance!

@knadh
Copy link
Owner

knadh commented Sep 28, 2013

Hey, sorry for the delayed reply. Let me look into it implementing a sort method.

@juarezpaf
Copy link
Author

It will be great for sure! 😄

@a904guy
Copy link
Contributor

a904guy commented Jan 26, 2014

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 a904guy mentioned this issue Jan 30, 2014
@orangecoding
Copy link

@a904guy see my PullReq. #35

@knadh
Copy link
Owner

knadh commented Mar 13, 2014

@juarezpaf, sorry it's been so long, but the multi-field sorting is now supported (63a1749). Thanks to @orangecoding.

@knadh knadh closed this as completed Mar 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants