Open
Description
I have found these related issues/pull requests
Description
psql "postgresql://postgres:<password>@<url>:5432/postgres?sslmode=verify-ca&sslrootcert=ca.pem&sslcert=cert.pem&sslkey=key.pem"
This works:
psql (14.11 (Homebrew), server 17.2)
WARNING: psql major version 14, server major version 17.
Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=>
but when I do
DATABASE_URL="postgresql://postgres:<password>@<url>:5432/postgres?sslmode=verify-ca&sslrootcert=ca.pem&sslcert=cert.pem&sslkey=key.pem" cargo sqlx prepare
or
cargo sqlx prepare -D "postgresql://postgres:<password>@<url>:5432/postgres?sslmode=verify-ca&sslrootcert=ca.pem&sslcert=cert.pem&sslkey=key.pem"
I get
error: error communicating with database: No such file or directory (os error 2)
--> src/run_webserver.rs:56:16
|
56 | let rows = sqlx::query!("SELECT version()")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not compile `library` (lib) due to 1 previous error
error: `cargo check` failed with status: exit status: 101
Reproduction steps
Here's my cargo.toml
rustls = "0.23.22"
serde = { version = "1.0.217", features = ["derive"] }
sqlx = { version = "0.8.3", features = [
"chrono",
"json",
"migrate",
"postgres",
"runtime-tokio",
"tls-native-tls",
"tls-rustls",
"rust_decimal",
"uuid",
"sqlite",
] }
tokio = { version = "1.43.0", features = ["full"] }
and the code:
let database_url = env::var("DATABASE_URL").expect("Failed to get DATABASE_URL.");
let pool = PgPoolOptions::new()
.max_connections(10)
.connect(&database_url)
.await?;
let rows = sqlx::query!("SELECT version()")
.fetch_one(&pool)
.await?;
println!("Database version: {}", rows.get(0));
Ok(())
SQLx version
0.8.3
Enabled SQLx features
chrono, json, migrate, postgres, runtime-tokio, tls-native-tls, tls-rustls, rust_decimal, uuid, sqlite
Database server and version
Postgres 17
Operating system
MacOS
Rust version
rustc 1.83.0 (90b35a623 2024-11-26)