Skip to content
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

cargo sqlx prepare - exactly same url works for the psql command, but not when I run cargo sqlx prepare #3737

Open
jesikmin opened this issue Feb 12, 2025 · 0 comments
Labels

Comments

@jesikmin
Copy link

jesikmin commented Feb 12, 2025

I have found these related issues/pull requests

Maybe #1716 and #1162

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)

@jesikmin jesikmin added the bug label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant