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:
parent
94d58a5bc5
commit
a4cacf42da
|
|
@ -577,7 +577,7 @@ impl MaterialRepository {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
name: row.get(1)?,
|
name: row.get(1)?,
|
||||||
path: row.get(2)?,
|
path: row.get(2)?,
|
||||||
description: row.get(3)?,
|
description: row.get::<_, Option<String>>(3)?.filter(|s| !s.is_empty()),
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
is_active: row.get::<_, i32>(6)? != 0,
|
is_active: row.get::<_, i32>(6)? != 0,
|
||||||
|
|
|
||||||
|
|
@ -194,8 +194,9 @@ impl ProjectRepository {
|
||||||
.map_err(|_| rusqlite::Error::InvalidColumnType(5, "updated_at".to_string(), rusqlite::types::Type::Text))?
|
.map_err(|_| rusqlite::Error::InvalidColumnType(5, "updated_at".to_string(), rusqlite::types::Type::Text))?
|
||||||
.with_timezone(&Utc);
|
.with_timezone(&Utc);
|
||||||
|
|
||||||
let description: String = row.get(3)?;
|
// 正确处理可能为NULL的description字段
|
||||||
let description = if description.is_empty() { None } else { Some(description) };
|
let description: Option<String> = row.get(3)?;
|
||||||
|
let description = description.filter(|s| !s.is_empty());
|
||||||
|
|
||||||
Ok(Project {
|
Ok(Project {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue