神奇的option, uuid

 

business_model_id, transaction_type_id 这2个字段在数据库都是not null,

 

 

pub async fn get_model_relation_transaction_types() -> Result<Vec<(Uuid, Uuid)>, sqlx::Error> {
    let pool = db::pool();
    let relations = sqlx::query!(r#"
        SELECT business_model_id as "business_model_id!",
               transaction_type_id as "transaction_type_id!"
        FROM biz_mdoel_relate_transaction_type
        WHERE deleted = false
    "#)
        .fetch_all(pool)
        .await?
        .into_iter()
        .map(|r| (r.business_model_id, r.transaction_type_id))
        .collect();
    Ok(relations)
}

  

 

这样写, 错误.

pub async fn get_model_relation_transaction_types() -> Result<Vec<(Uuid, Uuid)>, sqlx::Error> {
    let pool = db::pool();

    let relations = sqlx::query!(r#"
        SELECT business_model_id, transaction_type_id
        FROM biz_mdoel_relate_transaction_type
        WHERE deleted = false
    "#)
        .fetch_all(pool)
        .await?
        .into_iter()
        .map(|r| (r.business_model_id, r.transaction_type_id))
        .collect();

    Ok(relations)
}

  

这样写也错误.

pub async fn get_model_relation_transaction_types() -> Result<Vec<(Uuid, Uuid)>, sqlx::Error> {
    let pool = db::pool();

    let relations = sqlx::query!(r#"
        SELECT business_model_id, transaction_type_id
        FROM biz_mdoel_relate_transaction_type
        WHERE deleted = false
    "#)
        .fetch_all(pool)
        .await?
        .into_iter()
        .map(|r| (
            r.business_model_id.expect("business_model_id should not be NULL"),
            r.transaction_type_id.expect("transaction_type_id should not be NULL")
        ))
        .collect();

    Ok(relations)
}

  

posted @ 2026-02-14 21:11  CrossPython  阅读(2)  评论(0)    收藏  举报