diff --git a/Sources/FluentPostgresDriver/Postgres+Fluent.swift b/Sources/FluentPostgresDriver/Postgres+Fluent.swift index 9572f53..97bba3d 100644 --- a/Sources/FluentPostgresDriver/Postgres+Fluent.swift +++ b/Sources/FluentPostgresDriver/Postgres+Fluent.swift @@ -22,14 +22,38 @@ extension Databases { } } -extension ConnectionPool: Database where Source.Connection: SQLDatabase { +extension ConnectionPool: Database where Source.Connection: Database { public var eventLoop: EventLoop { return self.source.eventLoop } + + public func execute(_ schema: DatabaseSchema) -> EventLoopFuture { + return self.withConnection { $0.execute(schema) } + } + + public func execute(_ query: DatabaseQuery, _ onOutput: @escaping (DatabaseOutput) throws -> ()) -> EventLoopFuture { + return self.withConnection { $0.execute(query, onOutput) } + } + + public func close() -> EventLoopFuture { + #warning("TODO: implement connectionPool.close()") + fatalError("") + } + + public func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + return self.withConnection { conn in + return closure(conn) + } + } } -extension PostgresConnection: Database { } -extension Database where Self: SQLDatabase { +extension PostgresError: DatabaseError { } + +extension PostgresConnection: Database { + public func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + return closure(self) + } + public func execute(_ query: DatabaseQuery, _ onOutput: @escaping (DatabaseOutput) throws -> ()) -> EventLoopFuture { var sql = SQLQueryConverter().convert(query) switch query.action { diff --git a/Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift b/Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift index 29d9103..46351e5 100644 --- a/Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift +++ b/Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift @@ -38,12 +38,10 @@ final class FluentPostgresDriverTests: XCTestCase { } func testEagerLoadSubqueryJSONEncode() throws { - #warning("TODO: fix connection pool alg") try self.benchmarker.testEagerLoadSubqueryJSONEncode() } func testEagerLoadJoinJSONEncode() throws { - #warning("TODO: fix connection pool alg") try self.benchmarker.testEagerLoadJoinJSONEncode() } @@ -74,10 +72,22 @@ final class FluentPostgresDriverTests: XCTestCase { func testAggregates() throws { try self.benchmarker.testAggregates() } -// -// func testWorkUnit() throws { -// try self.benchmarker.testWorkUnit() -// } + + func testIdentifierGeneration() throws { + try self.benchmarker.testIdentifierGeneration() + } + + func testNullifyField() throws { + try self.benchmarker.testNullifyField() + } + + func testChunkedFetch() throws { + try self.benchmarker.testChunkedFetch() + } + + func testUniqueFields() throws { + try self.benchmarker.testUniqueFields() + } override func setUp() { let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1).next() @@ -99,8 +109,4 @@ final class FluentPostgresDriverTests: XCTestCase { let pool = ConnectionPool(config: .init(maxConnections: 1), source: db) self.benchmarker = FluentBenchmarker(database: pool) } - - static let allTests = [ - ("testAll", testAll), - ] } diff --git a/Tests/FluentPostgresDriverTests/XCTestManifests.swift b/Tests/FluentPostgresDriverTests/XCTestManifests.swift new file mode 100644 index 0000000..b375b05 --- /dev/null +++ b/Tests/FluentPostgresDriverTests/XCTestManifests.swift @@ -0,0 +1,38 @@ +#if !canImport(ObjectiveC) +import XCTest + +extension FluentPostgresDriverTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FluentPostgresDriverTests = [ + ("testAggregates", testAggregates), + ("testAll", testAll), + ("testBatchCreate", testBatchCreate), + ("testBatchUpdate", testBatchUpdate), + ("testChunkedFetch", testChunkedFetch), + ("testCreate", testCreate), + ("testDelete", testDelete), + ("testEagerLoadChildren", testEagerLoadChildren), + ("testEagerLoadJoinJSONEncode", testEagerLoadJoinJSONEncode), + ("testEagerLoadParent", testEagerLoadParent), + ("testEagerLoadParentJoin", testEagerLoadParentJoin), + ("testEagerLoadSubqueryJSONEncode", testEagerLoadSubqueryJSONEncode), + ("testIdentifierGeneration", testIdentifierGeneration), + ("testJoin", testJoin), + ("testMigrator", testMigrator), + ("testMigratorError", testMigratorError), + ("testNestedModel", testNestedModel), + ("testNullifyField", testNullifyField), + ("testRead", testRead), + ("testUniqueFields", testUniqueFields), + ("testUpdate", testUpdate), + ] +} + +public func __allTests() -> [XCTestCaseEntry] { + return [ + testCase(FluentPostgresDriverTests.__allTests__FluentPostgresDriverTests), + ] +} +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index fdd8105..b0d0c0f 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,6 +1,8 @@ import XCTest -@testable import FluentPostgresDriverTests -XCTMain([ - testCase(FluentPostgresDriverTests.allTests), -]) +import FluentPostgresDriverTests + +var tests = [XCTestCaseEntry]() +tests += FluentPostgresDriverTests.__allTests() + +XCTMain(tests)