| 注册
请输入搜索内容

热门搜索

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

纯 Swift 封装的 SQLite 框架:SQLite.swift

SQLite.swift 是一个使用纯 Swift 语言封装 SQLite3 的操作框架。

特性:

  • 简单的查询和参数绑定接口

  • 安全、自动类型数据访问

  • 隐式提交和回滚接口

  • 开发者友好的错误处理和调试

  • 文档完善

  • 通过广泛测试

纯 Swift 封装的 SQLite 框架:SQLite.swift

示例代码:
import SQLite     let db = Database("path/to/db.sqlite3")     db.execute(      "CREATE TABLE users (" +          "id INTEGER PRIMARY KEY, " +          "email TEXT NOT NULL UNIQUE, " +          "manager_id INTEGER, " +          "FOREIGN KEY(manager_id) REFERENCES users(id)" +      ")"  )     let stmt = db.prepare("INSERT INTO users (email) VALUES (?)")  for email in ["alice@example.com", "betsy@example.com"] {      stmt.run(email)  }     db.totalChanges // 2  db.lastChanges  // {Some 1}  db.lastID       // {Some 2}     for row in db.prepare("SELECT id, email FROM users") {      println(row)      // [Optional(1), Optional("betsy@example.com")]      // [Optional(2), Optional("alice@example.com")]  }     db.scalar("SELECT count(*) FROM users") // {Some 2}     let jr = db.prepare("INSERT INTO users (email, manager_id) VALUES (? ?)")  db.transaction(      stmt.run("dolly@example.com"),      jr.run("emery@example.com", db.lastID)  )

安装

Note: SQLite.swift requires Swift 1.1 (available in Xcode 6.1).

To install SQLite.swift:

  1. Drag the SQLite.xcodeproj file into your own project. (Submodule, clone, or download the project first.)

    installation@2x.png

  2. In your target’s Build Phases, add SQLite iOS (or SQLite Mac) to the Target Dependencies build phase.

  3. Add the appropriate SQLite.framework product to theLink Binary With Libraries build phase.

  4. Add the same SQLite.framework to a Copy Files build phase with aFrameworks destination. (Add a new build phase if need be.)

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

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