File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public final class Connection {
45
45
isClosed = false
46
46
}
47
47
48
- public func transaction( _ closure: ( ) throws -> Void ) throws {
48
+ public func transaction< R > ( _ closure: ( ) throws -> R ) throws -> R {
49
49
// required by transactions, but I don't want to open the old
50
50
// MySQL query API to the public as it would be a burden to maintain.
51
51
func manual( _ query: String ) throws {
@@ -55,16 +55,18 @@ public final class Connection {
55
55
}
56
56
57
57
try manual ( " START TRANSACTION " )
58
-
58
+
59
+ let value : R
59
60
do {
60
- try closure ( )
61
+ value = try closure ( )
61
62
} catch {
62
63
// rollback changes and then rethrow the error
63
64
try manual ( " ROLLBACK " )
64
65
throw error
65
66
}
66
67
67
68
try manual ( " COMMIT " )
69
+ return value
68
70
}
69
71
70
72
@discardableResult
Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ class MySQLTests: XCTestCase {
195
195
] )
196
196
197
197
try conn. transaction {
198
- try conn. execute ( " UPDATE transaction SET name = 'James' where name = 'james' " )
198
+ _ = try conn. execute ( " UPDATE transaction SET name = 'James' where name = 'james' " )
199
199
}
200
200
201
201
if let name = try conn. execute ( " SELECT * FROM transaction " ) [ " 0 " , " name " ] ? . string {
You can’t perform that action at this time.
0 commit comments