aboutsummaryrefslogtreecommitdiffstats
path: root/dist/main/db/projects.js
blob: af36cc0da880f83c9e7409f00301990e86647369 (plain)
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listProjects = listProjects;
exports.getProject = getProject;
exports.createProject = createProject;
exports.deleteProject = deleteProject;
const index_1 = require("./index");
const uuid_1 = require("uuid");
function listProjects() {
    return (0, index_1.getDb)()
        .prepare("SELECT * FROM projects ORDER BY updated_at DESC")
        .all();
}
function getProject(id) {
    return (0, index_1.getDb)()
        .prepare("SELECT * FROM projects WHERE id = ?")
        .get(id);
}
function createProject(name, projectPath) {
    const db = (0, index_1.getDb)();
    const id = (0, uuid_1.v4)();
    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 };
}
function deleteProject(id) {
    (0, index_1.getDb)().prepare("DELETE FROM projects WHERE id = ?").run(id);
}