From 18207bee18b9e4dc7f46c2560b38643e7df33776 Mon Sep 17 00:00:00 2001 From: soul-walker <31162815+soul-walker@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rtss_db/src/db_access/user.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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(()) } }