CBLIncrementalStore

111 views
Skip to first unread message

Todd Freese

unread,
Mar 11, 2014, 1:23:20 PM3/11/14
to mobile-c...@googlegroups.com
Just wondering what are the advantages and disadvantages of using Core Data as CBL's datastore? Doesn't Core Data use SQLite under the hood as well?

Just curious.

Todd

Jens Alfke

unread,
Mar 11, 2014, 2:13:53 PM3/11/14
to mobile-c...@googlegroups.com

On Mar 11, 2014, at 10:23 AM, Todd Freese <to...@filmworkers.com> wrote:

Just wondering what are the advantages and disadvantages of using Core Data as CBL's datastore?

Actually it’s the other way around: CBLIncrementalStore allows you to use Couchbase Lite as Core Data’s data store. Meaning that you can write your app using (mostly) Core Data APIs, if that’s what you prefer, and still get the benefits of really good sync.

—Jens

Ragu Vijaykumar

unread,
Apr 10, 2014, 8:45:00 AM4/10/14
to mobile-c...@googlegroups.com
I was wondering how fetchs work when using the CBLIncremental store. Aren't the NSPredicates written via SQL logic? Is there any specific way we should write filters in NSPredicate for NSFetchRequests for use with the CBL backend? Thanks for your help!

Ragu

Jens Alfke

unread,
Apr 10, 2014, 10:12:14 AM4/10/14
to mobile-c...@googlegroups.com

On Apr 10, 2014, at 5:45 AM, Ragu Vijaykumar <ra...@scrxpt.com> wrote:

I was wondering how fetchs work when using the CBLIncremental store. Aren't the NSPredicates written via SQL logic? Is there any specific way we should write filters in NSPredicate for NSFetchRequests for use with the CBL backend? Thanks for your help!

I haven’t used that class, and I’ve only looked through the source code once, but I remember that it only implements a subset of the full functionality of NSPredicate. You might want to look at the source; it’s in one file and the sections are pretty clearly grouped using “#pragma mark” lines. The sections on “NSPredicate”, “Querying” and “Views” are especially interesting.

Looks like one of the limits is that it only supports NSExpression types NSConstantValueExpressionType, NSEvaluatedObjectExpressionType, NSKeyPathExpressionType, with a comment:
    // not supported yet:
    //    NSFunctionExpressionType,
    //    NSAggregateExpressionType,
    //    NSSubqueryExpressionType = 13,
    //    NSUnionSetExpressionType,
    //    NSIntersectSetExpressionType,
    //    NSMinusSetExpressionType,
    //    NSBlockExpressionType = 19

It will automatically generate views for querying a specific property of a specific entity type. I think what happens is that it uses the view for basic filtering, and then any further processing in an NSFetchExpression happens at runtime by testing every matching doc against the predicate and then evaluating the expression.

Hopefully the author (Christian Beer) is reading this and can give more insight :)

—Jens

Christian Beer

unread,
Apr 11, 2014, 10:05:21 AM4/11/14
to mobile-c...@googlegroups.com
The CBLIncrementalStore analyses the NSPredicate used in a fetchRequest and, like Jens said, tries to use views as much as possible, before analyzing the data itself.

Not all expression types are supported as some are rather special. I used it in a complex project (my vocabulary trainer) for a test and all worked well... so I think most use cases should be covered.

The SQLite persistent storage does the same and creates SQL selects, just as we use the views.

This is an area where performance is key. Maybe somebody with a deeper CouchbaseLite knowledge could improve it further?
Reply all
Reply to author
Forward
0 new messages