aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/db/projects.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/db/projects.ts')
-rw-r--r--src/main/db/projects.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/db/projects.ts b/src/main/db/projects.ts
new file mode 100644
index 0000000..88ef2f6
--- /dev/null
+++ b/src/main/db/projects.ts
@@ -0,0 +1,38 @@
1import { getDb } from "./index";
2import { v4 as uuid } from "uuid";
3
4export interface Project {
5 id: string;
6 name: string;
7 path: string;
8 created_at: number;
9 updated_at: number;
10}
11
12export function listProjects(): Project[] {
13 return getDb()
14 .prepare("SELECT * FROM projects ORDER BY updated_at DESC")
15 .all() as Project[];
16}
17
18export function getProject(id: string): Project | undefined {
19 return getDb()
20 .prepare("SELECT * FROM projects WHERE id = ?")
21 .get(id) as Project | undefined;
22}
23
24export function createProject(name: string, projectPath: string): Project {
25 const db = getDb();
26 const id = uuid();
27 const now = Math.floor(Date.now() / 1000);
28
29 db.prepare(
30 "INSERT INTO projects (id, name, path, created_at, updated_at) VALUES (?, ?, ?, ?, ?)"
31 ).run(id, name, projectPath, now, now);
32
33 return { id, name, path: projectPath, created_at: now, updated_at: now };
34}
35
36export function deleteProject(id: string): void {
37 getDb().prepare("DELETE FROM projects WHERE id = ?").run(id);
38}