From 43e7bb10eaade56a9444ec089aa3102218231868 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 8 Jan 2024 19:27:47 +0100 Subject: Implement recipe page --- model/recipe.go | 35 +++++++++++++++++++++++++++++++++++ model/sql/recipe-select.sql | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 model/recipe.go create mode 100644 model/sql/recipe-select.sql (limited to 'model') diff --git a/model/recipe.go b/model/recipe.go new file mode 100644 index 0000000..2b3953f --- /dev/null +++ b/model/recipe.go @@ -0,0 +1,35 @@ +package model + +type Recipe struct { + Id string // FIXME has to be uint + Title string + Portions string // FIXME has to be uint + URL string + Notes string +} + +func (d *Recipe) FromDB() error { + query, err := GetSql(`recipe-select`) + if err != nil { + return err + } + + return db.QueryRow(query, d.Id).Scan( + &d.Id, + &d.Title, + &d.Portions, + &d.URL, + &d.Notes, + ) +} + +func (d *Recipe) ToDB() error { + query, err := GetSql(`recipe-update`) + if err != nil { + return err + } + + _, err = db.Exec(query, d.Title, d.Portions, d.URL, d.Notes, d.Id) + + return err +} diff --git a/model/sql/recipe-select.sql b/model/sql/recipe-select.sql new file mode 100644 index 0000000..2d2bc60 --- /dev/null +++ b/model/sql/recipe-select.sql @@ -0,0 +1,2 @@ +SELECT id,title,portions,url,notes FROM recipes +WHERE id=?; -- cgit v1.2.3-70-g09d2