aaronpowell/db.js — pull request #5 by aaronpowell (2012-09-26 02:49:13+00:00)
Title: Query refactor

With the addition of the support for `IDBKeyRange` querying db.js ended up with two separate ways to query, you could:

server.query( 'table' ).execute( ... )

or

server.index( 'table', 'indexName' )...

Internally this made the codebase ugly and confusing as to when you would use one over the other.

I've done a consolidation of this into a single API, like so:

server.query( 'table' , 'optional index name')

To do a unrestricted query you would do:

server.query( 'table' ).all().done(...)

Or adding a filter:

server.query( 'table' ).filter( fn ).done( ... )

Range queries still work the same, except you now have to explicitly execute the query:

server.query( 'table' , 'index' ).only( 'foo' ).execute().done( ... )

You can also perform a `count` or an `openKeyCursor` style query:

server.query( 'table' , 'index' ).only( 'foo' ).count().done( ... )
server.query( 'table' , 'index' ).only( 'foo' ).keys().done( ... )

All tests have been updated to the new API as well, would love feedback before merging it in.