diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/data.go | 5 | ||||
-rw-r--r-- | model/index.go | 29 | ||||
-rw-r--r-- | model/sql/index-select.sql | 1 |
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; |