-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix transaction rollback with top-level throw (#90)
* Fix GH89 by adding catchFlatMap to catch transaction closure throws. Add test. * Add tests to allTests * Update the contribute script to use docker-compose instead of docker-machine. Co-authored-by: Tanner <[email protected]>
- Loading branch information
1 parent
c00c474
commit a3d6587
Showing
3 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
12 changes: 6 additions & 6 deletions
12
Sources/FluentPostgreSQL/PostgreSQLDatabase+TransactionSupporting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
extension PostgreSQLDatabase: TransactionSupporting { | ||
/// See `TransactionSupporting`. | ||
public static func transactionExecute<T>(_ transaction: @escaping (PostgreSQLConnection) throws -> Future<T>, on connection: PostgreSQLConnection) -> Future<T> { | ||
func rollback(error: Error) -> Future<T> { | ||
return connection.simpleQuery("ROLLBACK").map { throw error } | ||
} | ||
|
||
return connection.simpleQuery("BEGIN TRANSACTION").flatMap { results in | ||
return try transaction(connection).flatMap { res in | ||
return connection.simpleQuery("END TRANSACTION").transform(to: res) | ||
}.catchFlatMap { error in | ||
return connection.simpleQuery("ROLLBACK").map { results in | ||
throw error | ||
} | ||
} | ||
} | ||
}.catchFlatMap(rollback) | ||
}.catchFlatMap(rollback) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,8 @@ | ||
echo "π§ starting docker..." | ||
docker-machine start default | ||
|
||
echo "π§ exporting docker machine environment..." | ||
eval $(docker-machine env default) | ||
|
||
echo "π§ cleaning previous vapor-psql dev db..." | ||
docker stop vapor-psql | ||
docker rm vapor-psql | ||
|
||
echo "π§ creating vapor-psql dev db..." | ||
docker run --name vapor-psql -e POSTGRES_USER=vapor_username -e POSTGRES_DB=vapor_database -p 5432:5432 -d postgres:latest | ||
|
||
echo "π§ generating xcode proj..." | ||
swift package generate-xcodeproj | ||
|
||
echo "π§ add the following env variable to Xcode test scheme:" | ||
echo "" | ||
echo " PSQL_HOSTNAME: `docker-machine ip`" | ||
echo "" | ||
|
||
echo "π§ opening xcode..." | ||
open *.xcodeproj | ||
open *.xcodeproj | ||
|
||
echo "π§ starting docker..." | ||
docker-compose up psql-10 |