Skip to content

Commit 271115e

Browse files
committed
Bump Swift min to 5.10, update README and API docs, clean up some doc comments, run swift-format, fix warning about retroactive conformance in 6.2.
1 parent a4212e1 commit 271115e

File tree

9 files changed

+239
-120
lines changed

9 files changed

+239
-120
lines changed

Package.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
@@ -13,9 +13,9 @@ let package = Package(
1313
.library(name: "PostgresKit", targets: ["PostgresKit"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.21.1"),
17-
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.3"),
18-
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
16+
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.27.0"),
17+
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.33.1"),
18+
.package(url: "https://github.com/vapor/async-kit.git", from: "1.21.0"),
1919
],
2020
targets: [
2121
.target(
@@ -40,6 +40,7 @@ let package = Package(
4040

4141
var swiftSettings: [SwiftSetting] { [
4242
.enableUpcomingFeature("ExistentialAny"),
43+
.enableUpcomingFeature("MemberImportVisibility"),
4344
.enableUpcomingFeature("ConciseMagicFile"),
4445
.enableUpcomingFeature("ForwardTrailingClosures"),
4546
.enableUpcomingFeature("DisableOutwardActorInference"),

README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<p align="center">
2-
<picture>
3-
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/postgres-kit/assets/1130717/02ca33b1-d788-4846-8280-7cd89f09c397">
4-
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/postgres-kit/assets/1130717/91de055b-0e4f-42f3-8257-946ac40d731c">
5-
<img src="https://github.com/vapor/postgres-kit/assets/1130717/91de055b-0e4f-42f3-8257-946ac40d731c" height="96" alt="PostgresKit">
6-
</picture>
2+
<img src="https://design.vapor.codes/images/vapor-postgreskit.svg" height="96" alt="PostgresKit">
73
<br>
84
<br>
95
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
106
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
117
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
128
<a href="https://github.com/vapor/postgres-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/postgres-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
139
<a href="https://codecov.io/github/vapor/postgres-kit"><img src="https://img.shields.io/codecov/c/github/vapor/postgres-kit?style=plastic&logo=codecov&label=codecov"></a>
14-
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+"></a>
10+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
1511
</p>
1612

1713
<br>
@@ -35,16 +31,11 @@ PostgresKit supports the following platforms:
3531

3632
## Overview
3733

38-
PostgresKit is an [SQLKit] driver for PostgreSQL clients. It supports building and serializing Postgres-dialect SQL queries. PostgresKit uses [PostgresNIO] to connect and communicate with the database server asynchronously. [AsyncKit](https://github.com/vapor/async-kit) is used to provide connection pooling.
34+
PostgresKit is an [SQLKit] driver for PostgreSQL clients. It supports building and serializing Postgres-dialect SQL queries. PostgresKit uses [PostgresNIO] to connect and communicate with the database server asynchronously. [AsyncKit] is used to provide connection pooling.
3935

4036
> [!IMPORTANT]
4137
> It is strongly recommended that users who leverage PostgresKit directly (e.g. absent the Fluent ORM layer) take advantage of PostgresNIO's [PostgresClient] API for connection management rather than relying upon the legacy AsyncKit API.
4238
43-
[SQLKit]: https://github.com/vapor/sql-kit
44-
[PostgresNIO]: https://github.com/vapor/postgres-nio
45-
[AsyncKit]: https://github.com/vapor/async-kit
46-
[PostgresClient]: https://api.vapor.codes/postgresnio/documentation/postgresnio/postgresclient
47-
4839
### Configuration
4940

5041
Database connection options and credentials are specified using a `PostgresConfiguration` struct.
@@ -96,7 +87,7 @@ defer { pools.shutdown() }
9687

9788
First create a `PostgresConnectionSource` using the configuration struct. This type is responsible for creating new connections to your database server as needed.
9889

99-
Next, use the connection source to create an `EventLoopGroupConnectionPool`. You will also need to pass an `EventLoopGroup`. For more information on creating an `EventLoopGroup`, visit SwiftNIO's [documentation](https://apple.github.io/swift-nio/docs/current/NIO/index.html). Make sure to shutdown the connection pool before it deinitializes.
90+
Next, use the connection source to create an `EventLoopGroupConnectionPool`. You will also need to pass an `EventLoopGroup`. For more information on creating an `EventLoopGroup`, visit [SwiftNIO's documentation]. Make sure to shutdown the connection pool before it deinitializes.
10091

10192
`EventLoopGroupConnectionPool` is a collection of pools for each event loop. When using `EventLoopGroupConnectionPool` directly, random event loops will be chosen as needed.
10293

@@ -126,7 +117,7 @@ let postgres = pool.database(logger: ...) // PostgresDatabase
126117
let rows = try postgres.simpleQuery("SELECT version();").wait()
127118
```
128119

129-
Visit [PostgresNIO's docs](https://github.com/vapor/postgres-nio) for more information on using `PostgresDatabase`.
120+
Visit [PostgresNIO's docs] for more information on using `PostgresDatabase`.
130121

131122
### SQLDatabase
132123

@@ -137,4 +128,12 @@ let sql = postgres.sql() // SQLDatabase
137128
let planets = try sql.select().column("*").from("planets").all().wait()
138129
```
139130

140-
Visit [SQLKit's docs](https://github.com/vapor/sql-kit) for more information on using `SQLDatabase`.
131+
Visit [SQLKit's docs] for more information on using `SQLDatabase`.
132+
133+
[SQLKit]: https://github.com/vapor/sql-kit
134+
[SQLKit's docs]: https://api.vapor.codes/sqlkit/documentation/sqlkit
135+
[PostgresNIO]: https://github.com/vapor/postgres-nio
136+
[PostgresNIO's docs]: https://api.vapor.codes/postgresnio/documentation/postgresnio
137+
[AsyncKit]: https://github.com/vapor/async-kit
138+
[PostgresClient]: https://api.vapor.codes/postgresnio/documentation/postgresnio/postgresclient
139+
[SwiftNIO's documentation]: https://swiftpackageindex.com/apple/swift-nio/documentation/nio

Sources/PostgresKit/Docs.docc/PostgresKit.md

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,127 @@
44
@TitleHeading(Package)
55
}
66

7-
PostgresKit is a library providing an SQLKit driver for PostgresNIO.
7+
🐘 Non-blocking, event-driven Swift client for PostgreSQL.
8+
9+
### Usage
10+
11+
Use the SPM string to easily include the dependendency in your `Package.swift` file.
12+
13+
```swift
14+
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0")
15+
```
16+
17+
### Supported Platforms
18+
19+
PostgresKit supports the following platforms:
20+
21+
- Ubuntu 20.04+
22+
- macOS 10.15+
823

924
## Overview
1025

11-
This package provides the "foundational" level of support for using [Fluent] with PostgreSQL by implementing the requirements of an [SQLKit] driver. It is responsible for:
26+
PostgresKit is an [SQLKit] driver for PostgreSQL clients. It supports building and serializing Postgres-dialect SQL queries. PostgresKit uses [PostgresNIO] to connect and communicate with the database server asynchronously. [AsyncKit] is used to provide connection pooling.
27+
28+
> Important: It is strongly recommended that users who leverage PostgresKit directly (e.g. absent the Fluent ORM layer) take advantage of PostgresNIO's [PostgresClient] API for connection management rather than relying upon the legacy AsyncKit API.
29+
30+
### Configuration
31+
32+
Database connection options and credentials are specified using a ``SQLPostgresConfiguration`` struct.
33+
34+
```swift
35+
import PostgresKit
36+
37+
let configuration = SQLPostgresConfiguration(
38+
hostname: "localhost",
39+
username: "vapor_username",
40+
password: "vapor_password",
41+
database: "vapor_database"
42+
)
43+
```
44+
45+
URL-based configuration is also supported.
46+
47+
```swift
48+
guard let configuration = SQLPostgresConfiguration(url: "postgres://...") else {
49+
...
50+
}
51+
```
52+
53+
To connect via unix-domain sockets, use ``SQLPostgresConfiguration/init(unixDomainSocketPath:username:password:database:)`` instead of ``SQLPostgresConfiguration/init(hostname:port:username:password:database:tls:)``.
54+
55+
```swift
56+
let configuration = PostgresConfiguration(
57+
unixDomainSocketPath: "/path/to/socket",
58+
username: "vapor_username",
59+
password: "vapor_password",
60+
database: "vapor_database"
61+
)
62+
```
63+
64+
### Connection Pool
65+
66+
Once you have a ``SQLPostgresConfiguration``, you can use it to create a connection source and pool.
67+
68+
```swift
69+
let eventLoopGroup: EventLoopGroup = ...
70+
defer { try! eventLoopGroup.syncShutdown() }
71+
72+
let pools = EventLoopGroupConnectionPool(
73+
source: PostgresConnectionSource(configuration: configuration),
74+
on: eventLoopGroup
75+
)
76+
defer { pools.shutdown() }
77+
```
78+
79+
First create a ``PostgresConnectionSource`` using the configuration struct. This type is responsible for creating new connections to your database server as needed.
80+
81+
Next, use the connection source to create an `EventLoopGroupConnectionPool`. You will also need to pass an `EventLoopGroup`. For more information on creating an `EventLoopGroup`, visit [SwiftNIO's documentation]. Make sure to shutdown the connection pool before it deinitializes.
82+
83+
`EventLoopGroupConnectionPool` is a collection of pools for each event loop. When using `EventLoopGroupConnectionPool` directly, random event loops will be chosen as needed.
84+
85+
```swift
86+
pools.withConnection { conn
87+
print(conn) // PostgresConnection on randomly chosen event loop
88+
}
89+
```
90+
91+
To get a pool for a specific event loop, use `pool(for:)`. This returns an `EventLoopConnectionPool`.
92+
93+
```swift
94+
let eventLoop: EventLoop = ...
95+
let pool = pools.pool(for: eventLoop)
96+
97+
pool.withConnection { conn
98+
print(conn) // PostgresConnection on eventLoop
99+
}
100+
```
101+
102+
### PostgresDatabase
103+
104+
Both `EventLoopGroupConnectionPool` and `EventLoopConnectionPool` can be used to create instances of `PostgresDatabase`.
12105

13-
- Managing the underlying PostgreSQL library ([PostgresNIO]),
14-
- Providing a two-way bridge between PostgresNIO and SQLKit's generic data and metadata formats, and
15-
- Presenting an interface for establishing, managing, and interacting with database connections via [AsyncKit].
106+
```swift
107+
let postgres = pool.database(logger: ...) // PostgresDatabase
108+
let rows = try postgres.simpleQuery("SELECT version();").wait()
109+
```
16110

17-
> Important: It is strongly recommended that users who leverage PostgresKit directly (e.g. absent the Fluent ORM layer) take advantage of PostgresNIO's [PostgresClient] API for connection management rather than relying upon the legacy AsyncKit-based support.
111+
Visit [PostgresNIO's docs] for more information on using `PostgresDatabase`.
18112

19-
> Tip: A FluentKit driver for PostgreSQL is provided by the [FluentPostgresDriver] package.
113+
### SQLDatabase
20114

21-
## Version Support
115+
A `PostgresDatabase` can be used to create an instance of `SQLDatabase`.
22116

23-
This package uses [PostgresNIO] for all underlying database interactions. It is compatible with all versions of PostgreSQL and all platforms supported by that package.
117+
```swift
118+
let sql = postgres.sql() // SQLDatabase
119+
let planets = try sql.select().column("*").from("planets").all().wait()
120+
```
24121

25-
> Caution: There is one exception to the above at the time of this writing: This package requires Swift 5.8 or newer, whereas PostgresNIO continues to support Swift 5.6.
122+
Visit [SQLKit's docs] for more information on using `SQLDatabase`.
26123

27-
[SQLKit]: https://swiftpackageindex.com/vapor/sql-kit
28-
[PostgresNIO]: https://swiftpackageindex.com/vapor/postgres-nio
29-
[Fluent]: https://swiftpackageindex.com/vapor/fluent-kit
30-
[FluentPostgresDriver]: https://swiftpackageindex.com/vapor/fluent-postgres-driver
31-
[AsyncKit]: https://swiftpackageindex.com/vapor/async-kit
124+
[SQLKit]: https://github.com/vapor/sql-kit
125+
[SQLKit's docs]: https://api.vapor.codes/sqlkit/documentation/sqlkit
126+
[PostgresNIO]: https://github.com/vapor/postgres-nio
127+
[PostgresNIO's docs]: https://api.vapor.codes/postgresnio/documentation/postgresnio
128+
[AsyncKit]: https://github.com/vapor/async-kit
32129
[PostgresClient]: https://api.vapor.codes/postgresnio/documentation/postgresnio/postgresclient
130+
[SwiftNIO's documentation]: https://swiftpackageindex.com/apple/swift-nio/documentation/nio
Lines changed: 17 additions & 13 deletions
Loading

Sources/PostgresKit/Docs.docc/theme-settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"logo-shape": { "dark": "#000", "light": "#fff" },
1616
"fill": { "dark": "#000", "light": "#fff" }
1717
},
18-
"icons": { "technology": "/postgreskit/images/vapor-postgreskit-logo.svg" }
18+
"icons": { "technology": "/postgreskit/images/PostgresKit/vapor-postgreskit-logo.svg" }
1919
},
2020
"features": {
2121
"quickNavigation": { "enable": true },

0 commit comments

Comments
 (0)