mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 01:32:33 +02:00
Init
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package history
|
||||
|
||||
import (
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/anotherhadi/spilltea/internal/db"
|
||||
)
|
||||
|
||||
type searchKind int
|
||||
|
||||
const (
|
||||
searchKindOff searchKind = iota
|
||||
searchKindFulltext
|
||||
searchKindSQL
|
||||
)
|
||||
|
||||
type SearchResultMsg struct {
|
||||
Entries []db.Entry
|
||||
}
|
||||
|
||||
type SearchErrMsg struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func SearchCmd(database *db.DB, term string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if database == nil {
|
||||
return SearchResultMsg{}
|
||||
}
|
||||
entries, err := database.SearchEntries(term)
|
||||
if err != nil {
|
||||
return SearchErrMsg{Err: err}
|
||||
}
|
||||
return SearchResultMsg{Entries: entries}
|
||||
}
|
||||
}
|
||||
|
||||
func SQLCmd(database *db.DB, query string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if database == nil {
|
||||
return SearchResultMsg{}
|
||||
}
|
||||
entries, err := database.QueryEntries(query)
|
||||
if err != nil {
|
||||
return SearchErrMsg{Err: err}
|
||||
}
|
||||
return SearchResultMsg{Entries: entries}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user