Add basic CRUD operations for the doselogging and a list command. Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
32 lines
555 B
Go
32 lines
555 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
func deleteDose(db *sql.DB, args []string) {
|
|
fs := flag.NewFlagSet("delete", flag.ExitOnError)
|
|
id := fs.Int("id", -1, "ID of dose to delete")
|
|
fs.Parse(args)
|
|
|
|
if *id < 0 {
|
|
fmt.Println("Error: --id is required")
|
|
return
|
|
}
|
|
|
|
res, err := db.Exec("DELETE FROM doses WHERE id = ?", *id)
|
|
if err != nil {
|
|
fmt.Println("Failed to delete:", err)
|
|
return
|
|
}
|
|
|
|
count, _ := res.RowsAffected()
|
|
if count == 0 {
|
|
fmt.Println("No dose found with that ID")
|
|
} else {
|
|
fmt.Println("Dose deleted.")
|
|
}
|
|
}
|