Hello all,
Code here: https://github.com/nasquam/taskmaster/blob/master/model/taskpull.go
I have a package I’ve created that I’m calling from my page controller. That package reads from the database and I can write all the data I have out to the screen.
I thought the best way to move that data from my package back into my controller would be to create a group of structs, each struct being 1 row from my query something like:
type RequestResults []RequestResult
I don’t know if I’m not thinking about this properly or if there’s something I’m missing.
package model
import (
"fmt"
)
//RequestResults Exported
type RequestResult struct {
id int
assignedto string
requester string
requestname string
company string
priority string
status string
}
//RequestResults are a map of structs
type RequestResults []RequestResult
//PullTasks will print out all the records in the database
func PullTasks() somethingHereToReturn someType {
fmt.Println("Start pull tasks")
//result := RequestResults{}
rows, QueryErr := db.Query(`SELECT id, assignedto, requester, requestname, company, priority, status FROM golang.tasks WHERE owner =$1 AND active =$2`, "Steven Aiello", "y")
if QueryErr != nil {
fmt.Println(QueryErr)
}
defer rows.Close()
i := 0
for rows.Next() {
var id int
var assignedto string
var requester string
var requestname string
var company string
var priority string
var status string
err := rows.Scan(&id, &assignedto, &requester, &requestname, &company, &priority, &status)
if err != nil {
fmt.Println(err)
panic(err)
}
RequestResultRow := RequestResult{
id: id,
assignedto: assignedto,
requester: requester,
requestname: requestname,
company: company,
priority: priority,
status: status,
}
//RequestResults = RequestResultRow
fmt.Println(i, RequestResultRow.id, RequestResultRow.assignedto, RequestResultRow.requester,
RequestResultRow.requestname, RequestResultRow.company, RequestResultRow.priority, RequestResultRow.status)
i++
}
}
Where am I going wrong?
Thank you kindly