diff --git a/crates/rtss_db/src/db_access/user.rs b/crates/rtss_db/src/db_access/user.rs index aa64cc8..f6e688f 100644 --- a/crates/rtss_db/src/db_access/user.rs +++ b/crates/rtss_db/src/db_access/user.rs @@ -77,9 +77,10 @@ impl UserPageFilter { )); } if clauses.is_empty() { - return "".to_string(); + "".to_string() + } else { + format!("WHERE {}", clauses.join(" AND ")) } - clauses.join(" AND ") } } @@ -370,11 +371,27 @@ mod tests { ]; accessor.sync_user(users.as_slice()).await?; // 分页查询检查是否更新成功 - let page_result = accessor.query_user_page(page, filter.clone()).await?; + let page_result = accessor + .query_user_page(page.clone(), filter.clone()) + .await?; assert_eq!(page_result.total, 3); assert_eq!(page_result.data.len(), 3); println!("{:?}", page_result); + // 带过滤条件的分页查询 + let filter = UserPageFilter { + id: Some(1), + name: None, + email: None, + mobile: None, + roles: None, + }; + let page_result = accessor + .query_user_page(page.clone(), filter.clone()) + .await?; + assert_eq!(page_result.total, 1); + assert_eq!(page_result.data.len(), 1); + Ok(()) } }