Return a map of areas because that makes more sense.

main
Nick Dumas 2 years ago
parent 866d839b06
commit f2a703ed9f

@ -22,8 +22,8 @@ type AardMapper struct {
db *sql.DB db *sql.DB
} }
func (am AardMapper) Areas() ([]Area, error) { func (am AardMapper) Areas() (map[string]Area, error) {
areas := make([]Area, 0) areas := make(map[string]Area)
rows, err := am.db.Query("select uid, name, flags from areas;") rows, err := am.db.Query("select uid, name, flags from areas;")
if err != nil { if err != nil {
@ -33,7 +33,7 @@ func (am AardMapper) Areas() ([]Area, error) {
for rows.Next() { for rows.Next() {
var a Area var a Area
err := rows.Scan(&a.Uid, &a.Name, &a.Flags) err := rows.Scan(&a.Uid, &a.Name, &a.Flags)
areas = append(areas, a) areas[a.Uid] = a
if err != nil { if err != nil {
return areas, fmt.Errorf("error scanning area into struct: %s\n", err) return areas, fmt.Errorf("error scanning area into struct: %s\n", err)
} }

Loading…
Cancel
Save