错误源于宏 $crate::sqlx_macros::expand_query,该宏来源于宏 sqlx::query_as 的展开。

huangapple go评论56阅读模式
英文:

error originates in the macro $crate::sqlx_macros::expand_query which comes from the expansion of the macro sqlx::query_as

问题

错误消息显示在解码第 0 列时发生了错误,预期值在第 13 行第 5 列。您正在使用 sqlx 与 Axum 和 postgres。

以下是您的代码部分的翻译:

let user = sqlx::query_as!(
        User,
        "SELECT * FROM users WHERE pan = $1",
        body.pan
    )
    .fetch_optional(&data.db)
    .await
[dependencies]
argon2 = "0.5.0"
axum = "0.6.18"
axum-extra = { version = "0.7.4", features = ["cookie"] }
chrono = { version = "0.4.26", features = ["serde"] }
dotenv = "0.15.0"
sqlx = { version = "0.7.0", features = ["runtime-async-std-native-tls", "postgres", "chrono", "uuid"] }
time = "0.3.22"
tokio = { version = "1.29.1", features = ["full"] }
uuid = { version = "1.4.0", features = ["serde", "v4"] }
英文:

My database and model have all the relevant fields. I want to send query to database, but I faced this error.:

error: error occurred while decoding column 0: expected value at line 13 column 5
   --> src/handler.rs:98:16
    |
98  |       let user = sqlx::queryas!(
    |  __^
99  | |         User,
100 | |         "SELECT * FROM users WHERE pan = $1",
101 | |         body.pan
102 | |     )
    | |__^
    |
    = note: this error originates in the macro $crate::sqlx_macros::expand_query which comes from the expansion of the macro sqlx::query_as (in Nightly builds, run with -Z macro-backtrace for more info)

I am using sqlx with Axum and postgres.

Code

let user = sqlx::query_as!(
        User,
        "SELECT * FROM users WHERE pan = $1",
        body.pan
    )
    .fetch_optional(&data.db)
    .await
[dependencies]
argon2 = "0.5.0"
axum = "0.6.18"
axum-extra = { version = "0.7.4", features = ["cookie"] }
chrono = { version = "0.4.26", features = ["serde"] }
dotenv = "0.15.0"
sqlx = { version = "0.7.0", features = ["runtime-async-std-native-tls", "postgres", "chrono", "uuid"] }
time = "0.3.22"
tokio = { version = "1.29.1", features = ["full"] }
uuid = { version = "1.4.0", features = ["serde", "v4"] }

答案1

得分: 1

我在更新到新版本(0.7.x)SQLx时也遇到了这个不太有帮助的错误。

当我降级到版本0.6.3时,错误消息又变得有帮助了。

我还没有开始尝试查找这两个版本之间发生了什么变化。

英文:

i also got this unhelpful error when i updated to the new version (0.7.x) SQLx.

The errors became helpful again when i downgraded to version 0.6.3.

I haven't done any work trying to figure out what changed between those two versions yet.

答案2

得分: 1

尝试在Cargo.toml中降级你的SQLx版本,我在使用SQLx 0.7时遇到了相同的问题,降级到版本0.6.3后问题解决了。

英文:

Try downgrading your SQLx version in Cargo.toml, I encountered the same issue with SQLx 0.7 and it went away after downgrading to version 0.6.3

huangapple
  • 本文由 发表于 2023年7月6日 14:11:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定