Nursery is an embeddable object-oriented database (OODB) framework for Cocoa
I am posting a series of articles on Qiita that introduce the basic usage of Nursery.(Japanese)
Nursery is published under the zlib license
I accept donations through the following services:
- Simple & Powerful
- Written in Objective-C
- Implemented ONLY with the Foundation framework of Cocoa and Core Foundation Framework (for creating sockets)
- ACID-compliant
- Lazy Loading
- Garbage Collection and Compaction in Database File
- Simultaneous Use from Multiple Processes
- Not ORM(Object-relational mapping)
- NULibrary
A collection class that implements B+ tree. - A class that implements the NUCoding protocol.
- A class that implements persistence processing by subclass of NUCoder
- NSObject
- NSString
- NSMutableString
- NSArray
- NSMutableArray
- NSDictionary
- NSMutableDictionary
- NSSet
- NSMutableSet
- NSNumber
- NSDate
- NSURL
- NSData
- NSMutableData
- NSIndexSet
- NSMutableIndexSet
#import <Nursery/Nursery.h>
NUMainBranchNursery *aNursery = [NUMainBranchNursery nurseryWithContentsOfFile:@"path/to/file"];
NUGarden *aGarden = [aNursery makeGarden];
[aGarden setRoot:@"Hi, I'm Nursery"];
[aGarden farmOut];
#import <Nursery/Nursery.h>
NUMainBranchNursery *aNursery = [NUMainBranchNursery nurseryWithContentsOfFile:@"path/to/file"];
NUGarden *aGarden = [aNursery makeGarden];
Person *aPerson = [Person new];
[aPerson setFirstName:@"Akifumi"];
[aPerson setLastName:@"Takata"];
[aGarden setRoot:aPerson];
[aGarden farmOut];
// Person Class
@interface Person : NSObject <NUCoding>
{
NSString *firstName;
NSString *lastName;
}
@property (weak) NUBell *bell;
- (NSString *)firstName;
- (void)setFirstName:(NSString *)aFirstName;
- (NSString *)lastName;
- (void)setLastName:(NSString *)aLastName;
@end
@implementation Person
+ (BOOL)automaticallyEstablishCharacter
{
return YES;
}
+ (void)defineCharacter:(NUCharacter *)aCharacter on:(NUGarden *)aGarden
{
[aCharacter addOOPIvarWithName:@"firstName"];
[aCharacter addOOPIvarWithName:@"lastName"];
}
- (void)encodeWithAliaser:(NUAliaser *)anAliaser
{
[anAliaser encodeObject:firstName forKey:@"firstName"];
[anAliaser encodeObject:lastName forKey:@"lastName"];
}
- (instancetype)initWithAliaser:(NUAliaser *)anAliaser
{
self = [super init];
if (self)
{
firstName = [anAliaser decodeObjectForKey:@"firstName"];
lastName = [anAliaser decodeObjectForKey:@"lastName"];
}
return self;
}
- (NSString *)firstName
{
return NUGetIvar(&firstName);
}
- (void)setFirstName:(NSString *)aFirstName
{
NUSetIvar(&firstName, aFirstName);
[[self bell] markChanged];
}
- (NSString *)lastName
{
return NUGetIvar(&lastName);
}
- (void)setLastName:(NSString *)aLastName
{
NUSetIvar(&lastName, aLastName);
[[self bell] markChanged];
}
@end
macOS (10.13 or higher)
- Click "Open in Xcode" on project page and clone to (For Example) your Desktop
- Select "Edit Scheme..." < "Scheme" < "Product" in menubar
- Select "Run" in left pane and change "Build Configuration" to "Release" then click "Close" button
- Select "Build" < "Product" in menubar
Instance variables are converted to big endian at the time of encoding and converted to host endian at the time of decoding
Loading and saving objects is thread-safe.
However, there is no guarantee that other processing is thread-safe
Nursery supports simultaneous use with multiple processes
Nursery implements write-ahead logging (WAL)
Objects that can not be traced from the root object of Nursery are automatically released by GC.
GC can handle circular references correctly.
GC implements garbage collection with Tri-color marking.
The released area is compacted
Bug fixes are welcome