Skip to content

Commit 0134290

Browse files
committed
final tests passing
1 parent 2a6df80 commit 0134290

File tree

4 files changed

+6
-31
lines changed

4 files changed

+6
-31
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
.package(url: "https://github.com/vapor/async.git", .branch("beta")),
1313

1414
// Swift ORM framework (queries, models, and relations) for building NoSQL and SQL database integrations.
15-
.package(url: "https://github.com/vapor/fluent.git", .branch("benchmark-await")),
15+
.package(url: "https://github.com/vapor/fluent.git", .branch("beta")),
1616

1717
// Pure Swift, async/non-blocking client for PostgreSQL.
1818
.package(url: "https://github.com/vapor/postgresql.git", .branch("beta")),

Sources/FluentPostgreSQL/PostgreSQLDatabase+QuerySupporting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension PostgreSQLDatabase: QuerySupporting {
88
public static func execute<I, D>(query: DatabaseQuery<PostgreSQLDatabase>, into stream: I, on connection: PostgreSQLConnection)
99
where I: Async.InputStream, D: Decodable, D == I.Input
1010
{
11-
let future = Future<Void> {
11+
let future = Future<Void>.flatMap {
1212
// Convert Fluent `DatabaseQuery` to generic FluentSQL `DataQuery`
1313
var (sqlQuery, bindValues) = query.makeDataQuery()
1414

Sources/FluentPostgreSQL/PostgreSQLDatabase+SchemaSupporting.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ extension PostgreSQLDatabase: SchemaSupporting {
6565
/// See `SchemaSupporting.execute`
6666
public static func execute(schema: DatabaseSchema<PostgreSQLDatabase>, on connection: PostgreSQLConnection) -> Future<Void> {
6767
do {
68-
let sqlQuery = schema.makeSchemaQuery(dataTypeFactory: dataType)
69-
let sqlString = PostgreSQLSQLSerializer().serialize(schema: sqlQuery)
68+
var schemaQuery = schema.makeSchemaQuery(dataTypeFactory: dataType)
69+
schema.applyReferences(to: &schemaQuery)
70+
let sqlString = PostgreSQLSQLSerializer().serialize(schema: schemaQuery)
7071
return try connection.query(sqlString).map(to: Void.self) { rows in
7172
assert(rows.count == 0)
7273
}

Sources/FluentPostgreSQL/PostgreSQLDatabase+TransactionSupporting.swift

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,11 @@ extension PostgreSQLDatabase: TransactionSupporting {
66
return connection.simpleQuery("BEGIN TRANSACTION").flatMap(to: Void.self) { results in
77
return transaction.run(on: connection).flatMap(to: Void.self) { void in
88
return connection.simpleQuery("END TRANSACTION").transform(to: ())
9-
}.flatMapError { error in
9+
}.catchFlatMap { error in
1010
return connection.simpleQuery("ROLLBACK").map(to: Void.self) { results in
1111
throw error
1212
}
1313
}
1414
}
1515
}
1616
}
17-
18-
19-
extension Future {
20-
func mapError(_ callback: @escaping (Error) -> (Expectation)) -> Future<Expectation> {
21-
let promise = Promise(Expectation.self)
22-
addAwaiter { result in
23-
switch result {
24-
case .error(let error): promise.complete(callback(error))
25-
case .expectation(let e): promise.complete(e)
26-
}
27-
}
28-
return promise.future
29-
}
30-
31-
32-
func flatMapError(_ callback: @escaping (Error) -> (Future<Expectation>)) -> Future<Expectation> {
33-
let promise = Promise(Expectation.self)
34-
addAwaiter { result in
35-
switch result {
36-
case .error(let error): callback(error).chain(to: promise)
37-
case .expectation(let e): promise.complete(e)
38-
}
39-
}
40-
return promise.future
41-
}
42-
}

0 commit comments

Comments
 (0)