Click here to Skip to main content
Click here to Skip to main content

jLinq 2.2.0 Released!

, 13 Aug 2009
Rate this:
Please Sign up or sign in to vote.
jLinq is a Javascript query language that makes it easy to work with large arrays of information. Today, jLinq 2.2.0 is released which offers new commands, bug fixes and more!

Ever hear of jLinq. If not, it’s no big deal. Its a personal project of mine to make a LINQ style query language for Javascript. With all these “Web 2.0″ applications floating around, the ability to sort, query and manage your records on the client side may become a necessity. Use jLinq with the JSON data you already have and you’ve got quite a combination.

If you haven’t tried it out, there is an online version available you can use to see it in action.

Below are some of the new features in jLinq 2.2.0.

Smarter Comparisons

Let’s say you ran the command below…

jLinq.from(users)
    .less("firstname", 5)
    .select();

Seems simple enough, first names less than 5 characters long?

Nope…

The previous version of jLinq expected certain data types depending on the command. For example, if you used less, lessEquals, greater, greaterEquals, between or betweenEquals then the expected parameter was a number as was the field you were querying against.

In the new version you’ll find code like this when checking values.

//get the the parameter value
value = query.helper.when(value, {
    number:function() { return value; },
    other:function() { return value.length; }
});

//determine how to check this against the value
return query.when({
    string:function() {
        return (query.value.length < value);
    },
    array:function() {
        return (query.value.length < value);
    },
    other:function() {
        return (query.value < value);
    }
});

Instead of making any assumptions, jLinq now checks the types and returns the values required to make the query work. For example, if you use ‘less’ with a string value, the length property is automatically used instead of the string value itself.

jLinq also is more intelligent with different command types. For example, the .contains() used to work with string values only. Now it works with arrays or converts a value to a string then checks the result.

11 New Commands

  • attach(alias, function): Executes and attaches the return value of your function onto the record using the alias name you provice.
  • sum(field): Returns an object with information about the sum of the field name used.
    returns
    {
    
        count:the number of records counted,
    
        result:the sum of all records selected,
    
        records:the records used to find the sum
    
    }
  • average(field): Returns an object with information about the average of the field name used.
    returns
    {
    
        total:the sum before the average was calculated,
    
        count:the number of records used,
    
        result:the average of all records selected,
    
        records:the records used to find the average 
    
    }
  • max(field): The maximum value found for the field name provided.
  • min(field): The minimum value found for the field name provided.
  • except(collection): Compares a second set of records and only returns records that are not found in the comparison list. Returns a new jLinq object. (example)
  • intersect(collection): Compares a second set of records and only returns records that are found in both lists. Returns a new jLinq object. (example)
  • union(collection): Compares a second set of records and only returns records that are unique in both lists. Returns a new jLinq object. (example)
  • skipWhile(delegate): Skips selecting records until the first ‘false’ result is returned from your function. After that point, all records are selected. Returns an array of results. (example)
  • takeWhile(delegate): Selects records until the first ‘false’ result is returned from your function. After that point, all records are ignored. Returns an array of results. (example)
  • selectMany(collection, compareFunction, selectionFunction): Compares each value of the current query against the provided collection array (example). For each successful comparison a new record is added to your results. If you use your own selection method then you need to write a function similar to function(queryRecord, compareRecord) {. The return value will be added to the list. If no selection method is used, then the following object is returned.
    returns
    {
    
        source:the record in the jLinq query that is compared,
    
        compare:the record in the collection array that is compared
    
    }

Bug Fixes

There was an Opera bug when you tried to sort records. I’m not sure that I understand why, but basically, there really is a difference between for loops in Opera.

jLinq Testing

If you’re interested in creating your own jLinq extension methods you can now download a series of tests that you can use to determine that your command doesn’t break anything else in jLinq.  

Wrapping Up

Whew! You’re still with me? You must be dedicated!

Right now I realize that there still may be some confusion on how to use jLinq. I’m currently working on some screencasts that I can share to help people get started.

If you have some requests on what you would like to see in an upcoming screencast, please send me your ideas and I’ll add them to my list.

Source Code  

Download jLinq 2.2.0 

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License

About the Author

webdev_hb

United States United States
No Biography provided

Comments and Discussions

 
Generalhey.. this is good.. PinmemberRajesh Pillai22-Aug-09 7:42 
GeneralRe: hey.. this is good.. Pinmemberwebdev_hb22-Aug-09 8:57 
GeneralHandy framework Pinmembermisaxi13-Aug-09 23:56 
my 5 because jLinq provides the excellent straightforward way to the .net developer
good work!
GeneralRe: Handy framework Pinmemberwebdev_hb14-Aug-09 1:23 
GeneralThankyou for your contribution PinmemberLe Hoang Dung6-Jul-09 6:06 
GeneralInteresting article... Pinmemberroguewarrior6-Jul-09 3:24 
GeneralRe: Interesting article... Pinmemberwebdev_hb6-Jul-09 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 13 Aug 2009
Article Copyright 2009 by webdev_hb
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid