An Objective-C database abstraction framework.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DatabaseKit.xcodeproj Made collection category private again, broke module header Feb 3, 2015
Source Enforced relationship join row uniqueness Feb 4, 2015
Tests Added error: to transaction: Feb 4, 2015
en.lproj Made inflections compiled in, to get rid of the only external depende… Sep 25, 2012
.gitattributes Gitignore&stuff Jul 25, 2008
.gitignore
Doxyfile Updated doxyfile Dec 17, 2014
Info.plist Renamed project to DatabaseKit Sep 24, 2012
LICENSE Removed remaining references to old name Sep 25, 2012
README.md Removed setClassPrefix: it's now automatically determined Dec 15, 2014

README.md

DatabaseKit ReadMe

About:

DatabaseKit is an unbelievably straight-forward to use database framework for Objective-C.

Features:

  • Supports SQLite, but is built to make it easy to add support for additional SQL databases, just subclass DBConnection.
  • Query composition done purely in Objective-C.
  • If you use a connection pool or queue(Done transparently by default) then query objects are thread safe.
  • If you provide a model class, then results from it's corresponding table will automatically be returned as instances of that class.
  • Supports creating and migrating tables for model classes at runtime.
  • Almost no code required.

Examples

Connecting:

// Open a SQLite database
DB *db = [DB withURL:[NSURL URLWithString:@"sqlite://myDb.sqlite"]];
if(err)
    NSLog(@"Couldn't open database: %@.", [err localizedDescription]);

Querying:

// Get the names of every person in our database
DBTable *people = db[@"people"];
DBSelectQuery *names = [people select:@"name"];

for(NSDictionary *row in [names limit:100]) {
    NSLog(@"Name: %@", row[@"name"]);
}

// Delete really old people
[[[people delete] where:@"bornOn < %@", [NSDate distantPast]] execute];

// Change the name of everyone called John
[[[people update:@{ @"name": @"Percie" }] where:@"name = %@", @"John"] execute];

// You can create a class to represent results from a table like so:
// (Our project's class prefix is `NICE`)
@interface NICEPerson : DBModel
@property(readwrite, retain) NSString *name, *address;
- (void)introduceYourself;
@end

@implementation NICEPerson
- (void)introduceYourself
{
    NSLog(@"Hi! I'm %@.", self.name);
}
@end

// And now if you perform a query
NicePerson *someone = [[people select] firstObject];
[someone introduceYourself];