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

macro uses wrong casing causing warnings in rust-analyzer #3361

Closed
liciana24 opened this issue Jul 22, 2024 · 0 comments · Fixed by #3454
Closed

macro uses wrong casing causing warnings in rust-analyzer #3361

liciana24 opened this issue Jul 22, 2024 · 0 comments · Fixed by #3454
Labels

Comments

@liciana24
Copy link

Bug Description

rust-analyzer and cargo complains about the casing of a variable leading to false negatives

Minimal Reproduction

use sqlx::{prelude::FromRow, Connection, SqliteConnection};

const DATABASE_URL: &str = "./mydb/sqlite";

#[derive(Debug, FromRow)]
#[sqlx(rename_all = "UPPERCASE")]
pub struct ObjInfo {
    pub name: String,
}

pub async fn get_info(name: &str) -> Result<ObjInfo, Box<dyn std::error::Error>> {
    let mut conn = SqliteConnection::connect(DATABASE_URL).await?;
    let param =  format!("{}%", name);
    let record = sqlx::query!("SELECT MYNAME FROM mytable WHERE MYNAME = ?", param)
        .fetch_one(&mut conn)
        .await?;

    Ok(ObjInfo {
        name: record.MYNAME.unwrap_or_default()
    })
}

gives the error on the query as so:

Field `MYNAME` should have snake_case name, e.g. `myname`
Variable `sqlx_query_as_NAME` should have snake_case name, e.g. `sqlx_query_as_name`

Info

  • SQLx version: 0.7.4
  • SQLx features enabled: sqlx = { version = "0.7.4", features = ["chrono", "macros", "runtime-tokio", "sqlite"] }
  • Database server and version: Sqlite
  • Operating system: windows and openbsd
  • rustc --version: rustc 1.79.0 (129f3b996 2024-06-10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant