Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions Sources/FluentPostgresDriver/Postgres+Fluent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> {
return self.withConnection { $0.execute(schema) }
}

public func execute(_ query: DatabaseQuery, _ onOutput: @escaping (DatabaseOutput) throws -> ()) -> EventLoopFuture<Void> {
return self.withConnection { $0.execute(query, onOutput) }
}

public func close() -> EventLoopFuture<Void> {
#warning("TODO: implement connectionPool.close()")
fatalError("")
}

public func transaction<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
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<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
return closure(self)
}

public func execute(_ query: DatabaseQuery, _ onOutput: @escaping (DatabaseOutput) throws -> ()) -> EventLoopFuture<Void> {
var sql = SQLQueryConverter().convert(query)
switch query.action {
Expand Down
26 changes: 16 additions & 10 deletions Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
Expand All @@ -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),
]
}
38 changes: 38 additions & 0 deletions Tests/FluentPostgresDriverTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import XCTest
@testable import FluentPostgresDriverTests

XCTMain([
testCase(FluentPostgresDriverTests.allTests),
])
import FluentPostgresDriverTests

var tests = [XCTestCaseEntry]()
tests += FluentPostgresDriverTests.__allTests()

XCTMain(tests)