diff options
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -87,16 +87,28 @@ func (m model) Init() tea.Cmd { func lookupWord(db *sql.DB, word string) tea.Cmd { return func() tea.Msg { word = strings.TrimSpace(word) // remove leading / trailing whitespace - row := db.QueryRow(`select definition from words where word = ? limit 1`, word) - var definition string - err := row.Scan(&definition) + rows, err := db.Query(`select definition from words where word = ?`, word) if err != nil { if errors.Is(err, sql.ErrNoRows) { return definitionMsg("") } return errMsg(fmt.Errorf("looking up '%s': %s", word, err)) } - return definitionMsg(definition) + defer rows.Close() + var combinedDefinition []string + for rows.Next() { + var definition string + err = rows.Scan(&definition) + if err != nil { + return errMsg(fmt.Errorf("looking up '%s': %s", word, err)) + } + combinedDefinition = append(combinedDefinition, definition) + } + if err := rows.Err(); err != nil { + return errMsg(fmt.Errorf("looking up '%s': %s", word, err)) + } + + return definitionMsg(strings.Join(combinedDefinition, "\n\n")) } } |
