Skip to content

Commit 288b6c7

Browse files
committed
Swift 2 Support
Swift 2 is an opportunity to revamp the SQLite.swift API alongside the changes the latest version brings to the table. This mostly includes error handling and protocol extensions (most helpful for the expression layer), but also lets us rethink the general project structure. Signed-off-by: Stephen Celis <stephen@stephencelis.com>
1 parent d87e05d commit 288b6c7

File tree

85 files changed

+9066
-7226
lines changed

Some content is hidden

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

85 files changed

+9066
-7226
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: objective-c
22
env:
3-
- BUILD_SDK=iphonesimulator ONLY_ACTIVE_ARCH=NO
4-
- BUILD_SDK=macosx
3+
- BUILD_SCHEME="SQLite iOS"
4+
- BUILD_SCHEME="SQLite Mac"
55
before_install:
66
- gem install xcpretty --no-document
77
script:
88
- make test
9-
osx_image: beta-xcode6.3
9+
osx_image: xcode7

CONTRIBUTING.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,7 @@ first.
5454
While Swift error messaging is improving with each release, complex
5555
expressions still lend themselves to misleading errors. If you encounter an
5656
error on a complex line, breaking it down into smaller pieces generally
57-
yields a more understandable error. _E.g._:
58-
59-
``` swift
60-
users.insert(email <- "alice@mac.com" <- managerId <- db.lastInsertRowid)
61-
// Cannot invoke 'insert' with an argument list of type '(Setter, Setter)'
62-
```
63-
64-
Not very helpful! If we break the expression down into smaller parts,
65-
however, the real error materializes on the appropriate line.
66-
67-
``` swift
68-
let emailSetter = email <- "alice@mac.com"
69-
let managerIdSetter = managerId <- db.lastInsertRowId
70-
// Binary operator '<-' cannot be applied to operands of type 'Expression<Int>' and 'Int64'
71-
users.insert(emailSetter, managerIdSetter)
72-
```
73-
74-
The problem turns out to be a simple type mismatch. The fix is elsewhere:
75-
76-
``` diff
77-
-let managerId = Expression<Int>("manager_id")
78-
+let managerId = Expression<Int64>("manager_id")
79-
```
57+
yields a more understandable error.
8058

8159
- **Is it an _even more_ unhelpful build error?** <a name='bugs-5'/>
8260

Documentation/Index.md

Lines changed: 180 additions & 186 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BUILD_TOOL = xcodebuild
2-
BUILD_SDK = macosx
3-
BUILD_ARGUMENTS = -scheme SQLite -sdk $(BUILD_SDK)
2+
BUILD_SCHEME = SQLite Mac
3+
BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)"
44

55
XCPRETTY := $(shell command -v xcpretty)
66
SWIFTCOV := $(shell command -v swiftcov)

README.md

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A type-safe, [Swift][]-language layer over [SQLite3][].
55
[SQLite.swift][] provides compile-time confidence in SQL statement
66
syntax _and_ intent.
77

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
99
[Travis]: https://travis-ci.org/stephencelis/SQLite.swift
1010
[Swift]: https://developer.apple.com/swift/
1111
[SQLite3]: http://www.sqlite.org
@@ -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+
try 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 <- "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)
6157
// INSERT INTO "users" ("name", "email") VALUES ('Alice', 'alice@mac.com')
6258

63-
for user in users {
59+
for user in db.prepare(users) {
6460
println("id: \(user[id]), name: \(user[name]), email: \(user[email])")
6561
// id: 1, name: Optional("Alice"), email: alice@mac.com
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+
db.scalar(users.count) // 0
7775
// SELECT count(*) FROM "users"
7876
```
7977

@@ -107,29 +105,54 @@ 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
115112
> tool, please read the [Frameworkless Targets][] section of the
116113
> documentation.
117114
118115

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+
119137
### CocoaPods
120138
121139
[CocoaPods][] is a dependency manager for Cocoa projects. To install
122140
SQLite.swift with CocoaPods:
123141
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.)
126144
127145
2. Update your Podfile to include the following:
128146
129147
``` ruby
130148
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'
133156
```
134157
135158
3. Run `pod install`.

0 commit comments

Comments
 (0)