summary refs log tree commit diff stats
path: root/search/word.go
blob: a62a393ef7baf2309aee19dc82accd9a2a336c99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}