英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论