Git Product home page Git Product logo

backbone_query's People

Contributors

cezary avatar davidgtonge 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  avatar  avatar  avatar  avatar

backbone_query's Issues

Making Backbone-query AMD-compatible

Just a note for others, so that they don't waste valuable time on debugging this:
Backbone-query does not work out-of-the box in conjunction with the RequireJS optimizer,

In Coffeescript

  • Replace (on top): define ['underscore', 'backbone'], (_, Backbone) ->
  • Replace (at the bottom): Backbone (to export the module variable).

In JavaScript

  • Replace the top (function(){ with `define(['underscore', 'backbone'], function(_, Backbone) {
  • Replace the bottom }).call(this); with }); (or, if an export is desired, return Backbone;});. Don't worry about the changed context, Backbone-query doesn't use var root = this; or something to export variables.

If you want to create a module which is compatible with node and AMD loaders, have a look at these examples for Backbone and underscore: https://gist.github.com/2517531 :

(function(root, define) { define('underscore', function(require, exports, module) {

...

})}).call(this, this, typeof define === 'function' && define.amd ? define : function(id, factory) {
  if (typeof exports !== 'undefined') {
    // CommonJS has require and exports, use them and execute
    // the factory function immediately. Provide a wrapper
    // for require to deal with jQuery.
    factory(function(id) {
      // jQuery most likely cannot be loaded
      // in a CommonJS environment, unless the developer
      // also uses a browser shim like jsdom. Allow
      // for that possibility, but do not blow
      // up if it does not work. Use of a
      // try/catch has precedent in Node modules
      // for this kind of situation.
      try {
        return require(id);
      } catch (e) {
        // Do not bother returning a value, just absorb
        // the error, the caller will receive undefined
        // for the value.
      }
    }, exports);
  } else {
    // Plain browser. Grab the global.
    this._ = {};
  }
});

Implement benchmark.js?

It would be nice to have an out-of-the-box benchmark to run using node benchmarks.js using Benchmark.js.

I'm using this library on a AngularJS project and angularjs is known of firing the same cycles over and over again, just one page load, a $watcher is called 90 times!

so I'm interested to I can rest assured that this won't ever be a bottleneck.

Search on nested properties

Given a collection consisting of models like

{
  "title": "post title",
  "content": "post content",
  "id": "1", 
  "comments": [
    {    
      "text": "comment 1 content"
    },
    {    
      "text": "comment 2 content"
    }
  ]
}

I'd like to be able to query against the text inside the nested array, in addition to the text in the toplevel attributes. Currently I'm doing this server-side using a mongo query against the nested property like:

find(
  "$or"=>[
    {:title          => /#{query}/i},
    {:content        => /#{query}/i},
    {"comments.text" => /#{query}/i}
  ]
)

Is it possible or planned to approximate this behavior with backbone_query?

Nested Models not supported ?

I have been using nested models quite a lot (using backbone-relational) to replicate the server side models in Backbone. This seems to be a really interesting project.

It would be even awesome if there would be support for nested models. Atm, it seems like i can perform queries only on categories(of Models in the collection), but what if my models had other nested models (

Lets say Comment Model -> belongs to -> Blog Model -> belongs to -> User Model.
Given the Comment Collection, I'd like query and list all the comments that belongs to a User.

Any plans for such support ?

Storing the query part in a db

Maybe I am missing something obvious but I am trying to store the actual query part in a db as a saved search and then use it to filter the collection.

Following your example:

MyCollection.query(
    {tags: { $any: ["coffeescript", "backbone", "mvc"]}},
    {sortBy: "likes", order: "desc", limit:10, page:2, cache:true}
);

If I take the main part out:

{tags: { $any: ["coffeescript", "backbone", "mvc"]}},
{sortBy: "likes", order: "desc", limit:10, page:2, cache:true}

That isn't valid json. Do you have any better ideas on how to store this in a db to be used later?

I was trying to store something like the following and merge the two parts together but isn't very clean and never could get it to work well:

{"query": [{"$and": {"tags": {"$all": ["!1"]},"status": "waiting"}}],"sorting": [{"sortBy": "last_reply_at", "order": "desc"}]}

Here is an actual query that works directly just not parsing via parseJSON

{$and: {tags: { $all: ["!1"] } }}, {sortBy: "last_reply_at", order: "desc", status:"waiting"}

two or more checks on same argument

I am building my querys dynamically. Therefore It would be great if backbone_query had the ability to check two or more times on the same argument. Meaning that these are the same:

MyCollection.query({ likes: {$gte:5}, likes: {$lte:15} });

MyCollection.query({ likes: {$between:[5,15} });

I can´t get it to work. This does not work either:

MyCollection.query({
  $and:{
    likes: {$gte: 5 }, 
    likes: {$lte: 15 }
}});

Very similar to Query Engine

Very similar to Query Engine perhaps we should team up :) What are your thoughts?

Here is a comparison that I've done up:

  • Backbone Query
    • good readme documentation
    • runs on node.js and in the browser
    • supports NoSQL queries (similar to MongoDB etc)
  • Query Engine
    • includes live interactive demo
    • source-code documentation only
    • runs on node.js and in the browser
    • supports NoSQL queries (similar to MongoDB etc)
    • 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)

Combined $and and $or are not working

Basic logic is not functioning in your API, see these tests: http://jsfiddle.net/RZJcJ/

Col = new Backbone.QueryCollection [
    {diff:1, equ:'ok', same: 'ok'},
    {diff:2, equ:'ok', same: 'ok'}
]
# Should return all items, but returns nothing
Col.query
  $and:
    equ: 'ok'
    $or:
      same: 'ok'
# Should return nothing, but all items are returned:
Col.query
  equ: 'bogus'  # This item is clearly unavailable
  $or:
    same: 'ok'

Typo id docs

There is a typo in the docs.

MyCollection.query({ likes: {$between:[5,15} });

It should be

MyCollection.query({ likes: {$between:[5,15]} });

instead.

requirejs + backbone_query

I admit to not being very familiar with requirejs but I'm running into some issues trying to load up backbone_query. I'm using backbone boilerplate as a base and I'm unable to get Backbone.QueryCollection to be defined. Is there any pointers?

dynamic queries not working?

Hey,

I'm trying to create a dynamic query, but it just doesn't seem to want to work, even though the query I'm generating works when I put it in statically. No errors are being thrown... Everything works except the dynamic query.

query = {};

for(i in selected) {
if(selected.hasOwnProperty(i)) {
var terms;

    if(selected[i].indexOf(',') >= 0) {
        terms = {$all: selected[i].split(',')};
    } else {
        terms = selected[i];
    }
}

query[i] = terms;

}

result = this.collection.query(query);
console.log(result);

$elemMatch doesn't work with backbone-relational?

First off, this project is awesome.

I have data that looks like this:

courses = [
    {
        title: "Biology",
        assignments: [
            {
                done: false,
                due: "2012-03-05T05:00:00.000Z",
             },
            {
                done: false,
                due: "2012-03-05T05:00:00.000Z",
             },
            {
                done: true,
                due: "2012-03-06T05:00:00.000Z",
             }
        ]
    },
    {
        title: "Math",
        assignments: [
            {
                done: true,
                due: "2012-03-05T05:00:00.000Z",
             },
            {
                done: false,
                due: "2012-03-03T05:00:00.000Z",
             },
            {
                done: true,
                due: "2012-03-06T05:00:00.000Z",
             }
        ]
    }

So basically a collection of courses which have a list of assignments.

I'm using backbone-relational to model this; courses is a QueryCollection, the individual course model is a RelationalModel, and the individual assignment model is a RelationalModel as well.

The query I want to do is to find all of the assignments (in all courses) that are due within a specific range and are not done.

From the examples (and being somewhat familiar with Mongo -- it's what I use on the server) I think that would look like this:

courses.query({
    assignments: {
      $elemMatch: {
        "done": true,
        "date": "2012-03-05T05:00:00.000Z" 
      }
    }
  });

(I'm just matching one specific date, not a range, for simplicity purposes).

The problem is that the above query does not return anything. It seems as if it's not applying the $elemMatch criteria to the 'assignments' field of each course.

Any idea why that might be? Feel free to call me names if I'm doing something incredibly dumb here -- my brain is a bit fried from staring at my computer all day ;)

Thanks!

whereBy is making the _events array leak

the line on whereBy:

return new this.constructor(this.query(params, options));

is adding to the model _events.all, many callbacks, and the array grows until the app start to feel laggy or unresponsive. I'm not sure what would the fix be. I'm using {cache: true}, but that doesn't seem to make a difference.

Here is the reproducible test case

http://jsfiddle.net/7pfCf/15/

Toggle the items, and press the button. Each time the button is pressed, a whereBy query is performed, and another item is appended to each model _events array. So, right now, I'm having to use underscore functions instead of chaining using whereBy

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.