InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

JSINQ, a JavaScript Implementation of LINQ

Posted by Abel Avram on Feb 05, 2009

Sections
Development
Topics
.NET ,
Javascript
Tags
LINQ

JSINQ stands for JavaScript INtegrated Query, a beta project implementing LINQ to Objects in JavaScript and recently released on CodePlex by Kai Jäger. JSINQ contains two modules, Enumerable and Query implementing System.Linq.Enumerable and System.Linq.Queryable respectively, allowing one to enumerate over arrays, DOM node lists or other objects.

The two modules are jsinq.Enumerable and jsinq.Query. An example of a query is:

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();

An example of enumerating is:

var enumerator = namesThatStartWithAnA.getEnumerator();
while (enumerator.moveNext()) {
	var name = enumerator.current();
	document.write(name + '<br  />');
}

According to Kai, JSINQ can do:

  • 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.

Kai has put up a playground web page allowing anyone to test JSINQ. The source code can be downloaded for free from CodePlex under the MIT License. Other similar projects: JSLINQ and JLINQ.

No comments

Watch Thread Reply

Educational Content

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.