GetIndex returns the list of check results for the database.
()
| 104 | |
| 105 | // GetIndex returns the list of check results for the database. |
| 106 | func (sql Storage) GetIndex() (map[string]int64, error) { |
| 107 | db, err := sql.dbConnect() |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | defer db.Close() |
| 112 | |
| 113 | idx := make(map[string]int64) |
| 114 | var check struct { |
| 115 | Name string `db:"name"` |
| 116 | Timestamp int64 `db:"timestamp"` |
| 117 | } |
| 118 | |
| 119 | rows, err := db.Queryx(`SELECT name,timestamp FROM "checks"`) |
| 120 | if err != nil { |
| 121 | return nil, err |
| 122 | } |
| 123 | for rows.Next() { |
| 124 | err := rows.StructScan(&check) |
| 125 | if err != nil { |
| 126 | rows.Close() |
| 127 | return nil, err |
| 128 | } |
| 129 | idx[check.Name] = check.Timestamp |
| 130 | } |
| 131 | |
| 132 | return idx, nil |
| 133 | } |
| 134 | |
| 135 | // Fetch fetches results of the check with given name. |
| 136 | func (sql Storage) Fetch(name string) ([]types.Result, error) { |