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() ([]Area, error) { areas := make([]Area, 0) 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 = append(areas, 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 }