| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

iOS数据库:canDB.swift

canDB.swift 是一个框架,作用类似 nonSQL 的数据库,但运作在 sqlite(FMDB) 。

canDB.swift uses sqlite (via FMDB) but it works like a nonSQL database. Just put the json into the can and retrieve it as a dictionary. Easy as pie.

    // loading the json      let filePath = NSBundle.mainBundle().pathForResource("data", ofType:"json")    let data = NSData(contentsOfFile:filePath!, options:NSDataReadingOptions.DataReadingUncached, error:nil)    let dataArray:Array = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.allZeros, error: nil) as! Array<Dictionary<String, String>>         // singleton instance      let storeInstance = canDB.sharedInstance    // saving the data, the can is automatically created if not exists      storeInstance.saveData("Person", data: dataArray, idString: kCanDBDefaultIdString, error: nil)    // adding the index for future queries and reindexing the table      storeInstance.addIndex("Person", indexes: ["Name"], error: nil)      storeInstance.reIndex("Person", idString: kCanDBDefaultIdString)    let result = storeInstance.loadData("Person")    for item in result {        for (key, value) in (item as! NSDictionary) {              println("\(key): \(value)")          }      }    // custom query using the previous created index "Name"      let resultWithQuery = storeInstance.loadDataWithQuery("SELECT * FROM Person WHERE Name='John'")    for item in resultWithQuery {        for (key, value) in (item as! NSDictionary) {              println("\(key): \(value)")          }      }         storeInstance.removeDataForId("Person", idString: kCanDBDefaultIdString, idsToDelete: ["17", "19"], error: nil)

项目主页:http://www.open-open.com/lib/view/home/1437535442849

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1437535442849.html
IOS iOS开发 移动开发