@@ -5,7 +5,7 @@ A type-safe, [Swift][]-language layer over [SQLite3][].
5
5
[ SQLite.swift] [ ] provides compile-time confidence in SQL statement
6
6
syntax _ and_ intent.
7
7
8
- [ Badge ] : https://img.shields.io/travis/stephencelis/SQLite.swift/master .svg?style=flat
8
+ [ Badge ] : https://img.shields.io/travis/stephencelis/SQLite.swift/swift-2 .svg?style=flat
9
9
[ Travis ] : https://travis-ci.org/stephencelis/SQLite.swift
10
10
[ Swift ] : https://developer.apple.com/swift/
11
11
[ SQLite3 ] : http://www.sqlite.org
@@ -34,46 +34,44 @@ syntax _and_ intent.
34
34
``` swift
35
35
import SQLite
36
36
37
- let db = Database (" path/to/db.sqlite3" )
37
+ let db = try Connection (" path/to/db.sqlite3" )
38
38
39
- let users = db[ " users" ]
39
+ let users = Table ( " users" )
40
40
let id = Expression< Int64 > (" id" )
41
41
let name = Expression< String ?> (" name" )
42
42
let email = Expression< String > (" email" )
43
43
44
- db.create ( table : users) { t in
44
+ try db.run ( users. create { t in
45
45
t.column (id, primaryKey : true )
46
46
t.column (name)
47
47
t.column (email, unique : true )
48
- }
48
+ })
49
49
// CREATE TABLE "users" (
50
50
// "id" INTEGER PRIMARY KEY NOT NULL,
51
51
// "name" TEXT,
52
52
// "email" TEXT NOT NULL UNIQUE
53
53
// )
54
54
55
- var alice: Query?
56
- if let rowid = users.insert (name <- " Alice" , email <- " alice@mac.com" ).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 <- " alice@mac.com" )
56
+ let rowid = try db.run (insert)
61
57
// INSERT INTO "users" ("name", "email") VALUES ('Alice', 'alice@mac.com')
62
58
63
- for user in users {
59
+ for user in db. prepare ( users) {
64
60
println (" id: \( user[id] ) , name: \( user[name] ) , email: \( user[email] ) " )
65
61
// id: 1, name: Optional("Alice"), email: alice@mac.com
66
62
}
67
63
// SELECT * FROM "users"
68
64
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" )))
70
68
// UPDATE "users" SET "email" = replace("email", 'mac.com', 'me.com')
71
69
// WHERE ("id" = 1)
72
70
73
- alice? .delete ()
71
+ try db. run ( alice.delete () )
74
72
// DELETE FROM "users" WHERE ("id" = 1)
75
73
76
- users.count
74
+ db. scalar ( users.count ) // 0
77
75
// SELECT count(*) FROM "users"
78
76
```
79
77
@@ -107,29 +105,54 @@ interactively, from the Xcode project’s playground.
107
105
108
106
## Installation
109
107
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.
112
109
>
113
110
> The following instructions apply to targets that support embedded
114
111
> Swift frameworks. To use SQLite.swift in iOS 7 or an OS X command line
115
112
> tool, please read the [ Frameworkless Targets] [ ] section of the
116
113
> documentation.
117
114
118
115
116
+ ### Carthage
117
+
118
+ [ Carthage] [ ] is a simple, decentralized dependency manager for Cocoa. To
119
+ install SQLite.swift with Carthage:
120
+
121
+ 1 . Make sure Carthage is [ installed] [ Carthage Installation ] .
122
+
123
+ 2 . Update your Cartfile to include the following:
124
+
125
+ ```
126
+ github "stephencelis/SQLite.swift" "swift-2"
127
+ ```
128
+
129
+ 3. Run `carthage update` and [add the appropriate framework][Carthage Usage].
130
+
131
+
132
+ [Carthage]: https://github.com/Carthage/Carthage
133
+ [Carthage Installation]: https://github.com/Carthage/Carthage#installing-carthage
134
+ [Carthage Usage]: https://github.com/Carthage/Carthage#adding-frameworks-to-an-application
135
+
136
+
119
137
### CocoaPods
120
138
121
139
[CocoaPods][] is a dependency manager for Cocoa projects. To install
122
140
SQLite.swift with CocoaPods:
123
141
124
- 1 . Make sure CocoaPods is [ installed] [ CocoaPods Installation ] (SQLite.swift
125
- requires version 0.37 or greater).
142
+ 1. Make sure CocoaPods is [installed][CocoaPods Installation]. (SQLite.swift
143
+ requires version 0.37 or greater.)
126
144
127
145
2. Update your Podfile to include the following:
128
146
129
147
``` ruby
130
148
use_frameworks!
131
- pod ' SQLite.swift' , git: ' https://github.com/stephencelis/SQLite.swift.git'
132
- # pod 'SQLite.swift/Cipher', git: ... # instead, for SQLCipher support
149
+
150
+ pod 'SQLite.swift',
151
+ git: 'https://github.com/stephencelis/SQLite.swift.git'
152
+
153
+ # instead, for SQLCipher support
154
+ pod 'SQLiteCipher.swift',
155
+ git: 'https://github.com/stephencelis/SQLite.swift.git'
133
156
```
134
157
135
158
3. Run `pod install`.
0 commit comments