Skip to content

Commit

Permalink
Merge git://github.com/dvv/rql
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jul 29, 2010
2 parents 736c7a0 + b888e48 commit e66e36a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/js-array.js
@@ -1,7 +1,7 @@
/*
* An implementation of RQL for JavaScript arrays. For example:
* require("./js-array").query("a=3", {}, [{a:1},{a:3}]) -> [{a:3}]
*
*
*/
var parseQuery = require("./parser").parseQuery;

Expand Down Expand Up @@ -70,10 +70,11 @@ exports.operators = {
},
select: function(){
var args = arguments;
var argc = arguments.length;
return this.map(function(object){
var selected = {};
for(var i = 0; i < args.length; i++){
var propertyName= args[i];
for(var i = 0; i < argc; i++){
var propertyName = args[i];
if(object.hasOwnProperty(propertyName)){
selected[propertyName] = object[propertyName];
}
Expand All @@ -88,10 +89,11 @@ exports.operators = {
});
}
var args = arguments;
var argc = arguments.length;
return this.map(function(object){
var selected = [];
for(var i = 0; i < args.length; i++){
var propertyName= args[i];
for(var i = 0; i < argc; i++){
var propertyName = args[i];
selected.push(object[propertyName]);
}
return selected;
Expand Down
9 changes: 7 additions & 2 deletions lib/query.js
Expand Up @@ -6,8 +6,8 @@
* require("./js-array").query(query, params, data); // if we want to operate on an array
* };
* query.eq("a", 3).le("b", 4).forEach(function(object){
* // for each object that matches the query
* });
* // for each object that matches the query
* });
*/

try{
Expand Down Expand Up @@ -74,6 +74,11 @@ exports.encodeValue = function(val) {
val.toISOString && val.toISOString() || val.toString()
))) {
var type = typeof val;
if(val instanceof RegExp){
type = "re";
val = val.toString();
val = val.substr(1, val.length-2);
}
if(type === "object"){
type = "epoch";
val = val.getTime();
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "rql",
"author": "Kris Zyp",
"contributors": [],
"contributors": ["Vladimir Dronnikov <dronnikov@gmail.com>"],
"keywords": [
"resource",
"query",
Expand Down

0 comments on commit e66e36a

Please sign in to comment.