Skip to content

Commit d446df4

Browse files
committed
WIP: Swift 2
Signed-off-by: Stephen Celis <[email protected]>
1 parent f791d36 commit d446df4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+7089
-7112
lines changed

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,44 @@ syntax _and_ intent.
3434
``` swift
3535
import 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")
4040
let id = Expression<Int64>("id")
4141
let name = Expression<String?>("name")
4242
let 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

Comments
 (0)