SwiftFFDB 2.3

SwiftFFDB 2.3

测试已测试
语言语言 SwiftSwift
许可证 Apache-2.0
发布日期最后发布2021年2月
SPM支持 SPM

Fidetro--verbose 维护。



  • fidetro

SwiftFFDB

中文文档


SwiftFFDB 是一个支持 iOS 和 Perfect-Server 库的对象/关系映射(ORM)。由于 SwiftFFDB 是基于 FMDB 构建的。
如果您使用 Objective-C,则可以使用 FFDB

Wiki

wiki 中有更多用法示例(未完成)

需求

iOS

  • 构建 Swift5.0 版本的工具链
  • 在 iOS 8 或更高版本上部署
  • 依赖 FMDB

安装

CocoaPod

可以使用 CocoaPod 安装 SwiftFFDB

$ vim Podfile

然后,编辑 Podfile,添加 SwiftFFDB

platform :ios, '8.0'
target 'YouApp' do
use_frameworks!
pod 'SwiftFFDB'
end

用法

设置

如果你在 iOS 上使用,可以查看 示例项目

Person.registerTable() //create table

创建

创建表的模型可能像这样

struct Person:FFObject {
    var primaryID: Int64?
    
    var name : String?
    
    static func ignoreProperties() -> [String]? {
        return nil
    }
    
    static func customColumnsType() -> [String : String]? {
        return nil
    }
    
    static func customColumns() -> [String : String]? {
        return nil
    }

    static func autoincrementColumn() -> String? {
        return "primaryID"
    }
}

插入

var person = Person()
person.name = "fidetro"
person.insert()

选择

// find all Object
Person.select(where: nil)
// find name is 'fidetro' 
Person.select(where: "name = 'fidetro'")

更新

// update name is 'fidetro' to 'ffdb'
Person.update(set: "name = ?", where: "name = ?", values: ["ffdb","fidetro"])  

删除

// find name is 'fidetro' 
let personList = Person.select(where: "name = 'fidetro'")

for (let person in personList){
    // delete this person in database
    person.delete()
}

您还可以

FFDBManager.delete(Person.self, where: "name = 'fidetro'")

架构

支持

SwiftFFDB是一个个人开源项目,但我很乐意在问题中回答问题或通过电子邮件至[email protected]