简体   繁体   English

GWT / JS库,用于类似DB的临时存储

[英]GWT/JS Libraries for DB-Like Temporary Storage

I am looking for a library written in either GWT or Javascript that allows me to put data to some kind of structure which would allow me database-like queries. 我正在寻找一个用GWT或Javascript编写的库,该库允许我将数据放入某种结构中,从而可以进行类似数据库的查询。

For example, I might store a number of records and then ask questions like, give me all the records matching certain conditions. 例如,我可能会存储许多记录,然后问一些问题,例如,给我所有符合特定条件的记录。

The level of optimization is less important...for example a scan may be appropriate for most applications since this code would be running clientside on small amounts of data. 优化级别不太重要...例如,扫描可能适合大多数应用程序,因为此代码将在少量数据上在客户端运行。

Library 图书馆

There's TrimQuery : TrimQuery

For rich web application developers, the TrimQuery engine from TrimPath is a lightweight GPL/APL open-source component that lets you have the power of SQL queries while running in a web browser. 对于富Web应用程序开发人员来说, TrimPath的TrimQuery引擎是轻量级的GPL / APL开源组件,使您可以在Web浏览器中运行时拥有SQL查询的功能。

No library 没有图书馆

...although for your stated goal, it seems easy enough to loop over array of objects, perhaps using one of the new ES5 Array methods like filter (which are easy enough to add when running in a browser that doesn't have native copies). ...虽然达到您的既定目标,但似乎很容易遍历对象数组,也许可以使用新的ES5 Array方法之一(例如filter (在没有本地副本的浏览器中运行时很容易添加) )。 For instance, if you have an array of objects representing cars, this gives you the blue ones: 例如,如果您有一系列代表汽车的对象,则为您提供蓝色的对象:

// Get only blue cars
var blueCars = store.filter(function(entry) {
    return entry.color === "blue";
});

Live example 现场例子

Or if you don't want to worry about adding filter to older browsers, just use a simple for loop: 或者,如果您不想担心将filter器添加到较旧的浏览器,只需使用一个简单的for循环:

var blueCars, index, entry;

blueCars = [];
for (index = 0; index < store.length; ++index) {
    entry = store[index];
    if (entry && entry.color === "blue") {
        blueCars.push(entry);
    }
}

Here's the store I'm running either of those against: 这是我针对这些store经营的store

// The data store
var store = [
    {color: "blue", make: "Toyota"},
    {color: "red", make: "Toyota"},
    {color: "green", make: "Toyota"},
    {color: "blue", make: "Ford"},
    {color: "silver", make: "Ford"},
    {color: "blue", make: "Jaguar"},
    {color: "red", make: "Jaguar"},
    {color: "green", make: "Fiat"}
];

And here's how to add filter if it's not there natively (off-the-cuff implementation, you might look for libraries like es5-shim that try to do a more thorough job, or just use a simple for loop): 如果本地不存在filter ,这是添加filter的方法(现成的实现,您可能会寻找诸如es5-shim之类的库,尝试做更彻底的工作,或者仅使用简单的for循环):

// Add `filter` if not already there
if (typeof Array.prototype.filter === "undefined") {
  (function() {
    display("(Added <code>filter</code>, browser didn't have it natively)");
    function Array$filter(callback, thisArg) {
      var index, value, result;

      result = [];
      for (index = 0; index < this.length; ++index) {
        if (this.hasOwnProperty(index)) {
          value = this[index];
          if (callback.call(thisArg, value, index, this)) {
            result.push(value);
          }
        }
      }
      return result;
    }
    if (typeof Object.defineProperty !== "undefined") {
      Object.defineProperty(Array.prototype, "filter", {
        enumerable: false
      });
    }
    else {
      Array.prototype.filter = Array$filter;
    }
  })();
}

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

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