-
I'm stumped on this one - I can't shake the error below when adding an Error:
The offending query: pub async fn find_by_slug(pool: &Pool, slug: &str) -> Result<Option<Water>> {
sqlx::query_as!(
Water,
r#"
SELECT
id,
slug,
name,
created_at,
updated_at,
upstream_id
FROM waters WHERE slug = $1
"#,
slug
).fetch_optional(pool).await
} The #[derive(Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Water {
pub id: i64,
pub slug: String,
pub name: String,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub upstream_id: Option<i64>,
} Using the various type-inference modifiers doesn't resolve the issue, e.g.:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
FWIW, the issue was that sqlx is depending on the Resolved by changing: CREATE TABLE waters (
"id" INTEGER PRIMARY KEY,
-- ... ... to ... CREATE TABLE waters (
"id" INTEGER PRIMARY KEY NOT NULL,
-- ... I found the issue by expanding the Docs on option inference here: https://docs.rs/sqlx/latest/sqlx/macro.query.html#nullability-output-columns
|
Beta Was this translation helpful? Give feedback.
FWIW, the issue was that sqlx is depending on the
NOT NULL
flag in the column definition to inferOption<T>
, which I had not included on theid
column.Resolved by changing:
... to ...
I found the issue by expanding the
query_as!
macro and discovering that sqlx was retrievingid
as anOption<i64>
.Docs on option inference here: https://docs.rs/sqlx/latest/sqlx/macro.query.html#nullability-output-columns