1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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);
}
|