GetHistory returns the most recent n history entries.
(limit int)
| 135 | |
| 136 | // GetHistory returns the most recent n history entries. |
| 137 | func (d *DB) GetHistory(limit int) ([]QueryHistory, error) { |
| 138 | rows, err := d.conn.Query( |
| 139 | `SELECT id, providers, regions, categories, product_families, attributes, prices, result_count, cache_key, created_at |
| 140 | FROM query_history ORDER BY created_at DESC LIMIT ?`, limit) |
| 141 | if err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | defer rows.Close() |
| 145 | |
| 146 | var result []QueryHistory |
| 147 | for rows.Next() { |
| 148 | var h QueryHistory |
| 149 | var createdStr string |
| 150 | err := rows.Scan(&h.ID, &h.Providers, &h.Regions, &h.Categories, &h.ProductFamilies, |
| 151 | &h.Attributes, &h.Prices, &h.ResultCount, &h.CacheKey, &createdStr) |
| 152 | if err != nil { |
| 153 | return nil, err |
| 154 | } |
| 155 | t, err := time.Parse(time.RFC3339, createdStr) |
| 156 | if err != nil { |
| 157 | t = time.Now() |
| 158 | } |
| 159 | h.CreatedAt = t |
| 160 | result = append(result, h) |
| 161 | } |
| 162 | return result, rows.Err() |
| 163 | } |
| 164 | |
| 165 | // ClearAll deletes all history and pricing cache. |
| 166 | func (d *DB) ClearAll() error { |
no test coverage detected