BRDocBase update
| April 17th, 2010A whole mess of updates for BRDocBase. My simple little framework is somewhat less simple unfortunately. ###iPhone Support As I’m working on CrankTunes for iPhone, I had to make a few changes internally. I was using blocks in a couple of places and had a few other very minor changes (like including Foundation rather than Cocoa). I was happy with how easy this was.
SQLite storage
The strategy for storing documents is now in it’s own class, and determined by the docbase config file. With this I added a class to store documents in a SQLite database. Originally I wanted to use Tokyo Cabinet, however after further looking at the LGBL issues, I realized it’s not really feasible for an iPhone application. So I went with SQLite instead, basically using it as a simple key-value storage mechanism.
There are now 3 different local storage mechanisms: my initial hash file storage, SQLite storage, and a simple single file storage. Really, if ‘present me’ could go back and talk to ‘past me’, I probably wouldn’t have written the hash file storage. I wanted something that was easy to view in a text editor for development/testing purposes. It’s not bad, but a single file is much better and SQLite is a better form for release.
In a premature optimization (since I don’t think I really need it yet), I also added support for document indexing. It’s only implemented in SQLite storage and probably will never be in either of the other storage formats. I mostly did it out of curiosity to see how I can detect the appropriate fields in an NSPredicate and use them if possible in a query. It’s still very basic support but it works. I added a few class methods to NSPredicate simply to assist in building predicates that utilize the indexes.
Syncing
A fourth storage mechanism was added as well: remote storage. Along with it there is a sync server that will work with it. All this is very preliminary but it will sync documents between a client and server. The server is currently Mac only since it uses NSSocketPort, but I think it’ll be an easy change to use CFSocket instead to get it working on iPhoneOS. The sync client is currently pretty draconian about any change conflicts. Right now the later change always wins. If the change dates happen to be equal, the server version is used. Eventually a delegate will be used to allow the app to decide what to do about conflicts. The server uses Bonjour to advertise itself, and there’s no form of authentication built in, so running it allows anyone on the local network to access the served docbase.
Other Stuff
There’s probably a bunch of other small changes that went in that I’m not thinking of right now. One thing I did want to highlight is class extensions. I’m trying to be somewhat careful about what classes I add categories to. Right now 3 framework classes are extended. NSMutableDictionary has methods to make it conform to the BRDocument protocol, as well as a convenience constructor to build a proper document dictionary (adding the document id, document type, and modification date automatically). NSDate has methods to format dates in a docbase-friendly format. Mostly this is for SQLite, since it seems to like UTC times without the addition of a timezone offset. And, as I mentioned earlier, NSPredicate has some methods to build predicates that are more likely to hit indexes.
So that’s it. Like I mentioned, it’s no longer a simple 1 or 2 files, but I’m pretty happy with it so far. I was especially excited to have it running on the iPhone and syncing with documents on the Mac.