CBL Model Generator

63 views
Skip to first unread message

Ragu Vijaykumar

unread,
Apr 19, 2014, 9:54:53 PM4/19/14
to mobile-c...@googlegroups.com
Since I ask so many questions, I decided to contribute something back to the community! :-) I wrote a Couchbase Model Generator for those that are interested, hosted here: https://github.com/RVijay007/cblmodelgenerator.

Basically, you can layout your data model in a Core Data - Data Model File (*.xcdatamodel) following simple instructions in the README, and run the command line utility on the file to autogenerate all your CBLModels (and CBLNestedModels if you use my fork for couchbase-lite-ios). You can even store versions using the CoreData versioning system, and it will always process whichever model you specify to be the current version in that file.

A sample CoreData model file that serves as an example and that can be run with this this utility can be found in my example repo: https://github.com/RVijay007/CBLNestedModelExample. There is a *.xcdatamodel file in CBLNestedModelExample/CBLNestedModelTest.

Please ask me if you have any questions about it and enjoy!

Cheers,
Ragu

Jens Alfke

unread,
Apr 19, 2014, 10:32:48 PM4/19/14
to mobile-c...@googlegroups.com
Wow, that is really cool! The Xcode Core Data model editing UI is pretty slick, and it’ll be nice to use that with Couchbase Lite. Thanks for contributing this.

—Jens

Ragu Vijaykumar

unread,
Apr 21, 2014, 2:02:22 AM4/21/14
to mobile-c...@googlegroups.com
Thanks for the encouragement. I added some functionality to aid in model generation that hopefully others will find useful.

-- Now you can alternatively define entities as CBLModels by checking the Abstract Entity box of the entity. Unchecked boxes with no parents will default to CBLNestedModels. This negates the necessity to always create a CBLModel/CBLNestedModel entity in your Core Data file and keeps the model file cleaner.
-- All CBLModels define their "type" property as the name of the entity if you use the "initWithNewDocumentInDatabase" initializer.
-- The tool creates a separate file that is named YourCoreDataModelNameModelFactory, which defines a single class method "registerModelWithCBLModelFactory". You can call this method in your AppDelegate once and all the CBLModels in your CoreData model will have their types registered with the model factory.

Cheers,
Ragu
Reply all
Reply to author
Forward
0 new messages