iOS中數(shù)據(jù)庫(kù)使用什么技術(shù)實(shí)現(xiàn)的

使用Sqlite和CoreData實(shí)現(xiàn)的

常用數(shù)據(jù)庫(kù):

  SQLServer 2000—保存游戲的素有用戶的信息;
  OracleMySQL—網(wǎng)上PHP網(wǎng)站室友較多,特點(diǎn)是網(wǎng)路數(shù)據(jù)庫(kù),支持的功能多,程序比較大。

移動(dòng)開發(fā)常用:

Sqlite數(shù)據(jù)庫(kù):
  特點(diǎn):足夠小,足夠快(本地?cái)?shù)據(jù)庫(kù)),使用比較簡(jiǎn)單;
  常用軟件:MesaSqlite數(shù)據(jù)庫(kù)操作軟件;
  數(shù)據(jù)庫(kù)操作語(yǔ)言:SQL(結(jié)構(gòu)和查詢語(yǔ)言);
  常用開源庫(kù):FMDB。
CoreData是iOS開發(fā)中經(jīng)常用的數(shù)據(jù)持久化的技術(shù)。但其操作過(guò)程稍微繁瑣,即使你只是實(shí)現(xiàn)簡(jiǎn)單的存取,不涉及請(qǐng)求優(yōu)化,也要進(jìn)行許多配置工作,代碼量動(dòng)輒幾十行,對(duì)新手來(lái)說(shuō)也需要較大時(shí)間成本。
MagicalRecord是OC的一個(gè)庫(kù),協(xié)助CoreData的工作。其吸收了Ruby on Rails 的Active Record模式,目標(biāo)是:假話CoreData相關(guān)代碼,允許清晰,簡(jiǎn)單,單行獲取,當(dāng)需要優(yōu)化請(qǐng)求的時(shí)候,仍然允許修改NSFetchRequest.
CoreData的用法:
 創(chuàng)建Model:創(chuàng)建一個(gè)Model.xcdatamodeld,添加一個(gè)Person Entity,添加age firstname,lastname三個(gè)屬性,最后時(shí)候用Editor >Create NSManagerdObject Subclass ORM生成Person類。
初始化:在AppDelegate中:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
     [MagicalRecord setupCoreDataStackWithStoreNamed:@"Model.sqlite"];
     return YES;
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
      [MagicalRecord cleanUp];
}
這樣初始化就完成
增加數(shù)據(jù):
 Person *person = [Person MR_createEntity];
 person.firstname = @"Frank";
 person.lastname = @"Zhang";
 person.age = @26;
 [[NSManagedObjectContext MR_defaultContext] MR_save];
查找數(shù)據(jù):
  //查找數(shù)據(jù)庫(kù)中的所有Person。
  NSArray *persons = [Person MR_findAll];
 //查找所有的Person并按照f(shuō)irst name排序。
 NSArray *personsSorted = [Person MR_findAllSortedBy:@"firstname" ascending:YES];
 //查找所有age屬性為25的Person記錄。
NSArray *personsAgeEuqals25   = [Person MR_findByAttribute:@"age" withValue:[NSNumber numberWithInt:25]];
//查找數(shù)據(jù)庫(kù)中的第一條記錄
Person *person = [Person MR_findFirst];
修改數(shù)據(jù):
Person *person = ...;//此處略
person.lastname = object;
[[NSManagedObjectContext MR_defaultContext] MR_save];
刪除數(shù)據(jù):
Person *person = ...;//此處略
[person MR_deleteEntity];
[[NSManagedObjectContext MR_defaultContext] MR_save];

更多的:

MagicalRecord 官方
Magical Record入門教程
Using CoreData with MagicalRecord
Magical Record: how to make programming with Core Data pleasant
來(lái)自:http://www.cnblogs.com/mybkn/p/3328183.html
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容