You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To connect via unix-domain sockets, use ``SQLPostgresConfiguration/init(unixDomainSocketPath:username:password:database:)`` instead of ``SQLPostgresConfiguration/init(hostname:port:username:password:database:tls:)``.
62
62
63
63
```swift
64
-
let configuration =PostgresConfiguration(
64
+
let configuration =SQLPostgresConfiguration(
65
65
unixDomainSocketPath: "/path/to/socket",
66
66
username: "vapor_username",
67
67
password: "vapor_password",
68
68
database: "vapor_database"
69
69
)
70
70
```
71
71
72
-
### Connection Pool
72
+
### Connection Pool (Modern PostgresNIO)
73
+
74
+
You don't need a ``SQLPostgresConfiguration`` to create a `PostgresClient`, an instance of PostgresNIO's modern connection pool. Instead, use `PostgresClient`'s native configuration type:
75
+
76
+
```swift
77
+
let configuration = PostgresClient.Configuration(
78
+
host: "localhost",
79
+
username: "vapor_username",
80
+
password: "vapor_password",
81
+
database: "vapor_database",
82
+
tls: .prefer(.makeClientConfiguration())
83
+
)
84
+
let psqlClient =PostgresClient(configuration: configuration)
85
+
86
+
// Start a Task to run the client:
87
+
let clientTask =Task { await client.run() }
88
+
// Or, if you're using ServiceLifecycle, add the client to a ServiceGroup:
You can then lease a `PostgresConnection` from the client:
93
+
94
+
```swift
95
+
tryawait client.withConnection { conn in
96
+
print(conn) // PostgresConnection managed by PostgresClient's connection pool
97
+
}
98
+
```
99
+
100
+
> [!NOTE]
101
+
> `PostgresClient.Configuration` does not support URL-based configuration. If you want to handle URLs, you can create an instance of `SQLPostgresConfiguration` and translate it into a `PostgresClient.Configuration`:
> AsyncKit is deprecated; using it is strongly discouraged. You should not use this setup unless you are also working with FluentKit, which at the time of this writing is not compatible with `PostgresClient`.
73
130
74
131
Once you have a ``SQLPostgresConfiguration``, you can use it to create a connection source and pool.
To connect via unix-domain sockets, use ``SQLPostgresConfiguration/init(unixDomainSocketPath:username:password:database:)`` instead of ``SQLPostgresConfiguration/init(hostname:port:username:password:database:tls:)``.
54
54
55
55
```swift
56
-
let configuration =PostgresConfiguration(
56
+
let configuration =SQLPostgresConfiguration(
57
57
unixDomainSocketPath: "/path/to/socket",
58
58
username: "vapor_username",
59
59
password: "vapor_password",
60
60
database: "vapor_database"
61
61
)
62
62
```
63
63
64
-
### Connection Pool
64
+
### Connection Pool (Modern PostgresNIO)
65
+
66
+
You don't need a ``SQLPostgresConfiguration`` to create a `PostgresClient`, an instance of PostgresNIO's modern connection pool. Instead, use `PostgresClient`'s native configuration type:
67
+
68
+
```swift
69
+
let configuration = PostgresClient.Configuration(
70
+
host: "localhost",
71
+
username: "vapor_username",
72
+
password: "vapor_password",
73
+
database: "vapor_database",
74
+
tls: .prefer(.makeClientConfiguration())
75
+
)
76
+
let psqlClient =PostgresClient(configuration: configuration)
77
+
78
+
// Start a Task to run the client; be sure you cancel this task before exiting:
79
+
let clientTask =Task { await psqlClient.run() }
80
+
// Or, if you're using ServiceLifecycle, add the client to a ServiceGroup:
You can then lease a `PostgresConnection` from the client:
85
+
86
+
```swift
87
+
tryawait client.withConnection { conn in
88
+
print(conn) // PostgresConnection managed by PostgresClient's connection pool
89
+
}
90
+
```
91
+
92
+
> Note: `PostgresClient.Configuration` does not support URL-based configuration. If you want to handle URLs, you can create an instance of `SQLPostgresConfiguration` and translate it into a `PostgresClient.Configuration`:
> Warning: AsyncKit is deprecated; using it is strongly discouraged. You should not use this setup unless you are also working with FluentKit, which at the time of this writing is not compatible with `PostgresClient`.
65
120
66
121
Once you have a ``SQLPostgresConfiguration``, you can use it to create a connection source and pool.
67
122
@@ -83,7 +138,7 @@ Next, use the connection source to create an `EventLoopGroupConnectionPool`. You
83
138
`EventLoopGroupConnectionPool` is a collection of pools for each event loop. When using `EventLoopGroupConnectionPool` directly, random event loops will be chosen as needed.
84
139
85
140
```swift
86
-
pools.withConnection { conn
141
+
pools.withConnection { conn in
87
142
print(conn) // PostgresConnection on randomly chosen event loop
0 commit comments