ANN: CBLQueryBuilder for iOS

498 views
Skip to first unread message

Jens Alfke

unread,
Dec 16, 2014, 5:24:03 PM12/16/14
to mobile-c...@googlegroups.com
There's a new higher-level query API available on the master branch of the Couchbase Lite/iOS repo, targeted at the 1.1 release: the CBLQueryPlanner class. (An earlier version of this was provided as an unsupported extra in 1.0.3.) It's something like Core Data's NSFetchRequest: you use Cocoa classes NSPredicate and NSExpression to specify what you want to find, and CBLQueryPlanner creates a view, sets its map and reduce functions, and configures the CBLQuery.

I've written documentation, and tried to make it polished so you can get up to speed easily.

Here's an example taken from the docs:
    self.tagQueryBuilder = [[CBLQueryBuilder alloc]
            initWithDatabase: self.database
                      select: @[@"title", @"body", @"author", @"date"]
                       where: @"type == 'post' and tags contains $TAG"
                     orderBy: @[@"-date"]
                       error: &error];
Then to run the query you just do:
    CBLQueryEnumerator* e = [self.tagQueryBuilder runQueryWithContext: @{@"TAG": tag}
                                                                error: &error];

CBLQueryPlanner can't do everything you can do with map/reduce, and there's no reason to stop using map/reduce if you like it; this is just a convenient higher-level interface that should be more familiar to many developers.

If you're willing to build from the master branch, we'd really appreciate it if you could try this out and give feedback.

—Jens

PS: This API is very platform-specific because it's based on Cocoa classes. We plan to support the same functionality on other platforms, using their idioms — on .NET we'll base it on LINQ, for example.

CouchbaseLover

unread,
Dec 19, 2014, 3:57:14 AM12/19/14
to mobile-c...@googlegroups.com
Nice, also good documentation! :)
Reply all
Reply to author
Forward
0 new messages