Chris Pietschmann

husband, father, hacker, entrepreneur, futurist, innovator, autodidact

NAVIGATION - SEARCH

LINQ to JavaScript (JSLINQ) Open Source Project Launched!

I know LINQ is still rather fresh to everyone yet, and you may not have really used it much, but I just started a new Open Source project called "LINQ to JavaScript". Or, JSLINQ for short. This project brings the ease of querying data collections down to the JavaScript world.

Here are some simple examples of using LINQ to JavaScript:

var myList = [
{FirstName:
"Chris",LastName:"Pearson"},
{FirstName:
"Kate",LastName:"Johnson"},
{FirstName:
"Josh",LastName:"Sutherland"},
{FirstName:
"John",LastName:"Ronald"},
{FirstName:
"Steve",LastName:"Pinkerton"}
];

// Select some data by passing in the clauses as Strings
var test = From(myList).
                Where(
"item.FirstName == 'Chris'").
                OrderBy(
"item.FirstName").
                Select(
"item.FirstName");

// Select some data by passing in the clauses as Methods
var test2 = From(myList).
                Where(
function(item){return item.FirstName == 'Chris';}).
                OrderBy(
function(item){return item.FirstName}).
                Select(
function(item){return item.FirstName});

// You can also mix the two
var test3 = From(myList).
                Where(
function(item){return item.FirstName == 'Chris';}).
                OrderBy(
"item.FirstName").
                Select(
"item.FirstName");

As you can see from the above examples JSLINQ supports two methods of defining the operator clauses:

1) You can pass in a string representation of the clause that will get evaluated to return the desired data.

2) You can pass in a method that will get evaluated to return the desired data.

By supporting both of these methods we are able to support two different, easy to write, yet powerful methods of querying any data you may have within JavaScript.

Go check out LINQ to JavaScript here, and download the source!

blog comments powered by Disqus