File tree 3 files changed +32
-6
lines changed
Sources/FluentPostgresDriver
Tests/FluentPostgresDriverTests
3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change 4
4
jobs :
5
5
xenial :
6
6
container :
7
- image : vapor/swift:5.1 -xenial
7
+ image : vapor/swift:5.2 -xenial
8
8
services :
9
9
psql :
10
10
image : postgres
20
20
- run : swift test --enable-test-discovery --sanitize=thread
21
21
bionic :
22
22
container :
23
- image : vapor/swift:5.1 -bionic
23
+ image : vapor/swift:5.2 -bionic
24
24
services :
25
25
psql :
26
26
image : postgres
Original file line number Diff line number Diff line change @@ -39,6 +39,28 @@ extension _FluentPostgresDatabase: Database {
39
39
return self . eventLoop. makeFailedFuture ( error)
40
40
}
41
41
}
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
+ }
42
64
43
65
func withConnection< T> ( _ closure: @escaping ( Database ) -> EventLoopFuture < T > ) -> EventLoopFuture < T > {
44
66
self . database. withConnection {
Original file line number Diff line number Diff line change @@ -32,10 +32,6 @@ final class FluentPostgresDriverTests: XCTestCase {
32
32
try self . benchmarker. testEagerLoadParent ( )
33
33
}
34
34
35
- func testEagerLoadParentJoin( ) throws {
36
- try self . benchmarker. testEagerLoadParentJoin ( )
37
- }
38
-
39
35
func testEagerLoadParentJSON( ) throws {
40
36
try self . benchmarker. testEagerLoadParentJSON ( )
41
37
}
@@ -180,6 +176,14 @@ final class FluentPostgresDriverTests: XCTestCase {
180
176
try self . benchmarker. testMultipleSet ( )
181
177
}
182
178
179
+ func testTransaction( ) throws {
180
+ try self . benchmarker. testTransaction ( )
181
+ }
182
+
183
+ func testPagination( ) throws {
184
+ try self . benchmarker. testPagination ( )
185
+ }
186
+
183
187
func testBlob( ) throws {
184
188
final class Foo : Model {
185
189
static let schema = " foos "
You can’t perform that action at this time.
0 commit comments