batmanjs/batman — pull request #1044 by Arjeno (2014-05-05 11:21:17+00:00)
Title: Batman.Query

I've extracted this behaviour from @angelini pull request for the new pagination system (which was cancelled): https://github.com/batmanjs/batman/pull/920

I'm very enthusiastic about the chainable query system which reflects ActiveRecord well. I think it would serve well in batman. Basically you can do this:

```coffeescript
Order.where(type: 'internal').limit(10)
```

You can easily set up readable scopes:

```coffeescript
class @Order extends Batman.Object
@internal: -> @where(type: 'internal')
```

I've added a bit of behavior to allow for observing query parameter changes. This can be used to alter the current URL to allow for hard refreshes.

```coffeescript
orders = Order.where(type: params.type)

orders.observe 'params', (queryParams) ->
# Do something with queryParams

orders.load (err, records) =>
@set('orders', records)
```

What do you guys think? @angelini I hope you don't mind I extracted your code. All credits go to you.