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

Loading…
Cancel
Save