Rework food service to use new search query
This commit is contained in:
@@ -62,7 +62,18 @@ func (s *FoodService) GetLastPer100(name string) (Food, error) {
|
||||
return res, fmt.Errorf("cannot get last per100, db is nil or is not ready")
|
||||
}
|
||||
|
||||
row := s.db.readConn.QueryRow(fmt.Sprintf("SELECT %s FROM food WHERE food like ? ORDER BY rowid DESC LIMIT 1", foodColumns), name+"%")
|
||||
row := s.db.readConn.QueryRow(fmt.Sprintf(`
|
||||
with search_results as (
|
||||
select word, rank
|
||||
from foodfix
|
||||
where word MATCH ?
|
||||
limit 1
|
||||
)
|
||||
select %s
|
||||
from search_results s
|
||||
inner join food f on s.word = f.food
|
||||
order by f.date desc;
|
||||
`, foodColumns), name)
|
||||
err := row.Scan(&res.Rowid, &res.Date, &res.Food, &res.Descripton, &res.Amount, &res.Per100, &res.Energy)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("error scanning row: %v", err)
|
||||
|
Reference in New Issue
Block a user