Skip to content

Commit e277f93

Browse files
authored
Raise minimum Swift version to 5.5 (vapor#310)
1 parent 2cad52a commit e277f93

File tree

10 files changed

+68
-69
lines changed

10 files changed

+68
-69
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let package = Package(

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Team Chat](https://img.shields.io/discord/431917998102675485.svg)][Team Chat]
66
[![MIT License](http://img.shields.io/badge/license-MIT-brightgreen.svg)][MIT License]
77
[![Continuous Integration](https://github.com/vapor/postgres-nio/actions/workflows/test.yml/badge.svg)][Continuous Integration]
8-
[![Swift 5.4](http://img.shields.io/badge/swift-5.4-brightgreen.svg)][Swift 5.4]
8+
[![Swift 5.5](http://img.shields.io/badge/swift-5.5-brightgreen.svg)][Swift 5.5]
99
<br>
1010
<br>
1111

@@ -191,7 +191,7 @@ Please see [SECURITY.md] for details on the security process.
191191
[Team Chat]: https://discord.gg/vapor
192192
[MIT License]: LICENSE
193193
[Continuous Integration]: https://github.com/vapor/postgres-nio/actions
194-
[Swift 5.4]: https://swift.org
194+
[Swift 5.5]: https://swift.org
195195
[Security.md]: https://github.com/vapor/.github/blob/main/SECURITY.md
196196

197197
[`PostgresConnection`]: https://api.vapor.codes/postgres-nio/main/PostgresNIO/PostgresConnection/

Sources/PostgresNIO/Connection/PostgresConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ extension PostgresConnection {
449449

450450
// MARK: Async/Await Interface
451451

452-
#if swift(>=5.5) && canImport(_Concurrency)
452+
#if canImport(_Concurrency)
453453
extension PostgresConnection {
454454

455455
/// Creates a new connection to a Postgres server.

Sources/PostgresNIO/New/PSQLRowStream.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class PSQLRowStream {
2222
case waitingForAll([PostgresRow], EventLoopPromise<[PostgresRow]>, PSQLRowsDataSource)
2323
case consumed(Result<String, Error>)
2424

25-
#if swift(>=5.5) && canImport(_Concurrency)
25+
#if canImport(_Concurrency)
2626
case asyncSequence(AsyncStreamConsumer, PSQLRowsDataSource)
2727
#endif
2828
}
@@ -63,7 +63,7 @@ final class PSQLRowStream {
6363

6464
// MARK: Async Sequence
6565

66-
#if swift(>=5.5) && canImport(_Concurrency)
66+
#if canImport(_Concurrency)
6767
func asyncSequence() -> PostgresRowSequence {
6868
self.eventLoop.preconditionInEventLoop()
6969

@@ -304,7 +304,7 @@ final class PSQLRowStream {
304304
// immediately request more
305305
dataSource.request(for: self)
306306

307-
#if swift(>=5.5) && canImport(_Concurrency)
307+
#if canImport(_Concurrency)
308308
case .asyncSequence(let consumer, _):
309309
consumer.receive(newRows)
310310
#endif
@@ -344,7 +344,7 @@ final class PSQLRowStream {
344344
self.downstreamState = .consumed(.success(commandTag))
345345
promise.succeed(rows)
346346

347-
#if swift(>=5.5) && canImport(_Concurrency)
347+
#if canImport(_Concurrency)
348348
case .asyncSequence(let consumer, _):
349349
consumer.receive(completion: .success(commandTag))
350350
self.downstreamState = .consumed(.success(commandTag))
@@ -371,7 +371,7 @@ final class PSQLRowStream {
371371
self.downstreamState = .consumed(.failure(error))
372372
promise.fail(error)
373373

374-
#if swift(>=5.5) && canImport(_Concurrency)
374+
#if canImport(_Concurrency)
375375
case .asyncSequence(let consumer, _):
376376
consumer.receive(completion: .failure(error))
377377
self.downstreamState = .consumed(.failure(error))

Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// NOTE: THIS FILE IS AUTO-GENERATED BY dev/generate-postgresrowsequence-multi-decode.sh
22

3-
#if swift(>=5.5) && canImport(_Concurrency)
3+
#if canImport(_Concurrency)
44
extension AsyncSequence where Element == PostgresRow {
55
@inlinable
66
@_alwaysEmitIntoClient

Sources/PostgresNIO/New/PostgresRowSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NIOCore
22
import NIOConcurrencyHelpers
33

4-
#if swift(>=5.5) && canImport(_Concurrency)
4+
#if canImport(_Concurrency)
55
/// An async sequence of ``PostgresRow``s.
66
///
77
/// - Note: This is a struct to allow us to move to a move only type easily once they become available.

Tests/IntegrationTests/AsyncTests.swift

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PostgresNIO
55
import NIOTransportServices
66
#endif
77

8-
#if swift(>=5.5.2)
8+
#if canImport(_Concurrency)
99
final class AsyncPostgresConnectionTests: XCTestCase {
1010

1111
func test1kRoundTrips() async throws {
@@ -64,6 +64,60 @@ final class AsyncPostgresConnectionTests: XCTestCase {
6464
}
6565
}
6666

67+
func testBindMaximumParameters() async throws {
68+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
69+
defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) }
70+
let eventLoop = eventLoopGroup.next()
71+
72+
try await withTestConnection(on: eventLoop) { connection in
73+
// Max binds limit is UInt16.max which is 65535 which is 3 * 5 * 17 * 257
74+
// Max columns limit is 1664, so we will only make 5 * 257 columns which is less
75+
// Then we will insert 3 * 17 rows
76+
// In the insertion, there will be a total of 3 * 17 * 5 * 257 == UInt16.max bindings
77+
// If the test is successful, it means Postgres supports UInt16.max bindings
78+
let columnsCount = 5 * 257
79+
let rowsCount = 3 * 17
80+
81+
let createQuery = PostgresQuery(
82+
unsafeSQL: """
83+
CREATE TABLE table1 (
84+
\((0..<columnsCount).map({ #""int\#($0)" int NOT NULL"# }).joined(separator: ", "))
85+
);
86+
"""
87+
)
88+
try await connection.query(createQuery, logger: .psqlTest)
89+
90+
var binds = PostgresBindings(capacity: Int(UInt16.max))
91+
for _ in (0..<rowsCount) {
92+
for num in (0..<columnsCount) {
93+
try binds.append(num, context: .default)
94+
}
95+
}
96+
XCTAssertEqual(binds.count, Int(UInt16.max))
97+
98+
let insertionValues = (0..<rowsCount).map { rowIndex in
99+
let indices = (0..<columnsCount).map { columnIndex -> String in
100+
"$\(rowIndex * columnsCount + columnIndex + 1)"
101+
}
102+
return "(\(indices.joined(separator: ", ")))"
103+
}.joined(separator: ", ")
104+
let insertionQuery = PostgresQuery(
105+
unsafeSQL: "INSERT INTO table1 VALUES \(insertionValues)",
106+
binds: binds
107+
)
108+
try await connection.query(insertionQuery, logger: .psqlTest)
109+
110+
let countQuery = PostgresQuery(unsafeSQL: "SELECT COUNT(*) FROM table1")
111+
let countRows = try await connection.query(countQuery, logger: .psqlTest)
112+
var countIterator = countRows.makeAsyncIterator()
113+
let insertedRowsCount = try await countIterator.next()?.decode(Int.self, context: .default)
114+
XCTAssertEqual(rowsCount, insertedRowsCount)
115+
116+
let dropQuery = PostgresQuery(unsafeSQL: "DROP TABLE table1")
117+
try await connection.query(dropQuery, logger: .psqlTest)
118+
}
119+
}
120+
67121
#if canImport(Network)
68122
func testSelect10kRowsNetworkFramework() async throws {
69123
let eventLoopGroup = NIOTSEventLoopGroup()

Tests/IntegrationTests/PSQLIntegrationTests.swift

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -330,59 +330,4 @@ final class IntegrationTests: XCTestCase {
330330
}
331331
}
332332

333-
#if swift(>=5.5.2)
334-
func testBindMaximumParameters() async throws {
335-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
336-
defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) }
337-
let eventLoop = eventLoopGroup.next()
338-
339-
try await withTestConnection(on: eventLoop) { connection in
340-
// Max binds limit is UInt16.max which is 65535 which is 3 * 5 * 17 * 257
341-
// Max columns limit is 1664, so we will only make 5 * 257 columns which is less
342-
// Then we will insert 3 * 17 rows
343-
// In the insertion, there will be a total of 3 * 17 * 5 * 257 == UInt16.max bindings
344-
// If the test is successful, it means Postgres supports UInt16.max bindings
345-
let columnsCount = 5 * 257
346-
let rowsCount = 3 * 17
347-
348-
let createQuery = PostgresQuery(
349-
unsafeSQL: """
350-
CREATE TABLE table1 (
351-
\((0..<columnsCount).map({ #""int\#($0)" int NOT NULL"# }).joined(separator: ", "))
352-
);
353-
"""
354-
)
355-
try await connection.query(createQuery, logger: .psqlTest)
356-
357-
var binds = PostgresBindings(capacity: Int(UInt16.max))
358-
for _ in (0..<rowsCount) {
359-
for num in (0..<columnsCount) {
360-
try binds.append(num, context: .default)
361-
}
362-
}
363-
XCTAssertEqual(binds.count, Int(UInt16.max))
364-
365-
let insertionValues = (0..<rowsCount).map { rowIndex in
366-
let indices = (0..<columnsCount).map { columnIndex -> String in
367-
"$\(rowIndex * columnsCount + columnIndex + 1)"
368-
}
369-
return "(\(indices.joined(separator: ", ")))"
370-
}.joined(separator: ", ")
371-
let insertionQuery = PostgresQuery(
372-
unsafeSQL: "INSERT INTO table1 VALUES \(insertionValues)",
373-
binds: binds
374-
)
375-
try await connection.query(insertionQuery, logger: .psqlTest)
376-
377-
let countQuery = PostgresQuery(unsafeSQL: "SELECT COUNT(*) FROM table1")
378-
let countRows = try await connection.query(countQuery, logger: .psqlTest)
379-
var countIterator = countRows.makeAsyncIterator()
380-
let insertedRowsCount = try await countIterator.next()?.decode(Int.self, context: .default)
381-
XCTAssertEqual(rowsCount, insertedRowsCount)
382-
383-
let dropQuery = PostgresQuery(unsafeSQL: "DROP TABLE table1")
384-
try await connection.query(dropQuery, logger: .psqlTest)
385-
}
386-
}
387-
#endif
388333
}

Tests/PostgresNIOTests/New/PostgresRowSequenceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Dispatch
44
import XCTest
55
@testable import PostgresNIO
66

7-
#if swift(>=5.5.2)
7+
#if canImport(_Concurrency)
88
final class PostgresRowSequenceTests: XCTestCase {
99

1010
func testBackpressureWorks() async throws {

dev/generate-postgresrowsequence-multi-decode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ cat <<"EOF"
9696
EOF
9797
echo
9898

99-
echo "#if swift(>=5.5) && canImport(_Concurrency)"
99+
echo "#if canImport(_Concurrency)"
100100
echo "extension AsyncSequence where Element == PostgresRow {"
101101

102102
# note:

0 commit comments

Comments
 (0)