Code Monkey home page Code Monkey logo

query-engine's Introduction

Query-Engine

Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Gratipay donate button Flattr donate button PayPayl donate button BitCoin donate button Wishlist browse button

Query-Engine is a NoSQL and MongoDb compliant query engine. It can run on the server-side with Node.js, or on the client-side within web browsers

QueryEngine provides extensive Querying, Filtering, and Searching abilities for Backbone.js Collections as well as JavaScript arrays and objects. The Backbone.js and Underscore dependencies are optional.

Features

  • runs on node.js and in the browser
  • supports NoSQL queries (like MongoDB)
  • supports filters (applying a filter function to a collection)
  • supports search strings (useful for turning search input fields into useful queries)
  • supports pills for search strings (e.g. author:ben priority:important)
  • supports optional live collections (when a model is changed, added or removed, it can automatically be tested against the collections queries, filters, and search string, if it fails, remove it from the collection)
  • supports parent and child collections (when a parent collection has a model removed, it is removed from the child collection too, when a parent collection has a model added or changed, it is retested against the child collection)
  • actively maintained, supported, and implemented by several companies

Compatability

Tested and working against:

Using

Install

  • Use: require('query-engine')
  • Install: npm install --save query-engine
  • Use: require('query-engine')
  • Install: npm install --save query-engine
  • CDN URL: //wzrd.in/bundle/[email protected]
  • Use: require('query-engine')
  • Install: ender add query-engine

Direct

  • Use: window.queryEngine or window.QueryEngine whichever you prefer
  • CDN URL: //bevry.github.io/query-engine/lib/query-engine.js

History

Discover the change history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

These amazing people have contributed finances to this project:

Become a sponsor!

Gratipay donate button Flattr donate button PayPayl donate button BitCoin donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Become a contributor!

License

Licensed under the incredibly permissive MIT license

Copyright © 2012+ Bevry Pty Ltd [email protected] (http://bevry.me)
Copyright © 2011 Benjamin Lupton [email protected] (http://balupton.com)

query-engine's People

Contributors

alfred-nsh avatar andrewjshults avatar balupton avatar djebbz avatar nfm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

query-engine's Issues

There's no Easy way to check that an array exists and has length

This is how I currently query to find a non empty array

collection
        .findAll({
            theArray: {$exists: true},
            $not: {theArray: $length: 0}
        })

It would be great if there was another way to do this or atleast some syntactic sugar that would let me do something like:

collection
        .findAll({
            theArray: $gt: 0
        })

or maybe

collection
        .findAll({
            theArray: $length: $gt: 0
        })

Wrong behaviour resetting collection without models array

Calling collection.reset() without arguments causes a wrong behaviour due to line 588 of query-engine.js. (QueryCollection.prototype.add). It looks the problem is the condition that forces the creation of an array when models argument is not one (:[models]). It creates an array even in the case the models argument of add method is undefined. This causes the array to have 1 phantom element ({}).
Fortunately there is an easy workaround, to call reset method with an an empty array (collection.reset([])). This way the condition that gets evaluated is ?models.slice() and that returns an empty array which is the expected behaviour.

Are you accepting pull requests? I see many issues open.

Create non-backbone query-engine build/fork

Now that query-engine requires backbone, it starts to get to heavy for simple use-cases with simple arrays. I understand the reason why backbone is now required is because of the live collections. This make sense, but if you remove the live collections feature from query-engine, does that trim it down enough to not warrant backbone? I personally don't need the concept of live collections.

Thoughts?

Error 'Couldn't find the selector' when changing properties order in findAllLive

I'm using docpad 6.59 and node 0.10.12

If I define this collection

pages: (database) ->
    database.findAllLive({relativeOutDirPath:/de[\/\\]\w+/, pageOrder: $exists: true})

it works, but when I change the order, it fails:

pages: (database) ->
    database.findAllLive({pageOrder: $exists: true, relativeOutDirPath:/de[\/\\]\w+/})

Error:

error: An error occured: 
Error: Couldn't find the selector relativeOutDirPath
    at Query.compileSelector (./node_modules/docpad/node_modules/query-engine/out/lib/query-engine.js:1492:15)

Limit the number of results

Unless I'm mistaken, QueryEngine doesn't implement the limit cursor method of MongoDB. S o it's not natively possible to extract only a few results. MongoDB docs says that it's a very good performance enhancement, since more objects than necessary may be returned otherwise.

Is there already a way to limit results ? If not, is this feature planned ?

reading property of undefined

If i use query-engine as a common module and convert them with browserify, then i got an error in line 5 of query-engine.js. This is the extend function of coffeescript, but it themes that the Backbone variable is the problem.

If i change

(function() {
  var Backbone, Criteria, Hash, Pill, Query, QueryCollection, queryEngine, util, _ref,
    __hasProp = {}.hasOwnProperty,
    __slice = [].slice,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  Backbone = this.Backbone || (typeof window !== "undefined" && window !== null ? window.Backbone : void 0) || ((function() {
    try {
      return typeof require === "function" ? require('backbone') : void 0;
    } catch (_error) {}
  })()) || ((function() {
    try {
      return typeof require === "function" ? require('exoskeleton') : void 0;
    } catch (_error) {}
  })()) || null;

  util = { [...]

to

(function() {
  var Backbone, Criteria, Hash, Pill, Query, QueryCollection, queryEngine, util, _ref,
    __hasProp = {}.hasOwnProperty,
    __slice = [].slice,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  Backbone = null;

  util = { [...]

it works fine. So i tested what i got back at the Backbone declaration. It themes that i will got an object instead of null. So the following parts act as i loaded Backbone an will extend functionallity from an undefined object. I hope it is not so confusing.

Thomas

assert all selectors are tested

Issue #41 is a result of $hasAll not having a test - I'd like to suggest that a "meta-test" be added simply to make sure all query selectors have an associated test. This would assert a certain level test coverage.

I imagine it would look something like looping over Query.selectors and making sure a key for the selector exists in queryTests:

https://github.com/bevry/query-engine/blob/master/src/documents/test/queries-test.js.coffee#L71

The selectors are defined here:

https://github.com/bevry/query-engine/blob/master/src/documents/lib/query-engine.js.coffee#L1214-L1470

It could even be as simple/naive as:

Object.keys(queryTests).length is Object.keys(Query.selectors).length

PS: If you want to get even more meta - test just $hasAll and then use that to test that queryTests has all of the keys of Query.selectors. WE CAN GO DEEPER

QueryEngine not RequireJS compatible

Hello,

When using the 'AMD' versions of Underscore and Backbone libraries, QueryEngine fails to load the proper dependencies using require("backbone"), etc.

As per this discussion require sync version needs to be used within a require or define callback, like so:

define(['foo-dep', function () {
  var foo = require('foo-dep');
});

The issue can be seen here

Patched version can be seen here

I apologize, I don't yet know coffeescript well enough to submit a pull request, but I have provided a diff of the javascript files if that helps. The main difference is a define wrapper at the top, and returning the global at the bottom. (code borrowed from knockout.js):

http://www.diffnow.com/?report=ignzq

Regards,
Aaron

Issue when using without Backbone

Hello,

I use your lib for a project that does'nt use Backbone and it fails with this line :

else if (selectorValue instanceof Backbone.Model) {

cause the Backbone is not defined, you cannot get something on it.

KR

Using with Webpack

Has anyone been able to get this working with Webpack? I tried shimming it but I'm not sure what is going wrong. It was complaining about not being able to find the parent. In fact, none of the require calls were working inside of it.

how to mix $or and $and ?

I want to make a query, something like that: (foo && bar) || (qux && baz)
I wrote it in this style (coffee script)

@getDatabase().findAllLive
  $or:
    $and:
      foo: {$exists: true}
      bar: {$exists: true}
    $and:
      qux: {$exists: true}
      baz: {$exists: true}

But the result is always the part with qux && baz

Here is the real query:
https://gist.github.com/timaschew/0f53f48a8e82431dccf6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.