diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-09 01:53:19 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-09 01:53:19 -0500 |
| commit | e5e4f420726cd67c89ee92498d9e5f20c64063ee (patch) | |
| tree | c15f12795ff220fd2717a82fb163e4db4b16063e /ui.go | |
| parent | d49203deaaf1a52115ac6aeb1da15ec9f4c9081d (diff) | |
Show all senses for each word
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")) } } |
