hotfix: 修复get_all_projects接口description字段NULL值处理问题

- 修复project_repository.rs中row_to_project函数对description字段的错误处理
- 将description字段从String类型改为Option<String>类型正确处理NULL值
- 修复material_repository.rs中类似的问题
- 解决'Invalid column type Null at index: 3, name: description'错误

问题根本原因:
数据库schema允许description为NULL,但代码尝试获取非空String类型,
当description为NULL时导致类型转换失败。

修复方案:
使用Option<String>类型和filter方法正确处理NULL和空字符串情况。
This commit is contained in:
imeepos 2025-07-16 13:58:04 +08:00
parent 94d58a5bc5
commit a4cacf42da
2 changed files with 4 additions and 3 deletions

View File

@ -577,7 +577,7 @@ impl MaterialRepository {
id: row.get(0)?,
name: row.get(1)?,
path: row.get(2)?,
description: row.get(3)?,
description: row.get::<_, Option<String>>(3)?.filter(|s| !s.is_empty()),
created_at,
updated_at,
is_active: row.get::<_, i32>(6)? != 0,

View File

@ -194,8 +194,9 @@ impl ProjectRepository {
.map_err(|_| rusqlite::Error::InvalidColumnType(5, "updated_at".to_string(), rusqlite::types::Type::Text))?
.with_timezone(&Utc);
let description: String = row.get(3)?;
let description = if description.is_empty() { None } else { Some(description) };
// 正确处理可能为NULL的description字段
let description: Option<String> = row.get(3)?;
let description = description.filter(|s| !s.is_empty());
Ok(Project {
id: row.get(0)?,