rbatis py_sql 写了两个示例:
#[crud_table]
#[derive(Clone, Debug)]
pub struct Posts {
pub id: Option<i32>,
pub title: Option<String>,
pub body: Option<String>,
pub created_at: Option<rbatis::DateTimeNative>,
}
/// 这个没有参数可以成功执行
#[py_sql("select * from posts")]
async fn find_posts(rb: Arc<Rbatis>) -> Result<Vec<Posts>, Error> { todo!() }
/// 这个传入 id 参数就报错
#[py_sql("select * from posts where id=#{id} limit 1")]
async fn find_one(rb: Arc<Rbatis>, id: i32) -> Option<Posts> { todo!() }
错误如下:
error[E0308]: mismatched types
--> src/bin/rb.rs:67:1
|
67 | #[py_sql("select * from posts where id=#{id} limit 1")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found `i32`
|
= note: expected reference `&_`
found type `i32`
= note: this error originates in the attribute macro `py_sql` (in Nightly builds, run with -Z macro-backtrace for more info)
麻烦大佬指导下 _
1
共 3 条评论, 1 页
评论区
写评论这个不行一样的错
--
👇
苦瓜小仔: 试试
#[py_sql("select * from posts where id=#{&id} limit 1")]
?感谢 wx 群的 洋仔 改成 &i32 可以了 如下:
试试
#[py_sql("select * from posts where id=#{&id} limit 1")]
?