-
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
Make PgConnectOptions
fields pub
instead of pub(crate)
#2764
Comments
+1 for MySqlConnectOptions. |
Another use case for this is testing in application using e.g. rocket. Right now you've to hardcode the connect URL and manually modify it based on the database name you can get from PgConnectOptions. https://wtjungle.com/blog/integration-testing-rocket-sqlx/ is a good example of what currently has to be done to execute tests with sqlx support. It shouldn't be that hard. Would a simple PR that makes these fields |
Public fields are a semver hazard that I'm not ready to accept. I just recently merged a PR to add a getter for the hostname to I would accept PRs to add getters for the port, and to add both getters to |
The way I solved this right now was parsing the async fn get_test_client(pg_connect_options: PgConnectOptions) -> Client {
use url::Url;
lazy_static::lazy_static! {
static ref ENV_DB_URL: Url = {
let env_database_url = std::env::var("DATABASE_URL").unwrap();
Url::parse(&env_database_url).unwrap()
};
}
let db_name = pg_connect_options.get_database().unwrap();
let db_url = {
let mut u = ENV_DB_URL.clone();
u.set_path(db_name);
u
};
let db_url = db_url.to_string();
Client::tracked(build_rocket(&db_url)).await.unwrap()
} It is a few lines of code but given that the database is usually define with that environment variable and since sqlx isn't changing port or host that should be good enough. |
When parsing db config from a custom struct that includes
url: String
one still may need access to the underlying parsed values such ashost
,port
etc.As you can see here the fields are all private: https://docs.rs/sqlx/latest/sqlx/struct.PgConnection.html
Use cases:
The text was updated successfully, but these errors were encountered: