Pull to refresh

Выполнение SQL-подобных запросов над данными — как в браузере, так и на сервере

Reading time1 min
Views1.9K
Marak Squires выпустил в свет JSLINQ — реализацию LINQ для JavaScript, работающую как на стороне браузера, так и на стороне сервера (к примеру, node.js). Поддерживаются такие конструкции, как JOIN, UNION, RANGE, DISTINCT, COUNT etc.

Смотрите:

JSLINQ


var sample = JSLINQ(sampleData).
 Where(function (item) {return item.FirstName == "Chris";}).
 Select(function (item) {return item.FirstName;}).
 OrderBy(function (item) {return item;});

* This source code was highlighted with Source Code Highlighter.

Кстати, XaocCPS когда-то рассказывал о проекте jLinq, а Карл Гертин упомянул о проекте JSINQ, которые также можно посмотреть.

jLinq


var results = jLinq.from(data.users)
  .startsWith("first", "a")
  .orEndsWith("y")
  .orderBy("admin", "age")
  .select();


* This source code was highlighted with Source Code Highlighter.

JSINQ


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


* This source code was highlighted with Source Code Highlighter.
Tags:
Hubs:
+24
Comments21

Articles

Change theme settings