首页 > 解决方案 > 使用 MySQL 的 Rust Actix-Web 示例项目 - Arity > 12 项

问题描述

我是 Rust 的新手,正在使用使用 Juniper 和 MySQL 的 Actix-Web“高级”GraphiQL 示例。当我的模型达到 13 列时,我遇到了一个问题,它会引发错误。这一直有效,直到我添加第 13 列。

#[graphql(description = "List of all (View) Items LIKE")]
fn items_view_like(context: &Context, item_number: String) -> FieldResult<Vec<ItemView>> {
    let mut conn = context.dbpool.get().unwrap();
    let items_view = conn
        .prep_exec("select item_number, description, extended_description, item_type, bulk_type, item_product_group, billing_category, stock_unit, price_unit, purchasing_unit, manufacturing_unit, purchase_price, category from v_items WHERE item_number LIKE :item_number", params! {"item_number" => item_number})
        .map(|result| {
            result
                .map(|x| x.unwrap())
                .map(|row| {
                    let (item_number, description, extended_description, item_type, bulk_type, item_product_group, billing_category, stock_unit, price_unit, purchasing_unit, manufacturing_unit, purchase_price, category) = from_row(row);
                    ItemView {
                        item_number,
                        description,
                        extended_description,
                        item_type, 
                        bulk_type,
                        item_product_group,
                        billing_category, 
                        stock_unit,
                        price_unit,
                        purchasing_unit,
                        manufacturing_unit,
                        purchase_price,
                        category

                    }
                })
                .collect()
        })
        .unwrap();
    Ok(items_view)
}

错误:

error[E0277]: the trait bound `(_, _, _, _, _, _, _, _, _, _, _, _, _): FromValue` is not satisfied
   --> src\schemas\root.rs:116:227
    |
116 | ...price, category) = from_row(row);
    |                       ^^^^^^^^ the trait `FromValue` is not implemented for `(_, _, _, _, _, _, _, _, _, _, _, _, _)`

从我能够找到的情况来看,如果 from_row 方法有 12 列,那么我处理更大查询的正确方法是什么?

对此菜鸟的任何帮助将不胜感激。再次感谢。

标签: mysqlrustactix-web

解决方案


问题是 from_row 被定义为最多 12 列。请参阅此处的文档:

将 Row 转换为 FromValue 实现者的元组的特征,最多 12 个。

看看Row::take的替代策略。


推荐阅读