简体   繁体   English

像javascript库这样的sql可与数组和对象一起使用

[英]sql like javascript library to work with arrays and objects

I have to mess around with several csv files in node, to produce new csv files (selecting, joining, grouping, etc). 我必须弄乱节点中的几个csv文件,以产生新的csv文件(选择,加入,分组等)。

It's fairly easy to accomplish it all with lodash's functions, but it all tends to be very verbose, and not so nice to maintain. 使用lodash的功能很容易完成所有这些工作,但是所有这些工作往往都很冗长,而且维护起来也不太好。

It could all be solved with a clear, nice, readable, self-documenting, sql statement. 可以使用清晰,美观,可读,自说明的sql语句解决所有问题。

So I'm looking for a library that would allow me to work with a couple of arrays of objects, treat them like tables, apply a sql statement, and get the resulting array ob objects. 因此,我正在寻找一个允许我处理几个对象数组,将它们像表一样对待,应用sql语句并获取结果数组ob对象的库。

Is there something like that? 有那样的东西吗?

Yes of course. 当然是。 As the saying goes, there are 1000 ways to skin a cat. 俗话说,有1000种给猫皮的方法。 Have a look at the following libraries. 看一下以下库。

http://www.jinqjs.com https://linqjs.codeplex.com http://www.jinqjs.com https://linqjs.codeplex.com

Here's an example query: 这是一个示例查询:

var people = [
              {Name: 'Jane', Age: 20, Location: 'Smithtown'},
              {Name: 'Ken', Age: 57, Location: 'Islip'},
              {Name: 'Tom', Age: 10, Location: 'Islip'}
            ];

var population = [
              {Location: 'Islip', People: 123},
              {Location: 'Melville', People: 332},
            ];

var result = new jinqJs()
    .from(people)
    .leftJoin(population)
      .on( function( left, right ) {
        return (left.Location === right.Location);
      } )
    .where( function(row) {
      return ( row.Age > 15);
    })
    .select('Name', 'Location', 'People');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM