@@ -34,46 +34,44 @@ syntax _and_ intent.
3434``` swift
3535import SQLite
3636
37- let db = Database (" path/to/db.sqlite3" )
37+ let db = try Connection (" path/to/db.sqlite3" )
3838
39- let users = db[ " users" ]
39+ let users = Table ( " users" )
4040let id = Expression< Int64 > (" id" )
4141let name = Expression< String ?> (" name" )
4242let email = Expression< String > (" email" )
4343
44- db.create ( table : users) { t in
44+ db.run ( users. create { t in
4545 t.column (id, primaryKey : true )
4646 t.column (name)
4747 t.column (email, unique : true )
48- }
48+ })
4949// CREATE TABLE "users" (
5050// "id" INTEGER PRIMARY KEY NOT NULL,
5151// "name" TEXT,
5252// "email" TEXT NOT NULL UNIQUE
5353// )
5454
55- var alice: Query?
56- if let rowid
= users.
insert (name
<- " Alice" , email
<- " [email protected] " ).rowid {
57- println (" inserted id: \( rowid ) " )
58- // inserted id: 1
59- alice = users.filter (id == rowid)
60- }
55+ let insert
= users.
insert (name
<- " Alice" , email
<- " [email protected] " )
56+ let rowid = try db.run (insert)
6157// INSERT INTO "users" ("name", "email") VALUES ('Alice', '[email protected] ')6258
63- for user in users {
59+ for user in try db. prepare ( users) {
6460 println (" id: \( user[id] ) , name: \( user[name] ) , email: \( user[email] ) " )
6561 // id: 1, name: Optional("Alice"), email: [email protected] 6662}
6763// SELECT * FROM "users"
6864
69- alice? .update (email <- replace (email, " mac.com" , " me.com" ))
65+ let alice = users.filter (id == rowid)
66+
67+ try db.run (alice.update (email <- email.replace (" mac.com" , " me.com" )))
7068// UPDATE "users" SET "email" = replace("email", 'mac.com', 'me.com')
7169// WHERE ("id" = 1)
7270
73- alice? .delete ()
71+ try db. run ( alice.delete () )
7472// DELETE FROM "users" WHERE ("id" = 1)
7573
76- users.count
74+ let count = try db. scalar ( users.count )
7775// SELECT count(*) FROM "users"
7876```
7977
@@ -107,8 +105,7 @@ interactively, from the Xcode project’s playground.
107105
108106## Installation
109107
110- > _ Note:_ SQLite.swift requires Swift 1.2 (and [ Xcode] [ ] 6.3) or
111- > greater.
108+ > _ Note:_ SQLite.swift requires Swift 2 (and [ Xcode] [ ] 7) or greater.
112109>
113110> The following instructions apply to targets that support embedded
114111> Swift frameworks. To use SQLite.swift in iOS 7 or an OS X command line
0 commit comments