summary refs log tree commit diff stats
path: root/search
diff options
context:
space:
mode:
Diffstat (limited to 'search')
-rw-r--r--search/word.go23
1 files changed, 23 insertions, 0 deletions
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
+}