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