Resources for updating to Current CBL from 1.2

Hello, I recently inherited a project that has been neglected for some time. It was running on, as far as I can tell, CBL 1.2. I’m trying to update to the current version since there are some reliability issues with the current syncing.

As a preface I’m very new to Couchbase, and am currently still in college so I’m not very experienced either.

The current software uses CBLModels, CBLManager, and CBLMapEmitBlocks. These all seem to be deprecated. I have started going through the documentation and found and old forum post about an alternative to CBLModels.

It seems to me like I’m going to need to rewrite a lot of the Couchbase Code and am wondering if there are any more recent example programs out there that use a Model structure and if that is even a viable way to program with current CBL.

The program is basically an inventory tracker that has different items like a hammer, nail, drill, etc where each item shares some properties but not all, and where some items are children to other items.

Sorry that became a wall of text and I don’t know if this is really an answerable question, but any advice is much appreciated.

CBL 2 is a rewrite with a significantly different API.

The methods of CBLManager are mostly class methods of CBLDatabase now; it should be pretty clear how they correspond.

The whole map/reduce view mechanism has been replaced by queries and indexes. The query API uses a ‘builder’ design pattern, but the high level structure of a query is based on N1QL, which is (more or less) an extension of SQL. Similarly, indexes work pretty much the way they do in SQL.

There’s no equivalent of CBLModel; that’s one of those things we’ve wanted to re-implement but hasn’t made it to the top of the feature list. (Plus the fact that it would have to have a different API and implementation on each platform.)

You could implement your own model class without too much trouble, I think; most of the complexity of CBLModel was from making its properties feel exactly like native Obj-C properties, and if you give that up it’s a lot simpler to do. One difference in CBLDocument you’ll need to pay attention to is that in 1.x a document was “live”: the contents of a document always reflected the current values in the database. In 2.x a CBLDocument is a snapshot taken at the time it was created, so if you want the new state of a document you need to get a new instance in response to a document-changed notification.

I hope that helps!

In addition to what Jens said, here are some resources on 2.x .

  • Blog on migration from 1.x . This is for Android but applies to iOS as well. There are some minor glitches in that blog but it is a good starting point to get the lay of the land.
  • 2.x tutorials. They don’t cover how you’d implement your own document object mapper but hope they help with the core concepts