From 69e919cd4e887a606dc1c007c2ce1f36b35477d1 Mon Sep 17 00:00:00 2001 From: Andinus Date: Mon, 6 Apr 2020 22:10:56 +0530 Subject: Add package search --- search/word.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 search/word.go diff --git a/search/word.go b/search/word.go new file mode 100644 index 0000000..a62a393 --- /dev/null +++ b/search/word.go @@ -0,0 +1,23 @@ +package search + +import ( + "tildegit.org/andinus/grus/storage" +) + +// Word will search for unjumbled words in database, given sorted word. +func Word(sorted string, db *storage.DB) (out string, err error) { + db.Mu.RLock() + defer db.Mu.RUnlock() + + stmt, err := db.Conn.Prepare("SELECT word FROM words WHERE sorted = ?") + if err != nil { + return + } + defer stmt.Close() + + err = stmt.QueryRow(sorted).Scan(&out) + if err != nil { + return + } + return +} -- cgit 1.4.1-2-gfad0