-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MySQL UDS Support #450
MySQL UDS Support #450
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a light code review -- I don't know enough about the workings of SQLx to comment on the correctness, but hopefully this is still useful.
sqlx-core/src/net/socket.rs
Outdated
#[cfg(unix)] | ||
pub async fn connect_uds(path: impl AsRef<Path>) -> io::Result<Self> { | ||
sqlx_rt::UnixStream::connect(path.as_ref()) | ||
.await | ||
.map(Socket::Unix) | ||
} | ||
|
||
#[cfg(not(unix))] | ||
pub async fn connect_uds(_: impl AsRef<Path>) -> io::Result<Self> { | ||
Err(io::Error( | ||
io::ErrorKind::Other, | ||
"Unix domain sockets are not supported outside Unix platforms.", | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat -- this is how std works these days as well. Also opens up the option to later enable it on Windows.
- Adds support for Unix Domain Sockets on MySQL - Allows setting the socket path in PostgreSQL connection options - ... and MySQL connection options
- If starts with a leading `/`, use socket - If not, use host
Tested mysql with a test app, running mariadb locally and there's a socket file:
A test app with a simple select: use sqlx::{Connect, MySqlConnection};
#[async_std::main]
async fn main() -> anyhow::Result<()> {
let mut conn = MySqlConnection::connect("mysql://root@localhost/mysql?socket=/run/mysqld/mysqld.sock").await?;
let row = sqlx::query("SELECT 1").fetch_one(&mut conn).await?;
dbg!(row);
Ok(())
} Seems to connect and output the row. |
There's a slight problem with PostgreSQL here, having a socket in
Now my test app is this: use sqlx::{Connect, PgConnection, Row};
#[async_std::main]
async fn main() -> anyhow::Result<()> {
let mut conn =
PgConnection::connect("postgresql://postgres@localhost:5433/postgres?host=/var/run/postgresql").await?;
let row = sqlx::query("SELECT 1 as val").fetch_one(&mut conn).await?;
let val: i32 = row.get("val");
dbg!(val);
Ok(())
} If I don't specity the hostname, I'm getting an error:
Seems like the url parsing doesn't like when the hostname is missing. If I add |
Looks good to me. Thank you for cleaning up and generalizing the UDS code @pimeys ❤️ |
|
||
#[cfg(not(unix))] | ||
pub async fn connect_uds(_: impl AsRef<Path>) -> io::Result<Self> { | ||
Err(io::Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, our CI didn't catch this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a fix to master
.
Fixes issue #449