mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Functions that fetch no longer throw (they crash), but the low-level Database.selectStatement(_:bindings:unsafe:).
This commit is contained in:
1 parent
13817d864d
commit
343a239905
4 files changed
+14
-5
No files matched your search
@@ -31,7 +31,7 @@ class DatabaseMigratorTests: GRDBTests {
|
||||
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
try dbQueue.inDatabase { db in
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(db.tableExists("persons"))
|
||||
XCTAssertTrue(db.tableExists("pets"))
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class DatabaseMigratorTests: GRDBTests {
|
||||
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
try dbQueue.inDatabase { db in
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(db.tableExists("persons"))
|
||||
XCTAssertFalse(db.tableExists("pets"))
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ class DatabaseTests: GRDBTests {
|
||||
|
||||
// Fetching rows and values:
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
dbQueue.inDatabase { db in
|
||||
for row in db.fetchRows("SELECT * FROM persons") {
|
||||
// Leverage Swift type inference
|
||||
let name: String? = row.value(atIndex: 1)
|
||||
|
||||
@@ -39,6 +39,16 @@ public class DatabaseQueue {
|
||||
}
|
||||
}
|
||||
|
||||
public func inDatabase(block: (db: Database) -> Void) {
|
||||
guard databaseQueueID != dispatch_get_specific(DatabaseQueue.databaseQueueIDKey) else {
|
||||
fatalError("inDatabase(_:) was called reentrantly on the same queue, which would lead to a deadlock")
|
||||
}
|
||||
|
||||
dispatch_sync(queue) { () -> Void in
|
||||
block(db: self.database)
|
||||
}
|
||||
}
|
||||
|
||||
public func inDatabase<R>(block: (db: Database) -> R) -> R {
|
||||
guard databaseQueueID != dispatch_get_specific(DatabaseQueue.databaseQueueIDKey) else {
|
||||
fatalError("inDatabase(_:) was called reentrantly on the same queue, which would lead to a deadlock")
|
||||
|
||||
@@ -66,7 +66,7 @@ try dbQueue.inTransaction { db in
|
||||
|
||||
// Fetching rows and values:
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
dbQueue.inDatabase { db in
|
||||
for row in db.fetchRows("SELECT * FROM persons") {
|
||||
// Leverage Swift type inference
|
||||
let name: String? = row.value(atIndex: 1)
|
||||
@@ -94,5 +94,4 @@ let names = dbQueue.inDatabase { db in
|
||||
db.fetchValues("SELECT name FROM persons ORDER BY name", type: String.self).map { $0! }
|
||||
}
|
||||
// names is [String]: ["Arthur", "Barbara"]
|
||||
|
||||
```
|
||||
Reference in new issue
Block a user