package db import ( "git.bhasher.com/bhasher/focus/backend/types" ) func CreateProject(p types.Project) (int, error) { res, err := db.Exec("INSERT INTO projects (title) VALUES (?)", p.Title) if err != nil { return 0, err } id, err := res.LastInsertId() if err != nil { return 0, err } return int(id), nil } func GetAllProjects() ([]types.Project, error) { rows, err := db.Query("SELECT * FROM projects") if err != nil { return nil, err } defer rows.Close() var projects []types.Project for rows.Next() { var p types.Project if err := rows.Scan(&p.ID, &p.Title); err != nil { return nil, err } projects = append(projects, p) } if err = rows.Err(); err != nil { return nil, err } return projects, nil } func GetProject(id int) (*types.Project, error) { var p types.Project err := db.QueryRow("SELECT * FROM projects WHERE id = ?", id).Scan(&p.ID, &p.Title) if err != nil { return nil, err } return &p, nil } func DeleteProject(id int) error { _, err := db.Exec("DELETE FROM projects WHERE id = ?", id) return err } func UpdateProject(p types.Project) error { _, err := db.Exec("UPDATE projects SET title = ? WHERE id = ?", p.Title, p.ID) return err }