maccman/spine — pull request #295 by bn1 (2012-05-06 18:21:05+00:00)
Title: queryset

it's a bit hacky, but it should be only a showcase of benefits of chaining filters. Now you can use it like:

```coffee
Model.select().select()..
```

It's handy with other methods like:

```coffee
drop: (options={}) ->
@destroyAll options
@deleteAll()
```

```coffee
__filter: (args, revert=false) ->
(rec) ->
f = !!revert

for key, value of args
return f unless rec[key] is value

return !f

filter: (args) -> @select @__filter args, false
exclude: (args) -> @select @__filter args, true
```

```coffee
order_by: (key) ->
if $.isArray(key)
ref = @
for k in key.reverse()
ref = ref.order_by(k)

ref

else
@all().sort((x, y) ->
result = 1

if key[0] is '-'
key = key[1..]
result = -1

result *= -1 if x[key] < y[key]

result = 1 if x[key] is null #vyřešit jinak
result = -1 if x[key] is null #vyřešit jinak

result = 0 if x[key] is y[key]

return result
)
```

etc. with that, you can for example simple delete selected items of model `Model.filter(key: value).drop()` ..it will dropped (destroy) all `items`, where `item.key == value`