summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-12-27 13:33:59 +0100
committerxengineering <me@xengineering.eu>2023-12-27 13:33:59 +0100
commitc6d2e9dadcd08cdf82aab507d9d4d8d58574df20 (patch)
tree65495b3fd84060638c5dc396417b6aab926bca79 /model
parent1978c5257e2cf4720716b59c3d69dc21cf457c18 (diff)
downloadceres-c6d2e9dadcd08cdf82aab507d9d4d8d58574df20.tar
ceres-c6d2e9dadcd08cdf82aab507d9d4d8d58574df20.tar.zst
ceres-c6d2e9dadcd08cdf82aab507d9d4d8d58574df20.zip
Implement index page with recipe overview
Diffstat (limited to 'model')
-rw-r--r--model/data.go5
-rw-r--r--model/index.go29
-rw-r--r--model/sql/index-select.sql1
3 files changed, 35 insertions, 0 deletions
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;