开发者

ORM on iPhone. More simple than CoreData

开发者 https://www.devze.com 2022-12-29 11:58 出处:网络
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.

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开发者_StackOverflow中文版 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.


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?


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.


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.


Take a look at BNRPersistence.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号