views:

82

answers:

4

The question is rather simple. I know that there is SQLite. There is Core Data also. But I need something in between. More object-oriented than SQLite API and simplier than Core Data.

Main points are:

  • I need access to stored entities only by id. No queries required.
  • I need to store items of a single type, it means that I can use only one table if I choose SQLite.
  • I want automatic object-relational conversion. Or object-storage if the storage is not relational.

I can use object archiving, but I have to implement things (NSArchiver).

But I want to write some kind of class and get persistence automatically. As it can be done with Hibernate/ActiveRecord/Core Data/etc.

Thanks.

A: 

Take a look at BNRPersistence.

Alex Reynolds
Thanks. But as I can see, I have to create something similar to archiver's encodeObject/decodeObject methods. I'd like to have something model-based instead. Anyway, interesting possibility, thanks.
Alexander Babaev
A: 

Beyond BNRPersistence, which Alex points out, I don't think you're going to find anything that maintains object relationships, yet is simpler than Core Data on the Cocoa platforms. An object wrapper around SQLite like FMDB still requires you to manage relationships in your own code.

Maintaining relationships between objects is a non-trivial task, which is why you see so few of these frameworks out there. Core Data gets it right for many people, so there isn't that much motivation among developers to build an alternative to Apple's solution. BNRPersistence was created out of Aaron Hillegass' long-time frustration with certain aspects of Core Data, but many people (like me) are perfectly happy with the way Core Data does what it does.

You might also want to look at Core Resource, a newer framework that provides some wrappers around Core Data to make common tasks easier.

Brad Larson
Well, I do not need any relations right now. I've only one entity and I don't want to write serialization code. I'm looking for something like: I write object structure and send save message. And it determines how to save and what to save by itself. Anyway, thanks for the resources. I already know about FMDB, but Core Resource is new for me and I'll look at it.
Alexander Babaev
A: 

You might consider a non-Objective-C approach to serializing objects, just as XML or JSON, where you don't have to write serialization code, if you don't want to, because the framework does it for you. For example, put your objects into a key-value attribute pairing with NSDictionary (via a wrapper class or whatever) that points to another record's id key, and then encode the mess with json-framework's JSONRepresentation call. You'd probably need to do your own relationship integrity tests, but voila, instant relational database.

Alex Reynolds
Interesting. Not exactly what I want but very useful for another project. Thanks.
Alexander Babaev
+1  A: 

Everything you've said you want here is completely compatible with Core Data. Apple's giving you a solution that meets your stated needs exactly, so why are you trying to avoid it?

Tom Harrington