canDB.swift 介绍
canDB.swift 是一个框架,作用类似 nonsql 的数据库,但运作在 sqlite(FMDB) 。
// 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)
canDB.swift 官网
https://github.com/colatusso/canDB.swift
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。