Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9244cb2

Browse files
Beta 4 (#138)
* beta 4 * updates * 5.2
1 parent dc03d7c commit 9244cb2

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

‎.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
jobs:
55
xenial:
66
container:
7-
image: vapor/swift:5.1-xenial
7+
image: vapor/swift:5.2-xenial
88
services:
99
psql:
1010
image: postgres
@@ -20,7 +20,7 @@ jobs:
2020
- run: swift test --enable-test-discovery --sanitize=thread
2121
bionic:
2222
container:
23-
image: vapor/swift:5.1-bionic
23+
image: vapor/swift:5.2-bionic
2424
services:
2525
psql:
2626
image: postgres

‎Sources/FluentPostgresDriver/FluentPostgresDatabase.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ extension _FluentPostgresDatabase: Database {
3939
return self.eventLoop.makeFailedFuture(error)
4040
}
4141
}
42+
43+
func transaction<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
44+
self.database.withConnection { conn in
45+
conn.simpleQuery("BEGIN").flatMap { _ in
46+
let db = _FluentPostgresDatabase(
47+
database: conn,
48+
context: self.context,
49+
encoder: self.encoder,
50+
decoder: self.decoder
51+
)
52+
return closure(db).flatMap { result in
53+
conn.simpleQuery("COMMIT").map { _ in
54+
result
55+
}
56+
}.flatMapError { error in
57+
conn.simpleQuery("ROLLBACK").flatMapThrowing { _ in
58+
throw error
59+
}
60+
}
61+
}
62+
}
63+
}
4264

4365
func withConnection<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
4466
self.database.withConnection {

‎Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ final class FluentPostgresDriverTests: XCTestCase {
3232
try self.benchmarker.testEagerLoadParent()
3333
}
3434

35-
func testEagerLoadParentJoin() throws {
36-
try self.benchmarker.testEagerLoadParentJoin()
37-
}
38-
3935
func testEagerLoadParentJSON() throws {
4036
try self.benchmarker.testEagerLoadParentJSON()
4137
}
@@ -180,6 +176,14 @@ final class FluentPostgresDriverTests: XCTestCase {
180176
try self.benchmarker.testMultipleSet()
181177
}
182178

179+
func testTransaction() throws {
180+
try self.benchmarker.testTransaction()
181+
}
182+
183+
func testPagination() throws {
184+
try self.benchmarker.testPagination()
185+
}
186+
183187
func testBlob() throws {
184188
final class Foo: Model {
185189
static let schema = "foos"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /