From c6d2e9dadcd08cdf82aab507d9d4d8d58574df20 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 27 Dec 2023 13:33:59 +0100 Subject: Implement index page with recipe overview --- model/data.go | 5 +++++ model/index.go | 29 +++++++++++++++++++++++++++++ model/sql/index-select.sql | 1 + 3 files changed, 35 insertions(+) create mode 100644 model/data.go create mode 100644 model/index.go create mode 100644 model/sql/index-select.sql (limited to 'model') diff --git a/model/data.go b/model/data.go new file mode 100644 index 0000000..b5edd85 --- /dev/null +++ b/model/data.go @@ -0,0 +1,5 @@ +package model + +type ReadableData interface { + FromDB() error +} diff --git a/model/index.go b/model/index.go new file mode 100644 index 0000000..cc7ffd5 --- /dev/null +++ b/model/index.go @@ -0,0 +1,29 @@ +package model + +type IndexElement struct { + Id uint + Title string +} + +type Index []IndexElement + +func (d *Index) FromDB() error { + query, err := GetSql(`index-select`) + if err != nil { + return err + } + rows, err := db.Query(query) + if err != nil { + return err + } + + for rows.Next() { + var i IndexElement + if err = rows.Scan(&i.Id, &i.Title); err != nil { + return err + } + *d = append(*d, i) + } + + return nil +} diff --git a/model/sql/index-select.sql b/model/sql/index-select.sql new file mode 100644 index 0000000..20b6126 --- /dev/null +++ b/model/sql/index-select.sql @@ -0,0 +1 @@ +SELECT id,title FROM recipes; -- cgit v1.2.3-70-g09d2