From 680f9a253a154a06475bb6b0a9c96b799088262b Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 20 Jan 2025 01:32:28 +0000 Subject: [PATCH 1/4] Add test --- Tests/IntegrationTests/PostgresNIOTests.swift | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tests/IntegrationTests/PostgresNIOTests.swift b/Tests/IntegrationTests/PostgresNIOTests.swift index ff59209b..67beda0c 100644 --- a/Tests/IntegrationTests/PostgresNIOTests.swift +++ b/Tests/IntegrationTests/PostgresNIOTests.swift @@ -664,6 +664,32 @@ final class PostgresNIOTests: XCTestCase { XCTAssertEqual(row?[data: "balance"].decimal, Decimal(string: "123456.789123")!) } + func testDateSerialization() { + let date = Date() + var conn: PostgresConnection? + XCTAssertNoThrow(conn = try PostgresConnection.test(on: eventLoop).wait()) + defer { XCTAssertNoThrow( try conn?.close().wait() ) } + + XCTAssertNoThrow(_ = try conn?.simpleQuery("DROP TABLE IF EXISTS \"table1\"").wait()) + XCTAssertNoThrow(_ = try conn?.simpleQuery(""" + CREATE TABLE table1 ( + "date" timestampz NOT NULL + ); + """).wait()) + defer { XCTAssertNoThrow(_ = try conn?.simpleQuery("DROP TABLE \"table1\"").wait()) } + + XCTAssertNoThrow(_ = try conn?.query("INSERT INTO table1 VALUES ($1)", [.init(date: date)]).wait()) + + var rows: PostgresQueryResult? + XCTAssertNoThrow(rows = try conn?.query(""" + SELECT + "date" + FROM table1 + """).wait()) + let row = rows?.first?.makeRandomAccess() + XCTAssertEqual(row?[data: "date"].date, date) + } + func testMoney() { var conn: PostgresConnection? XCTAssertNoThrow(conn = try PostgresConnection.test(on: eventLoop).wait()) From 21403e18cbcc1ddec07b70f2285f0504b3659e88 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 20 Jan 2025 01:39:33 +0000 Subject: [PATCH 2/4] numptie --- Tests/IntegrationTests/PostgresNIOTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/IntegrationTests/PostgresNIOTests.swift b/Tests/IntegrationTests/PostgresNIOTests.swift index 67beda0c..9442e4dc 100644 --- a/Tests/IntegrationTests/PostgresNIOTests.swift +++ b/Tests/IntegrationTests/PostgresNIOTests.swift @@ -673,7 +673,7 @@ final class PostgresNIOTests: XCTestCase { XCTAssertNoThrow(_ = try conn?.simpleQuery("DROP TABLE IF EXISTS \"table1\"").wait()) XCTAssertNoThrow(_ = try conn?.simpleQuery(""" CREATE TABLE table1 ( - "date" timestampz NOT NULL + "date" TIMESTAMP WITH TIME ZONE NOT NULL ); """).wait()) defer { XCTAssertNoThrow(_ = try conn?.simpleQuery("DROP TABLE \"table1\"").wait()) } @@ -687,7 +687,7 @@ final class PostgresNIOTests: XCTestCase { FROM table1 """).wait()) let row = rows?.first?.makeRandomAccess() - XCTAssertEqual(row?[data: "date"].date, date) + XCTAssertEqual(row?[data: "date"].date?.timeIntervalSince1970, date.timeIntervalSince1970) } func testMoney() { From 2505a47784853958f2638a4736d2bf2577107efc Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 20 Jan 2025 01:45:15 +0000 Subject: [PATCH 3/4] Test different Swift versions --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8364e8ae..9c7a68f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,8 +57,11 @@ jobs: postgres-auth: md5 - postgres-image: postgres:12 postgres-auth: trust + swift-version: + - swift-6.0 + - swift-5.10-noble container: - image: swift:5.10-noble + image: ${{ matrix.swift-version }} volumes: [ 'pgrunshare:/var/run/postgresql' ] runs-on: ubuntu-latest env: From 34cf75c97c22b9c248f251cc34f019318f8d2906 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 20 Jan 2025 01:53:48 +0000 Subject: [PATCH 4/4] Thanks AI --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9c7a68f7..c482683e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,8 +58,8 @@ jobs: - postgres-image: postgres:12 postgres-auth: trust swift-version: - - swift-6.0 - - swift-5.10-noble + - swift:6.0 + - swift:5.10-noble container: image: ${{ matrix.swift-version }} volumes: [ 'pgrunshare:/var/run/postgresql' ]