纯 Swift 封装的 SQLite 框架:SQLite.swift
SQLite.swift 是一个使用纯 Swift 语言封装 SQLite3 的操作框架。
特性:
-
简单的查询和参数绑定接口
-
安全、自动类型数据访问
-
隐式提交和回滚接口
-
开发者友好的错误处理和调试
-
文档完善
-
通过广泛测试
示例代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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:
-
Drag the SQLite.xcodeproj file into your own project. (Submodule, clone, or download the project first.)
-
In your target’s Build Phases, add SQLite iOS (or SQLite Mac) to the Target Dependencies build phase.
-
Add the appropriate SQLite.framework product to theLink Binary With Libraries build phase.
-
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
https://github.com/stephencelis/SQLite.swift
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)