feat 项目表crud

This commit is contained in:
Ironsp
2026-09-10 16:15:05 +08:00
parent b670e06bc9
commit 903019b15a

View File

@@ -5,19 +5,21 @@ const TABLE = 'project'
export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_name TEXT NOT NULL,
project_type TEXT,
status TEXT DEFAULT 'offline',
stake_range TEXT,
total_area REAL,
status INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`
export interface Project {
id?: number
project_name: string
project_type?: string
status?: string
created_at?: string
updated_at?: string
id?: number // 主键,自增
project_name: string // 项目名称,必填
stake_range: string // 项目范围,可选
total_area: number // 项目总面积,可选
status: 0 | 1 // 项目状态,0:未完成,1:已完成,默认0
created_at?: string // 创建时间,默认当前时间
updated_at?: string // 更新时间,默认当前时间
}
/** 查询全部项目 */
@@ -30,19 +32,19 @@ export async function selectById(id: number): Promise<Project | null> {
return DB.selectById(TABLE, id)
}
/** 按状态查询 */
export async function selectByStatus(status: string): Promise<Project[]> {
/** 按状态查询(0=进行中, 1=结束) */
export async function selectByStatus(status: 0 | 1): Promise<Project[]> {
return DB.selectByField(TABLE, 'status', status)
}
/** 新增项目 */
export async function insert(data: Project): Promise<any> {
export async function insert(data: Omit<Project, 'id'>): Promise<any> {
return DB.insert(TABLE, data)
}
/** 更新项目 */
export async function update(id: number, data: Partial<Project>): Promise<any> {
return DB.update(TABLE, data, `id = ${id}`)
return DB.update(TABLE, { ...data, updated_at: new Date().toISOString() }, `id = ${id}`)
}
/** 删除项目 */