Click here to Skip to main content
15,613,716 members
Articles / Programming Languages / Javascript
Posted 6 Jul 2009


27 bookmarked

jLinq 2.2.0 Released!

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
13 Aug 2009CC (ASA 2.5)4 min read
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. It's 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…

    .less("firstname", 5)

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


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 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 provide.
  • sum(field): Returns an object with information about the sum of the field name used.
    {<br />
    	count:the number of records counted,<br />
    	result:the sum of all records selected,<br />
    	records:the records used to find the sum<br />
  • average(field): Returns an object with information about the average of the field name used.
    {<br />
    	total:the sum before the average was calculated,<br />
    	count:the number of records used,<br />
    	result:the average of all records selected,<br />
    	records:the records used to find the average <br />
  • 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.
    {<br />
    	source:the record in the jLinq query that is compared,<br />
    	compare:the record in the collection array that is compared<br />

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.


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

Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

Generalhey.. this is good.. Pin
Rajesh Pillai22-Aug-09 7:42
Rajesh Pillai22-Aug-09 7:42 
GeneralRe: hey.. this is good.. Pin
webdev_hb22-Aug-09 8:57
webdev_hb22-Aug-09 8:57 
GeneralHandy framework Pin
misaxi13-Aug-09 23:56
misaxi13-Aug-09 23:56 
GeneralRe: Handy framework Pin
webdev_hb14-Aug-09 1:23
webdev_hb14-Aug-09 1:23 
GeneralThankyou for your contribution Pin
Tumi Le6-Jul-09 6:06
Tumi Le6-Jul-09 6:06 
GeneralInteresting article... Pin
roguewarrior6-Jul-09 3:24
roguewarrior6-Jul-09 3:24 
GeneralRe: Interesting article... Pin
webdev_hb6-Jul-09 5:40
webdev_hb6-Jul-09 5:40 

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

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