Skip to content

Commit af0e05e

Browse files
committed
add test for #46
1 parent 3883464 commit af0e05e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,33 @@ class PostgreSQLConnectionTests: XCTestCase {
352352
XCTAssertEqual(config.database, "database")
353353
}
354354

355+
// https://github.com/vapor/postgresql/issues/46
356+
func testGH46() throws {
357+
struct Overview {
358+
var platform: String
359+
var identifier: String
360+
var count: Int
361+
}
362+
363+
let connection = try PostgreSQLConnection.makeTest()
364+
_ = try connection.simpleQuery("DROP TABLE IF EXISTS apps").wait()
365+
_ = try connection.simpleQuery("CREATE TABLE apps (id INT, platform TEXT, identifier TEXT)").wait()
366+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (1, 'a', 'b')").wait()
367+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (2, 'c', 'd')").wait()
368+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (3, 'a', 'd')").wait()
369+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (4, 'a', 'b')").wait()
370+
let overviews = try connection.query("SELECT platform, identifier, COUNT(id) as count FROM apps GROUP BY platform, identifier").map(to: [Overview].self) { data in
371+
return try data.map { row in
372+
return try Overview(
373+
platform: row.firstValue(forColumn: "platform")!.decode(String.self),
374+
identifier: row.firstValue(forColumn: "identifier")!.decode(String.self),
375+
count: row.firstValue(forColumn: "count")!.decode(Int.self)
376+
)
377+
}
378+
}.wait()
379+
XCTAssertEqual(overviews.count, 3)
380+
}
381+
355382
static var allTests = [
356383
("testVersion", testVersion),
357384
("testSelectTypes", testSelectTypes),
@@ -362,6 +389,7 @@ class PostgreSQLConnectionTests: XCTestCase {
362389
("testNull", testNull),
363390
("testGH24", testGH24),
364391
("testURLParsing", testURLParsing),
392+
("testGH46", testGH46),
365393
]
366394
}
367395

0 commit comments

Comments
 (0)