story.js New Query Object

May 6, 2012

no comments

story.js New Query Object

story.js New ReleaseIf you are following my Blog you probably know that I’ve published a new JavaScript library by the name story.js. story.js enables web developers to use client-side storages in a simple and consistent way.

Today, I’ve added a new feature – query language which resembles LINQ. The query language implementation include functions such as where, forEach, first, last and etc. The query language was created as a plugin to story.js and we are going to add more features to it in the near future. Here is an example of using story query:

/// <reference path="../story.js" />
/// <reference path="../story.query.js" />
 
var storage = story.storage(story.StorageTypes.IN_MEMORY);
storage.add("key1", "value1").then(function (data) {
}, function (error) {
});
storage.add("key2", "value2").then(function (data) {
}, function (error) {
});
storage.add("key3", "value3").then(function (data) {
}, function (error) {
});
storage.getAll().then(function (data) {
    var items = storage.query.from(data).where(function (item) {
        return item.key === "key2";
    }).forEach(function (item) {
        console.log(item.key + ' ' + item.value);
    });
}, function (error) {
    console.log(error);
});

If you want to play with story.js you can download it from here.

If you have any feedback it is most welcome.

Enjoy!

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*