Microsoft is continuing to build on it’s cloud based document database designed for web applications and today is announcing support for JavaScript Language Integrated Queries.

Azure DocumentDB’s database engine is purposefully designed from the ground up to provide first class support for JSON and JavaScript. Our vision is for JavaScript developers to build applications without having to deal with the entity mappers, schemas, code generation tools, type adornments and other duct tapes.  — Azure Blog

Azure DocumentDB allows developers to store data in native JSON format and then perform queries on that data including using stored procedures.  The diagram below shows how JSON data is stored in Azure DocumentDB

JSTree

 

The query for all “exports” from documents with the headquarters of Belgium previously looked like this.

[code language=”javascript”]
function() {
var filterQuery = ‘SELECT * from companies c where c.headquarter = "Belgium"’;
var isAccepted = .queryDocuments(.getSelfLink(), filterQuery,
function(err, docs, options) {
if (err) throw new Error(err.number + err.message);
__.response.setBody(docs);
});
if (!isAccepted) __.response.setBody(‘Query timed out’);
}
[/code]

But with JavaScript Language Integrated Queries, that same query can be expressed with this syntax.

[code language=”javascript”]
function() {
var resp = __.filter(function(company) {
return company.headquarter == ‘Belgium’;
});
if (!resp.isAccepted) __.response.setBody(‘Query timed out’);
}
[/code]

For more information on this announcement including a SQL to JavaScript Query API Cheat Sheet, visit the Azure Blog.