New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to determine whether the select result is no record found? #457
Comments
Todolist 这个结构体 解析uint失败的column成员 |
todolist中没有存在的记录就会报这个错, 有记录就没有问题,查询结果正常。 |
If there is no record in the todolist, this error will be reported. If there is a record, there will be no problem and the query result will be normal. |
可以告诉我数据库类型,表结构体的定义,以及 数据库表的数据吗? |
Can you tell me the database type, the definition of the table structure, and the data of the database table? |
mysql 8
···
|
mysql 8
···
|
todolist中没有存在的记录就会报这个错, |
谢谢, OK 了 |
Thank you, OK |
我更新rbs序列化框架,提示更新为 |
推荐使用crud! 宏内置的函数,更方便。 #[macro_use]
extern crate rbatis;
pub mod init;
use crate::init::init_db;
use rbatis::rbdc::datetime::DateTime;
use serde_json::json;
/// table
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Activity {
pub id: Option<String>,
pub name: Option<String>,
pub pc_link: Option<String>,
pub h5_link: Option<String>,
pub pc_banner_img: Option<String>,
pub h5_banner_img: Option<String>,
pub sort: Option<String>,
pub status: Option<i32>,
pub remark: Option<String>,
pub create_time: Option<DateTime>,
pub version: Option<i64>,
pub delete_flag: Option<i32>,
}
crud!(Activity {});
impl_select!(Activity{select_all_by_id(id:&str,name:&str) => "`where id = #{id} and name = #{name}`"});
impl_select!(Activity{select_by_id(id:&str) -> Option => "`where id = #{id} limit 1`"});
#[tokio::main]
pub async fn main() {
fast_log::init(
fast_log::Config::new()
.console()
.level(log::LevelFilter::Debug),
)
.expect("rbatis init fail");
let rb = init_db().await;
let data = Activity::select_by_column(&rb, "id", "1").await;
println!("select_by_id = {}", json!(data));
let data = Activity::select_all_by_id(&rb, "1", "1").await;
println!("select_all_by_id = {}", json!(data));
let data = Activity::select_by_id(&rb, "1").await;
println!("select_by_id = {}", json!(data));
} |
怎么判断select结果是no record found?
pub async fn select_todo_by_id(id: u64) -> Result<Todolist, rbatis::rbdc::Error> { let rs = RB .query_decode("select * from todolist where id = ?", vec![Value::U64(id)]) .await?; Ok(rs) }
现在错误打印出来的是以下信息
E("error while decoding value: invalid type: unit value, expected struct Todolist")
The text was updated successfully, but these errors were encountered: