File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed
Sources/FluentPostgresDriver
Tests/FluentPostgresDriverTests Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change 44jobs :
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
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
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 "
You can’t perform that action at this time.
0 commit comments