What is JSINQ?

JSINQ is the JavaScript library that allows you to write SQL-like queries against arrays and DOM node lists.
JSINQ is a complete implementation of LINQ to Objects in JavaScript. What that means is that if you know LINQ and you know JavaScript, you know JSINQ. JSINQ is both an API-compatible implementation of System.Linq.Enumerable and a complete query-expression compiler. That's right: you can write LINQ-style queries in JavaScript. And if that isn't enough: JSINQ is also very liberally licensed, well-document, reasonably well-tested (the Enumerable-part) and currently in beta. So give it a go!

What does it look like?

Let's say you have an array of customers and an array of orders and you want to assemble a list of top customers, that is a list of customers who have in total ordered more than ten items. With JSINQ, you might write something like this:

var query = new jsinq.Query('\
    from order in $1 \
    group order by order.customerId into g \
    select {customerId: g.getKey(), items: g.sum(function(g) { return g.items; })} \
    into h \
    join customer in $0 on h.customerId equals customer.id \
    where h.items > 10 \
    orderby h.items descending \
    select {lastname: customer.lastname, items: h.items} \
');

query.setValue(0, customers);
query.setValue(1, orders);
var result = query.execute();

Confused? What's with all the backslashes? Please read: JSINQ in a nutshell.

What can I do with JSINQ?

  • Write arbitrarily complex queries against JavaScript arrays, DOM node lists or your own enumerable types
  • Find elements in the HTML DOM tree using SQL-like queries
  • Dynamically create HTML elements from JSON you have received via XMLHttpRequest in a declarative manner
  • Tinker with XML and turn it into something else
  • Combine it in interesting ways with the JavaScript-/Ajax-frameworks you are already using
  • Write less code by exploiting the power of declarative programming
  • And for the ambitious: write raytracers, monadic parser combinators, etc.

Using JSINQ

Previous work

JSINQ isn't the first attempt at implementing LINQ in JavaScript. There is also Chris Pietschmann's LINQ to JavaScript (right here on CodePlex), there is jLINQ and then there is this.
Last edited Feb 2 at 2:23 PM by kaijaeger, version 13

 

Want to leave feedback?
Please use Discussions or Reviews instead.

Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2009.10.27.15987