Sqlite.swift is an operating framework that encapsulates SQLite3 using the pure Swift language.
Characteristics:
-
Simple query and parameter binding interface
-
Secure, automated type of data access
-
Implicit commit and rollback interfaces
-
Developer-friendly error handling and debugging
-
Document Perfection
-
Through extensive testing
Example code:
?
| 1234567891011121314151617181920212223242526272829303132333435 |
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 ["[email protected]", "[email protected]"] { stmt.run(email)} db.totalChanges // 2db.lastChanges // {Some 1}db.lastID // {Some 2} for row in db.prepare("SELECT id, email FROM users") { println(row) // [Optional(1), Optional("[email protected]")] // [Optional(2), Optional("[email protected]")]} db.scalar("SELECT count(*) FROM users") // {Some 2} let jr = db.prepare("INSERT INTO users (email, manager_id) VALUES (? ?)")db.transaction( stmt.run("[email protected]"), jr.run("[email protected]", db.lastID)) |
Installation
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 for 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.)
Project home:http://www.open-open.com/lib/view/home/1412900499530
The SQLite framework in pure Swift package: Sqlite.swift