测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布上次发布 | 2017年3月 |
SwiftSwift 版本 | 3 |
SPM支持 SPM | ✗ |
由 Pawel Bednorz 维护。
Realm 查询扩展
// Simple class
class Foo: Object {
dynamic var bar = ""
}
// Conform to protocol
extension Foo: Queryable {}
// Create simple object
let foo = Foo()
foo.bar = "something"
// Save objec
foo.add()
// Update object
foo.update(transaction: {
foo.bar = "something other"
}, completion: nil)
// Remove object
foo.remove()
// Fetch all objects
_ = Foo.arrayOfObjects
// Realm results
_ = Foo.resultsOfObjects
// Fetch filtred array
_ = Foo.filtredArray("bar == 'something'")
// Fetch filtred results
_ = Foo.filtredResults("bar == 'something'")
Queryable 还提供了 DBManager,该工具提供通用方法
// Fetching objects
public class func getObjects<T: Object>(of entity: T.Type, filter: String? = nil) -> [T]
// Add
public class func add(object: Object) -> Bool
//Update
public class func update(transaction: @escaping ()->()) -> Bool
//Remove
public class func remove(object: Object) -> Bool
public class func removeAll() -> Bool