import { getDb } from "./index"; import { v4 as uuid } from "uuid"; export interface Project { id: string; name: string; path: string; created_at: number; updated_at: number; } export function listProjects(): Project[] { return getDb() .prepare("SELECT * FROM projects ORDER BY updated_at DESC") .all() as Project[]; } export function getProject(id: string): Project | undefined { return getDb() .prepare("SELECT * FROM projects WHERE id = ?") .get(id) as Project | undefined; } export function createProject(name: string, projectPath: string): Project { const db = getDb(); const id = uuid(); const now = Math.floor(Date.now() / 1000); db.prepare( "INSERT INTO projects (id, name, path, created_at, updated_at) VALUES (?, ?, ?, ?, ?)" ).run(id, name, projectPath, now, now); return { id, name, path: projectPath, created_at: now, updated_at: now }; } export function deleteProject(id: string): void { getDb().prepare("DELETE FROM projects WHERE id = ?").run(id); }