package main import ( "database/sql" "fmt" "log" ) func NewMapper(fn string) (AardMapper, error) { var am AardMapper db, err := sql.Open("sqlite3", fn) if err != nil { return am, fmt.Errorf("error opening mapper sqlite3 database: %s\n", err) } am.db = db return am, nil } type AardMapper struct { db *sql.DB } 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 { log.Fatalf("error querying areas: %s\n", err) } for rows.Next() { var a Area err := rows.Scan(&a.Uid, &a.Name, &a.Flags) areas[a.Uid] = a if err != nil { return areas, fmt.Errorf("error scanning area into struct: %s\n", err) } } return areas, nil } type Area struct { Uid, Name, Flags string }