Skip to content

Commit

Permalink
Merge pull request #159 from vapor/tn-beta-4
Browse files Browse the repository at this point in the history
Beta 4
  • Loading branch information
tanner0101 authored Feb 15, 2020
2 parents 6b7fa4b + 748a5a1 commit 16a462c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
jobs:
mysql-8_0:
container:
image: vapor/swift:5.1
image: vapor/swift:5.2
services:
mysql:
image: mysql:8.0
Expand All @@ -22,7 +22,7 @@ jobs:
MYSQL_TLS: true
mysql-5_7:
container:
image: vapor/swift:5.1
image: vapor/swift:5.2
services:
mysql:
image: mysql:5.7
Expand Down
17 changes: 17 additions & 0 deletions Sources/FluentMySQLDriver/FluentMySQLDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ extension _FluentMySQLDatabase: Database {
return self.eventLoop.makeFailedFuture(error)
}
}

func transaction<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
self.database.withConnection { conn in
conn.simpleQuery("START TRANSACTION").flatMap { _ in
let db = _FluentMySQLDatabase(database: conn, context: self.context)
return closure(db).flatMap { result in
conn.simpleQuery("COMMIT").map { _ in
result
}
}.flatMapError { error in
conn.simpleQuery("ROLLBACK").flatMapThrowing { _ in
throw error
}
}
}
}
}

func withConnection<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
self.database.withConnection {
Expand Down
12 changes: 8 additions & 4 deletions Tests/FluentMySQLDriverTests/FluentMySQLDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ final class FluentMySQLDriverTests: XCTestCase {
try self.benchmarker.testEagerLoadParent()
}

func testEagerLoadParentJoin() throws {
try self.benchmarker.testEagerLoadParentJoin()
}

func testEagerLoadParentJSON() throws {
try self.benchmarker.testEagerLoadParentJSON()
}
Expand Down Expand Up @@ -169,6 +165,14 @@ final class FluentMySQLDriverTests: XCTestCase {
try self.benchmarker.testDuplicatedUniquePropertyName()
}

func testTransaction() throws {
try self.benchmarker.testTransaction()
}

func testPagination() throws {
try self.benchmarker.testPagination()
}

func testClarityModel() throws {
final class Clarity: Model {
static let schema = "clarities"
Expand Down

0 comments on commit 16a462c

Please sign in to comment.