Commit d9725f3
committed
feat: add custom socket transport support for Postgres and MySQL
Add methods to PgConnection and MySqlConnection that accept pre-connected
sockets implementing AsyncRead + AsyncWrite, enabling custom transport
layers (vsock, QUIC, turmoil, SSH tunnels, etc.) without forking sqlx.
Per maintainer feedback on #4187, this uses AsyncRead + AsyncWrite traits
instead of exposing the internal Socket trait. Two separate methods are
provided for each runtime's trait set:
- connect_with_custom_tokio(): accepts tokio::io::{AsyncRead, AsyncWrite}
- connect_with_custom_futures(): accepts futures_io::{AsyncRead, AsyncWrite}
Also adds PoolOptions::connector() so pools can use custom transports:
PgPoolOptions::new()
.connector(|options| async move {
let socket = VsockStream::connect(addr).await?;
PgConnection::connect_with_custom_tokio(socket, &options).await
})
.connect_with(options)
.await?
TLS upgrade is negotiated automatically based on the connection options.
No new public trait exposure. No behavioral changes to existing code.1 parent 75bc048 commit d9725f3
11 files changed
Lines changed: 791 additions & 7 deletions
File tree
- sqlx-core/src
- net
- socket
- pool
- sqlx-mysql
- src/connection
- sqlx-postgres
- src/connection
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments