Permalink
Browse files

Updated documentation

Made AMD compliant (thanks @Rob--W)
Added tests for new features
Updated CAKE file
  • Loading branch information...
Dave Tonge
Dave Tonge committed Sep 17, 2012
1 parent bfb0ca5 commit 141d491e912d07b2b74c00c83bc298322e6eb758
Showing with 940 additions and 767 deletions.
  1. +2 −1 .gitignore
  2. +2 −5 Cakefile
  3. +1 −1 LICENSE
  4. +21 −5 README.md
  5. +0 −352 js/backbone-query.js
  6. +0 −1 js/backbone-query.min.js
  7. +459 −0 lib/backbone-query.js
  8. +1 −0 lib/backbone-query.min.js
  9. +1 −1 package.json
  10. +304 −299 src/backbone-query.coffee
  11. +149 −102 test/bq-test.coffee
View
@@ -1,3 +1,4 @@
# Idea IDE files
.idea/
-node_modules/
+node_modules/
+backbone_query.iml
View
@@ -213,9 +213,6 @@ mocha = (options, callback) ->
if typeof options is 'function'
callback = options
options = []
- # add coffee directive
- options.push '--coffee'
- options.push 'coffee:coffee-script'
launch 'mocha', options, callback
@@ -232,11 +229,11 @@ task 'uglify', 'Minify and obfuscate', ->
jsp = uglify.parser
pro = uglify.uglify
- contents = fs.readFileSync "js/backbone-query.js", 'utf8'
+ contents = fs.readFileSync "lib/backbone-query.js", 'utf8'
ast = jsp.parse contents # parse code and get the initial AST
ast = pro.ast_mangle ast # get a new AST with mangled names
ast = pro.ast_squeeze ast # get an AST with compression optimizations
final_code = pro.gen_code ast # compressed code here
- fs.writeFile 'js/backbone-query.min.js', final_code
+ fs.writeFile 'lib/backbone-query.min.js', final_code
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Dave Tonge
+Copyright (c) 2012 Dave Tonge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
@@ -21,10 +21,14 @@ You can install with NPM: `npm install backbone-query`
Then simply require in your project: `QueryCollection = require("backbone-query").QueryCollection`
-Your collections will now have two new methods: `query` and `where`. Both methods accept 2 arguments -
-a query object and an options object. The `query` method returns an array of models, but the `where` method
+Your collections will now have two new methods: `query` and `whereBy`. Both methods accept 2 arguments -
+a query object and an options object. The `query` method returns an array of models, but the `whereBy` method
returns a new collection and is therefore useful where you would like to chain multiple collection
-methods / where queries (thanks to @cezary). The following are some basic examples:
+methods / whereBy queries (thanks to @cezary).
+
+The library also supports nested compound queries and is AMD compatible (thanks to @Rob--W).
+
+The following are some basic examples:
```js
MyCollection.query({
@@ -71,14 +75,14 @@ MyCollection.query
colors: $contains: "yellow"
```
-Another CoffeeScript example, this time using `where` rather than `query`
+Another CoffeeScript example, this time using `whereBy` rather than `query`
```coffeescript
query =
$likes: $lt: 10
$downloads: $gt: 20
-MyCollection.where(query).my_custom_collection_method()
+MyCollection.whereBy(query).my_custom_collection_method()
```
@@ -351,6 +355,18 @@ MyCollection.query({ $not: { title: {$like: "News"}, likes: {$gt: 10}}});
// Returns all models that don't contain "News" in the title AND DON'T have more than 10 likes.
```
+If you need to perform multiple queries on the same key, then you can supply the query as an array:
+```js
+MyCollection.query({
+ $or:[
+ {title:"News"},
+ {title:"About"}
+ ]
+});
+// Returns all models with the title "News" or "About".
+```
+
+
Compound Queries
================
Oops, something went wrong.

0 comments on commit 141d491

Please sign in to comment.